Hi Quinn,
SimplePing is written in objective-C so I couldn't use Int/CInt
instead I replaced int val
to uint32_t val
just to make sure I work with 32, and also made sure that the function setsockopt
returns 0 which symbolize success.
However, when I trace the ping icmp packets in WireShark, I could clearly see that the DF bit is unset in the IP header.
In the SimplePing example, they first create underlying BSD socket, and than use it to create the core foundation. Here the relevant code :
fd = -1;
err = 0;
switch (self.hostAddressFamily) {
case AF_INET: {
fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
uint32_t val = 1;
if (fd < 0) {
err = errno;
break;
}
int x = setsockopt(fd, IPPROTO_IP, IP_DONTFRAG, &val, sizeof(val));
if (x < 0) {
err = errno;
}
} break;
// after creating the BSD socket it create the CFSocket
self.socket = (CFSocketRef) CFAutorelease( CFSocketCreateWithNative(NULL, fd, kCFSocketReadCallBack, SocketReadCallback, &context) );
assert(self.socket != NULL);
// The socket will now take care of cleaning up our file descriptor.
assert( CFSocketGetSocketFlags(self.socket) & kCFSocketCloseOnInvalidate );
fd = -1;
rls = CFSocketCreateRunLoopSource(NULL, self.socket, 0);
assert(rls != NULL);
CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
CFRelease(rls);
I wonder if the DF option is being deleted somewhere when i create CFSocket from BSD socket.