我遇到了一些編譯不正常的問題。他們幾乎從示例程序中借用,以便更好地瞭解網絡編程的工作方式,並查看是否可以使用RAW套接字組合可靠的TCP連接(三次握手)。這些都是功能:tcp原始程序中的PCAP函數。
void recieve(u_char *args, const struct pcap_pkthdr *pkthdr, const u_char *buffer)
{
const int one = 1;
u_char *ptr;
int LEN = args; /* FIRST WARNING POINTS HERE */
struct ipheader *ip;
struct tcpheader *tcp;
ip = (struct ipheader *)(buffer + LEN);
tcp = (struct tcpheader *)(buffer + LEN + sizeof (struct ipheader));
printf("%d\n", LEN);
printf("Packet recieved. ACK number: %d\n", ntohl (tcp->tcph_seqnum));
printf("Packet recieved. SEQ number: %d\n", nthol (tcp->tcph_acknum));
s_seq = nthol (tcp->tcph_seqnum);
send_syn_ack(s_seq, dip, sip, dport, sport);
sleep(100);
}
和
void capture()
{
pcap_t *pd;
bpf_u_int32 netmask;
bpf_u_int32 localnet;
char *filter = ("ip dest host %s", dstip); /* SECOND WARNING POINTS HERE */
char *dev = NULL;
char errbuf[PCAP_ERRBUF_SIZE];
struct bpf_program filterprog;
int dl = 0, dl_len = 0;
if ((pd = pcap_open_live(dev, 1514, 1, 500, errbuf)) == NULL)
{
fprintf(stderr, "cannot open device %s: %s\n", dev, errbuf);
exit(1);
}
pcap_lookupnet(dev, &localnet, &netmask, errbuf);
pcap_compile(pd, &filterprog, filter, 0, localnet);
if (pcap_setfilter(pd, &filterprog) == - 1)
{
fprintf(stderr, "cannot set pcap filter %s: %s\n", filter, errbuf);
exit(1);
}
pcap_freecode(&filterprog);
dl = pcap_datalink(pd);
switch(dl) {
case 1:
dl_len = 14;
break;
default:
dl_len = 14;
break;
}
if (pcap_loop(pd, -1, recieve, (u_char *)dl_len) < 0) { /* LAST WARNING HERE */
fprintf(stderr, "cannot get raw packet: %s\n", pcap_geterr(pd));
exit(1);
}
}
,這些都是錯誤信息:
In function ‘recieve’:
warning: initialization makes integer from pointer without a cast
In function ‘capture’:
warning: initialization makes pointer from integer without a cast
Warning: cast to pointer from integer of different size
我得到的第一個和最後的警告,甚至在示例程序。這兩個功能是否有用,是否有更簡單更清晰的方法來實現它們的目的?如果不是,我該怎麼辦才能擺脫這些警告?謝謝:)
拼寫錯誤「收到」。 – 2012-07-30 19:49:23