Subject: Re: IP packet length patch for 1.2
To: Curt Sampson <cjs@portal.ca>
From: Kevin M. Lahey <kml@nas.nasa.gov>
List: netbsd-users
Date: 04/23/1997 21:28:56
In message <Pine.NEB.3.93.961104094611.314A-100000@cynic.portal.ca>Curt Sampson
 writes
>
>Ok, I've just checked out this set of patches (finally!). Sorry
>for the delay. It turns out that NetBSD 1.2 was not vulnurable to
>the `Windows 95 65510 size ping bug.' (A `ping -l 65510 host' would
>panic a Linux machine.)
>
>The new patches seem to work fine. I can't get NetBSD's ping program
>to generate packets larger than the physical network's MTU (I don't
>know if this is a problem with ping or the kernel), but Windows 95
>machines do this quite happily.

The problem is the socket buffer size for ping.  Here's a patch
for -current sometime pre-1.2:

diff -c -r1.1.1.1 ping.c
*** ping.c      1996/08/02 02:47:00     1.1.1.1
--- ping.c      1996/08/03 23:57:00
***************
*** 178,184 ****
        struct protoent *proto;
        struct in_addr ifaddr, saddr;
        register int i;
!       int ch, fdmask, hold, packlen, preload;
        u_char *datap, *packet;
        char *target, hnamebuf[MAXHOSTNAMELEN];
        u_char ttl, loop = 1;
--- 178,184 ----
        struct protoent *proto;
        struct in_addr ifaddr, saddr;
        register int i;
!       int ch, fdmask, hold, packlen, preload, maxsize, maxsizelen;
        u_char *datap, *packet;
        char *target, hnamebuf[MAXHOSTNAMELEN];
        u_char ttl, loop = 1;
***************
*** 364,376 ****
--- 364,396 ----
                       sizeof(ifaddr)) < 0)
                err(1, "setsockopt IP_MULTICAST_IF");
  
+       /* 
+        * When trying to send large packets, you must increase the
+        * size of both the send and receive buffers...
+        */
+ 
+       maxsizelen = sizeof maxsize;
+       if (getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &maxsize, 
+                      &maxsizelen) < 0)
+               err(1, "getsockopt");
+ 
+       if (maxsize < packlen) {
+               if(setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &packlen, 
+                             sizeof(maxsize)) < 0)
+                       err(1, "setsockopt");
+       }
+ 
        /*
         * When pinging the broadcast address, you can get a lot of answers.
         * Doing something so evil is useful if you are trying to stress the
         * ethernet, or just want to fill the arp cache to get some stuff for
         * /etc/ethers.
         */
+ 
        hold = 48 * 1024;
+       if (hold < packlen)
+               hold = packlen;
+ 
        (void)setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold,