Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

c - Where is function in_cksum() defined

Libraries I've included

#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/ip.h>
#include <netinet/in.h>
#include <arpa/inet.h>

code:

 //Step 1: Fill in the ICMP header.                                                                                                                                    
  struct icmpheader *icmp = (struct icmpheader *)(buffer+sizeof(struct ipheader));

  icmp->icmp_type = 8;  //ICMP Type: 8 is request, 0 is reply                                                                                                           

  //Calculate the checksum for integrity                                                                                                                                
  icmp->icmp_chksum = 0;
  icmp->icmp_chksum = in_cksum((unsigned short *) icmp, sizeof(struct icmpheader));

compiling and error message:

spoof.c: In function ‘send_raw_ip_packet’:
spoof.c:64:3: warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration]
   close(sock);
   ^
spoof.c: In function ‘main’:
spoof.c:81:23: warning: implicit declaration of function ‘in_cksum’ [-Wimplicit-function-declaration]
   icmp->icmp_chksum = in_cksum((unsigned short *) icmp, sizeof(struct icmpheader));
                       ^
/tmp/ccboXLMP.o: In function `main':
spoof.c:(.text+0x119): undefined reference to `in_cksum'
collect2: error: ld returned 1 exit status

I'm guessing this error is because I didn't include the right header filer.

I'm using Ubuntu 16.04.2 LTS on a VM.

question from:https://stackoverflow.com/questions/66056257/where-is-function-in-cksum-defined

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...