Typedef struct ip_hdr
{
/* unsigned char
Version: 4,
Ihl: 4; */
Unsigned char h_ver;
Unsigned char tos.
Unsigned short tot_len;
Unsigned short id;
Unsigned short
Zero: 1,
Frag: 1,
More_frag: 1,
Frag_off: 13;
Unsigned char TTL.
Unsigned char protocol;
Unsigned short checkSum.
Unsigned long saddr;
Unsigned long daddr;
/* The options start here. */
} IP_HEADER;
Unsigned short checkSum (unsigned char * buff, int wlen)
{
Unsigned long sum=0;
If (wlen) {
Unsigned long bogus.
__asm__ (" CLC \ n
""1: \ t
""Lodsl \ n \ t"
"Adcl % 3, % 0 \ n \ t"
Decl "% 2 \ n \ t"
"Developed 1 b \ n \ t"
"Adcl $0, 0 \ % n \ t"
"Movl % 0, % 3 \ n \ t"
"SHRL $16, % 3 \ n \ t"
"W3, addw % % w0 \ n \ t"
"% w0 adcw $0,"
: "=r (sum)", "=" S "(buff),"=r (wlen) ", "=a" (bogus)
: "0" (the sum), "1" (buff), "2" (wlen));
}
Return (to sum) & amp; 0 XFFFF;
}
Int IPGen (HDR ip_hdr * and unsigned long srcIP, unsigned long dstIP)
{
/* HDR - & gt; Version=4;
HDR - & gt; Ihl=5;//==? */
HDR - & gt; H_ver=(4 & lt; <4 | sizeof (ip_hdr)/sizeof (unsigned int));
HDR - & gt; Tos=0;
HDR - & gt; Tot_len=sizeof (ip_hdr) + sizeof (tcp_hdr);
HDR - & gt; Id=0;
HDR - & gt; Zero=0;
HDR - & gt; Frag=0;
HDR - & gt; More_frag=0;
HDR - & gt; Frag_off=0;
HDR - & gt; TTL=64;
HDR - & gt; Protocol=IP_TCP;
HDR - & gt; Saddr=srcIP,
HDR - & gt; Daddr=dstIP;
HDR - & gt; Saddr=htonl (HDR - & gt; Saddr);
HDR - & gt; Daddr=htonl (HDR - & gt; Daddr);
HDR - & gt; Tot_len=htons (HDR - & gt; Tot_len);
HDR - & gt; CheckSum=0;
HDR - & gt; CheckSum=checkSum (HDR (char *), sizeof (ip_hdr));
return 0;
}
The checksum calculation code from the Linux source code copy.. There should be no wrong,
But!
Wireshark catch BaoYongYuan is a checksum error.. Whywhywhy...
CodePudding user response:
This is not the x86 architecture, size is correct? Debugged will know where is wrong