I am implementing a trivial ICMP ping where "invalid argument" is being given to send IP packet in wire .
Here is the code:
Aipi_sarsi))! = 1) {Fprintf (CDR, "Inset_pton () failed. \ N Error message:% S ", strerror (status)); exit (EXIT_FAILURE);} // destination ((status = inet_pton (AF_INET, dst_ip, & amp; (iphdr- & gt; ip_dst)) that IPv4 address (32 bits)) = 1) failed {fprintf (stderr, "inet_pton (). \ N error message:% S", strerror (status)); exit (EXIT_FAILURE);} IcmpPacket = [NSMutableData dataWithLength: sizeof (* icmpPtr) + [payload Length]]; emphasis (ICMPP! = Shoe Somewhere); Aisimpititi = [Aisimpikeket Mteblbait]; Aisimpitiar- & gt; type = Keaisimtippeikorekvest; Aisimpititi- & gt; code = 0; Aisimpititi- & gt; checksum = 0; Aisimpititi- & gt; identifier = Ossopostvoigaint 16 (self. identifier); Aisimpititi- & gt; sequence number = Ossopvsttobinnt 16 (Self. Anaksaksansonmber); Memcpy (& amp; icmpPtr [1], [payload bytes], [payload length]); Aisimpititi- & gt; checksum = In_ksem ([ICMPP bytes], [ICMPPeter letter]); Int = 1; / * Copy ICMP and Data Packet * / Mempi (Packet + IPv4_HDRRL, ICMPPTR, ICMPP Length)); // set the flag so the socket expects us to provide an IPv4 header. If (Setokopet (Sifsketget native (Self- & gt; _ socket), Aipeepiartioaiaipi, Aipi_acdiaraianelel, and dew, Saifof (on)) and am lt; 0) {Spirit ( "Setokpet () failed to set Aipi_acdiaraianelel"); Exit (EXIT_FAILURE); } / * Send packet * / if (self-> _socket == NULL) {bytesent = -1; Err = EBADF; } Other {Bytescent = Dispatch (CFSocketGetNative (self-> _socket), Packet, Packet_size, 0, (Structure of Socadar *) and Sin, Size (Structured SockDrar)); Err = 0; If (bytecent & lt; 0) {err = errno; This is actually an extension for Apple's simple ping: The IP packet that is being prepared looks straight forward, but for some reason, it is always giving wrong 22. I'm not sure what else is wrong with the code.
Created using socket:
fd = socket (AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
I am making it for the iOS app because I can not use raw sockets.
Thanks
If a person has to face the same problem, So the problem is exactly as mentioned in this post:
No comments:
Post a Comment