I want to be able to explicitly set the TTL value for a socket connection using Cocoa. I've been unable to see anything useful in the CoreFoundation docs. Do I need to go even lower to the BSD Sockets to set the TTL value?
+3
A:
There are two possibilities.
1) You can use plain C/Unix style sockets, so that you first create your socket, then set its options using setsockopt() including the ones you want to add (you may want to check first if these are supported), and finally you create a a CFSocket using CFSocketCreateWithNative().
2) You use directly the CF Apis, for instance
CFSocketSendData
Sends data over a CFSocket object.
CFSocketError CFSocketSendData (
CFSocketRef s,
CFDataRef address,
CFDataRef data,
CFTimeInterval timeout
);
allows you to set a timeout, which is equivalent to setting the socket option SO_SNDTIMEO.
CFSocketCreateConnectedToSocketSignature
Creates a CFSocket object and opens a connection to a remote socket.
CFSocketRef CFSocketCreateConnectedToSocketSignature (
CFAllocatorRef allocator,
const CFSocketSignature *signature,
CFOptionFlags callBackTypes,
CFSocketCallBack callout,
const CFSocketContext *context,
CFTimeInterval timeout
);
Kind regards.
unforgiven
2009-07-02 15:35:37
A:
Are you writing YA variant of traceroute? ;)
And yes, plain C sockets API is your friend: call as usual setsockopt()
with IP_TTL
socket option for IPv4 or IPV6_UNICAST_HOPS
for IPv6.
Henry Flower
2009-07-03 06:04:14