设为首页 加入收藏

TOP

Linux下用GCC编绎简单的sniffier工具(二)
2014-11-23 22:32:49 来源: 作者: 【 】 浏览:12
Tags:Linux 下用 GCC 简单 sniffier 工具

struct hostent *hostname;
char hn[MAXSTRINGSIZE];
iadd=*((unsigned long int *)(ipadd));


reghost(iadd);
intohost(iadd,hn);
if(strlen(hn)>0)
printf("%s",hn);
else{
for(i=0;i<3;++i)
printf("%d:",ipadd[i]);
printf("%d:",ipadd[i]);
}
}


//main
//the start and configure of getting packet
int main(int argc,char **argv)
{
char ebuf[PCAP_ERRBUF_SIZE];
pcap_t *pd;


if(argc<=1){
printf("usage:%s \n",argv[0]);
exit(0);
}


/*configure using pcap*/
if((pd=pcap_open_live(argv[1],DEFAULT_SNAPLEN,1,1000,ebuf))==NULL)
{
(void)fprintf(stderr,"%s",ebuf);
exit(1);
}


/*get the packet by the pcap_loop*/
if(pcap_loop(pd,-1,packet_print,NULL)<0){
(void)fprintf(stderr,"pcap_loop:%s\n",pcap_geterr(pd));
exit(1);
}
pcap_close(pd);
exit(0);
}


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇初次学习编译Linux内核 下一篇新手进阶 用getopt在Linux下获取..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: