Sorry for the late reply
Originally Posted by Cactus_Hugger
I'm writing a ping application for the iPhone . However I'm not using SOCK_RAW as this requires root privilege. I'm using SOCK_DGRAM and IPPROTO_ICMP.
I can't post the full source code as I've encapsulated most C calls in Objective-C methods of Classes, so it's quite a few number of files.
Here's a bigger snapshot though
P.S. I'm not showing any of the error handling here as it's all being handled by a try block in another file.
struct sockaddr_in sourceAddressStructure;
socklen_t sourceAddressStructureLength = sizeof(sourceAddressStructure);
unsigned char packet[IP_MAXPACKET];
int packetLength = [self->socket receiveFrom:packet
source:(struct sockaddr *)&sourceAddressStructure
printf("Packet Length = %d\n", packetLength); # This prints 84
for (int i = 0; i < packetLength; i++)
sprintf(buf, "%02X", packet[i]);
if (i % 2)
if (i % 16 == 15)
struct ip *test = (struct ip *)packet;
printf("Test Version = %d\n", test->ip_v); // This prints 4
printf("Test Header Length = %d\n", test->ip_hl); // This prints 5
printf("Test TOS = %d\n", test->ip_tos); // This prints 0
printf("Test Length = %d\n", (u_short)test->ip_len); // This prints 64!!!!!!!
printf("Test Identification = %d\n", test->ip_id);
printf("Test Offset = %d\n", test->ip_off);
printf("Test TTL = %d\n", test->ip_ttl);
printf("Test Protocol = %d\n", test->ip_p); // This prints 1
printf("Test Checksum = %d\n", test->ip_sum);
printf("Test Source Address = %s\n", inet_ntoa(test->ip_src));
printf("Test Destination Address = %s\n", inet_ntoa(test->ip_dst));
Hope this helps a bit more
Thanks again and sorry for the delay