私は駅のプリンタへの着信パケットをキャプチャする私のFirestationに "C"プログラムを持っています。次に、プログラムはパケットをスキャンし、どの装置が通話にかかっているかを通知します。郡は最近UTF-8パケットを使用し始めましたが、cプログラムはデータフローの余分な "00"をすべて処理できません。私は00を無視するか、UTF-8を処理するプログラムを設定する必要があります。私は何日も探していて、自分のような初心者が扱うことができるutf-8をどう扱うかについては何も具体的なことはありません。以下は、プログラムの解釈部分です。ダンプまたはutf-8のバイトをCで取り除く
72 00 65 00 61 00 74 00 68 00 69 00 6E 00 67 00後パケットの
43 4F 44 45 53 45 54 3D 55 54 46 38 0A 40 50 4A先頭パケットで
***void compressUtf16 (char *buff, size_t count) {
int i;
for (i = 0; i < count; i++)
buff[i] = buff[i*2]; // for xx 00 xx 00 xx 00 ...
} * {u_int I = 0。 char * searcher = 0; char c; int j; int locflag; static int locationtripped = 0;
static char currentline[256];
static int currentlinepos = 0;
static char lastdispatched[256];
static char dispatchstring[256];
char betastring[256];
static int a = 0;
static int e = 0;
static int pe = 0;
static int md = 0;
static int pulse = 0;
static char location[128];
static char type[16];
static char station[16];
static FILE *fp;
static int printoutscanning = 0;
static char printoutID[20];
static char printoutfileID[32];
static FILE *dbg;
if(pulse) {
if(pulse == 80) {
sprintf(betastring, "beta a a a");
printf("betastring: \"%s\"\n", betastring);
system(betastring);
pulse = 0;
} else
pulse++;
}
if(header->len > 96) {
for(i=55; (i < header->caplen + 1) ; i++) {
c = pkt_data[i-1];
if(c == 13 || c == 10) {
currentline[currentlinepos] = 0;
currentlinepos = 0;
j = strlen(currentline);
if(j && (j > 1)) {
if(strlen(printoutfileID) && printoutscanning) {
dbg = fopen(printoutfileID, "a");
fprintf(dbg, "%s\n", currentline);
fclose(dbg);
}
if(!printoutscanning) {
searcher = 0;
searcher = strstr(currentline, "INCIDENT HISTORY DETAIL:");
if(searcher) {
searcher = searcher + 26;
strncpy(printoutID, searcher, 9);
printoutID[9] = 0;
printoutscanning = 1;
a = 0;
e = 0;
pe = 0;
md = 0;
for(j = 0; j < 128; j++)
location[j] = 0;
for(j = 0; j < 16; j++) {
type[j] = 0;
station[j] = 0;
}
sprintf(printoutfileID, "calls/%s %.6d.txt", printoutID, header-> ts.tv_usec);
dbg = fopen(printoutfileID, "a");
fprintf(dbg, "%s\n", currentline);
fclose(dbg);
}
、あなたはおそらくUTF-16を意味しますか? –
UTF-8は特殊なエンコーディング文字として00を使用しません。あなたはUTF-16を持っていませんか? –
"C"プログラム? Cのステータスは疑わしいですか? – nil