Reputation: 1814
I'm adding a new function in ping by C. I want to set the TTL by command line, but the ping is built by ICMP, and TTL is set in IP. So can you tell me some ways to solve it? Thank you.
Upvotes: 0
Views: 1880
Reputation: 7808
You didn't mention your target platform (or why you have to reinvent the wheel, as has been mentioned) but regardless here we go.
On *NIX it's a standard socket option to your already open socket. It's just at a different level of the networking stack. Soooo...
setsockopt (socket_descriptor, IPPROTO_IP, IP_TTL, val, val_var_len);
See W. Richard Stevens for his bible on sockets if you're in a *NIX world. Otherwise, someone else will/might help out.
Upvotes: 5