私は、inetアドレス127.0.0.1(ループバックアドレス)を使用してサーバからクライアントに送信されるテキストを読み取るスニファを作成しようとしています。クライアントがサーバーからデータを受信しても、プログラムは停止状態を維持します。スニファのクライアントとサーバ間のLinuxスニファLibpcap
CODE:
int main(int argc,char **argv)
{
char *dev;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t* descr;
bpf_u_int32 maskp; /* subnet mask */
bpf_u_int32 netp; /* ip*/
struct bpf_program fp; /* hold compiled program */
char *filter = "host 127.0.0.1";
//char *filter = "port 5000";
dev = pcap_lookupdev(errbuf);
if(dev == NULL)
{ printf("%s\n",errbuf); exit(1); }
printf("call success");
/* ask pcap for the network address and mask of the device */
pcap_lookupnet(dev,&netp,&maskp,errbuf);
descr = pcap_open_live(dev,BUFSIZ,1,-1,errbuf);
if(descr == NULL)
{ printf("pcap_open_live(): %s\n",errbuf); exit(1); }
/* Lets try and compile the program.. non-optimized */
if(pcap_compile(descr,&fp,filter,0,netp) == -1)
{ fprintf(stderr,"Error calling pcap_compile\n"); exit(1); }
/* set the compiled program as the filter */
if(pcap_setfilter(descr,&fp) == -1)
{ fprintf(stderr,"Error setting filter\n"); exit(1); }
pcap_loop(descr,2,callback,NULL);
fprintf(stdout,"\nfinished\n");
return 0;
}
サーバーとクライアントがポート5000を使用しています – Usman