[PATCH] ping.c: Add -t TTL support

Joachim Nilsson joachim.nilsson at vmlinux.org
Mon Nov 29 08:32:00 UTC 2010


On 11/28/2010 11:04 PM, Denys Vlasenko wrote:
> On Sunday 21 November 2010 01:21, Joachim Nilsson wrote:
>> Hi, maybe someone else is also interested in this.
>>
>> I was testing multicast routing (pimd) on a server today and needed a
>> very simple multicast generator.  Calling BusyBox "ping 225.1.2.3" sends
>> out a neat UDP multicast stream of one packet per second, simple enough
>> for my purposes.  However, for multicast ICMP_ECHO defaults to a TTL of
>> 1, whereas unicast gets 64.  Hence this little patch.
>
> I tested "standard" ping -t TTL and it uses:
>
> setsockopt(3, SOL_IP, IP_TTL, [<ttl_val>], 4);
>
> I changed IP_MULTICAST_TTL to IP_TTL that in your patch and applied it.
> Please test current git and let me know if it doesn't work for you.

Sorry, does not work. I modeled the code after netkit ping, which only
sets the IP_MULTICAST_TTL. It seems the IP_TTL sockopt does not bite for
multicast destination addresses, only unicast.

   
ftp://ftp.uk.linux.org/pub/linux/Networking/netkit/netkit-base-0.17.tar.gz

Looking at iputils ping the set both sockopts.  Here's a snippet from an
old uClinux-dist version:

                int ittl = ttl;
                if (setsockopt(icmp_sock, IPPROTO_IP, IP_MULTICAST_TTL,
                                                        &ttl, 1) == -1) {
                        perror ("ping: can't set multicast time-to-live");
                        exit(2);
                }
                if (setsockopt(icmp_sock, IPPROTO_IP, IP_TTL,
                                                        &ittl,
sizeof(ittl)) == -1) {
                        perror ("ping: can't set unicast time-to-live");
                        exit(2);
                }

Possibly both setsockopt() calls are needed.

Regards
 /Joahcim

-------------- next part --------------
A non-text attachment was scrubbed...
Name: joachim_nilsson.vcf
Type: text/x-vcard
Size: 169 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20101129/2037e7c3/attachment.vcf>


More information about the busybox mailing list