![]() This means you have an extra 8 bits in your header which shouldn't be there. The other problem with your struct ipheader is that you have both an 8-bit iph_flags and a 16-bit iph_offset, while the flags field in an IP header should be 3 bits and the offset field should be 13 bits (both of these together adding up to 16 bits). In the case of your program, omitting #pragma pack(pop) after your declarations should still work, but it is good practice to reset this, in case you ever do declare any other structs which you don't want to be tightly-packed, or you include any other header files afterwards. After you are finished declaring your structs, you can then do #pragma pack(pop) to reset struct packing back to normal in any following declarations. One issue is your misuse of #pragma pack.īefore you declare your structs, you should do #pragma pack(push, 1), which both sets struct packing alignment to 1, and pushes the previous state of packing alignment to a stack. Your program should still compile under C89 without this due to implicit function declaration but it is bad practice to rely on that and it could lead to subtle bugs. #Tcp packet sender in c codeI would really appreciate if you could tell me what am I doing wrong in my code :)įirst of all, you are missing the header, which provides the inet_addr function you are using. but If I do a simple hping3 -p 1000 192.168.1.151 it works just fine and I can see it in wireshark too. also when I run the program as it suppose to be as. While compiling it, it compiles just fine. Printf("Count #%u - sendto() is OK\n", count) If(setsockopt(sd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) iph_len, 0, (struct sockaddr *)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |