当前位置: 技术问答>linux和unix
一个奇怪的指针问题?
来源: 互联网 发布时间:2016-11-07
本文导语: 本帖最后由 VisualEleven 于 2011-02-14 15:31:32 编辑 以下程序是在Linux下使用gcc编译,第一个程序A1.C运行正常,第二个程序A2.C却是不能编译通过。因不懂gdb调试,所以上来请教大家。 有点长,请耐心看看。运行时需要先安...
有点长,请耐心看看。运行时需要先安装libpcap-0.9.8.tar.gz
//A1.c
#include
#include
#include /* GIMME a libpcap plz! */
#include
#include
#include
#include
int main(int argc, char **argv) {
char *dev; /* name of the device to use */
char *net; //如此定义
int ret; /* return code */
char errbuf[PCAP_ERRBUF_SIZE];
bpf_u_int32 netp; /* ip */
bpf_u_int32 maskp;/* subnet mask */
struct in_addr addr;
dev = pcap_lookupdev(errbuf);
if(dev == NULL)
{ printf("%sn",errbuf); exit(1); }
printf("DEV: %sn",dev);
ret = pcap_lookupnet(dev,&netp,&maskp,errbuf);
addr.s_addr = netp;
net = inet_ntoa(addr); //运行正常
printf("NET: %sn",net); //输出结果正确
return 0; }
以下为第二个程序A2.C
//
#include
#include
#include
#include
#include
#include
#define LINE_LEN 16
struct conn_info {
long int tv_sec;
long int tv_usec;
char *ip_source;
int s_port;
char *ip_dest;
int d_port;
unsigned long seq;
unsigned long ack_seq;
}*pp;
void dispatcher_handler(u_char *, const struct pcap_pkthdr *, const u_char *);
struct timeval old_ts;
FILE *fl;
main() {
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
char packet_filter[] = "ip and tcp";
struct bpf_program fcode;
fp = pcap_open_offline("LLS_DDOS_2.0.2-outside.dump", errbuf);
fl=fopen("info_b.txt","wb+");
printf("Now file is processing......n");
if(errbuf == NULL)
{ fprintf(stderr,"nError opening dump filen");
return -1; }
if(pcap_compile(fp, &fcode, packet_filter, 1, 0)){
fprintf(stderr,"nUnable to compile the packet filter. Check the syntax.n");
return -1; }
if(pcap_setfilter(fp, &fcode)saddr;
a1=inet_ntoa(addrs); //编译时提示: warning: assignment makes pointer from integer without a cast
//为何方式与前面的程序一样,但是却出现warning ?
strcpy(pp->ip_source,a1);
printf("ip_source=%ld",pp->ip_source);
addrd.s_addr = ipptr->daddr;
a2= inet_ntoa(addrd);//编译时提示: warning: assignment makes pointer from integer without a cast
strcpy(pp->ip_dest,a2);
printf("%s",pp->ip_dest);
}
|
使用inet_ntop来代替inet_ntoa.
|
编译提示的错误信息呢?
|
A2.C中#include 。但这只是warning,除非你设置编译器把warning当作错误,否则应该可以编译通过的。
|
warning居然就不能继续编译了?
|
第二个程序缺少头文件
#include
#include