home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume27 / bootp-2.2.B / patch01 < prev    next >
Text File  |  1993-10-19  |  10KB  |  350 lines

  1. Newsgroups: comp.sources.unix
  2. From: gwr@mc.com (Gordon W. Ross)
  3. Subject: v27i076: bootp-2.2 - RFC 1048 "bootp" server (w/ vendor extensions), Patch01
  4. Sender: unix-sources-moderator@gw.home.vix.com
  5. Approved: vixie@gw.home.vix.com
  6.  
  7. Submitted-By: gwr@mc.com (Gordon W. Ross)
  8. Posting-Number: Volume 27, Issue 76
  9. Archive-Name: bootp-2.2.B/patch01
  10.  
  11. I didn't have a Solaris machine to test on when I merge in the
  12. Solaris support changes and, well, I botched it.  Sorry.
  13. (On Solaris, it dumps core while composing the first reply.)
  14.  
  15. Here are changes to make bootp-2.2.B _really_ work on Solaris.
  16. Your copy becomes version 2.2.C after these chages.
  17.  
  18. Gordon W. Ross          Mercury Computer Systems
  19. gwr@mc.com              199 Riverneck Road
  20. 508-256-1300            Chelmsford, MA 01824-2820
  21.  
  22. diff -rcw bootp-2.2.B/Makefile bootp-2.2.C/Makefile
  23. *** bootp-2.2.B/Makefile    Thu Oct  7 15:30:56 1993
  24. --- bootp-2.2.C/Makefile    Thu Oct 14 19:21:29 1993
  25. ***************
  26. *** 20,26 ****
  27.   # Uncomment these lines for SunOS 4.X
  28.   SYSDEFS= -DSUNOS4
  29.   # Uncomment these lines for SVR4 (or Solaris 2.X)
  30. ! # SYSDEFS= -DSVR4 # -Dsparc -Dsun -Dunix ?XXX?
  31.   # SYSLIBS= -lsocket -lnsl
  32.   
  33.   INSTALL=/usr/bin/install
  34. --- 20,26 ----
  35.   # Uncomment these lines for SunOS 4.X
  36.   SYSDEFS= -DSUNOS4
  37.   # Uncomment these lines for SVR4 (or Solaris 2.X)
  38. ! # SYSDEFS= -DSVR4
  39.   # SYSLIBS= -lsocket -lnsl
  40.   
  41.   INSTALL=/usr/bin/install
  42. diff -rcw bootp-2.2.B/Version.c bootp-2.2.C/Version.c
  43. *** bootp-2.2.B/Version.c    Thu Oct  7 16:11:18 1993
  44. --- bootp-2.2.C/Version.c    Thu Oct 14 19:40:01 1993
  45. ***************
  46. *** 41,48 ****
  47.    */
  48.   
  49.   #ifndef lint
  50. ! char sccsid[] = "@(#)bootpd 2.2.B %VERSION% %WHOANDWHERE%\n";
  51. ! char rcsid[] = "$Header: Version 2.2.B from gwr@mc.com $";
  52.   #endif /* not lint */
  53.   
  54. ! char Version[] = "bootpd 2.2.B %VERSION%\n\t%WHOANDWHERE%\n";
  55. --- 41,48 ----
  56.    */
  57.   
  58.   #ifndef lint
  59. ! char sccsid[] = "@(#)bootpd 2.2.C %VERSION% %WHOANDWHERE%\n";
  60. ! char rcsid[] = "$Header: Version 2.2.C from gwr@mc.com $";
  61.   #endif /* not lint */
  62.   
  63. ! char Version[] = "bootpd 2.2.C %VERSION%\n\t%WHOANDWHERE%\n";
  64. diff -rcw bootp-2.2.B/bootpd.c bootp-2.2.C/bootpd.c
  65. *** bootp-2.2.B/bootpd.c    Fri Oct  8 11:34:30 1993
  66. --- bootp-2.2.C/bootpd.c    Thu Oct 14 19:27:24 1993
  67. ***************
  68. *** 85,93 ****
  69.   #include <signal.h>
  70.   #include <stdio.h>
  71.   #ifdef SVR4
  72. ! #include <sys/termios.h>    /* Why? */
  73.   #include <string.h>
  74. - #include <sys/fcntl.h>    /* Why? */
  75.   #else
  76.   #include <strings.h>
  77.   #endif
  78. --- 85,93 ----
  79.   #include <signal.h>
  80.   #include <stdio.h>
  81.   #ifdef SVR4
  82. ! #include <sys/fcntl.h>        /* for O_RDONLY, etc */
  83. ! #include <sys/termios.h>    /* for TIOCNOTTY */
  84.   #include <string.h>
  85.   #else
  86.   #include <strings.h>
  87.   #endif
  88. ***************
  89. *** 120,126 ****
  90.   #define bcopy(a,b,c)    memcpy(b,a,c)
  91.   #define bzero(p,l)      memset(p,0,l)
  92.   #define bcmp(a,b,c)     memcmp(a,b,c)
  93. ! #define    index(a,b)    strchr(a,b)
  94.   #endif
  95.   
  96.   
  97. --- 120,126 ----
  98.   #define bcopy(a,b,c)    memcpy(b,a,c)
  99.   #define bzero(p,l)      memset(p,0,l)
  100.   #define bcmp(a,b,c)     memcmp(a,b,c)
  101. ! #define    index        strchr
  102.   #endif
  103.   
  104.   
  105. ***************
  106. *** 162,169 ****
  107.    * Internet socket and interface config structures
  108.    */
  109.   
  110. ! struct sockaddr server_addr;
  111. ! struct sockaddr client_addr;
  112.   struct ifreq ifreq[10];        /* Holds interface configuration */
  113.   struct ifconf ifconf;        /* Int. config ioctl block (pnts to ifreq) */
  114.   struct arpreq arpreq;        /* Arp request ioctl block */
  115. --- 162,169 ----
  116.    * Internet socket and interface config structures
  117.    */
  118.   
  119. ! struct sockaddr_in server_addr;
  120. ! struct sockaddr_in client_addr;
  121.   struct ifreq ifreq[10];        /* Holds interface configuration */
  122.   struct ifconf ifconf;        /* Int. config ioctl block (pnts to ifreq) */
  123.   struct arpreq arpreq;        /* Arp request ioctl block */
  124. ***************
  125. *** 243,249 ****
  126.       struct timeval actualtimeout, *timeout;
  127.       struct bootp *bp;
  128.       struct servent *servp;
  129. -     struct sockaddr_in *s_sin;
  130.       char *stmp;
  131.       int n, sa_len, ca_len;
  132.       int nfound, readfds;
  133. --- 243,248 ----
  134. ***************
  135. *** 253,259 ****
  136.       actualtimeout.tv_usec = 0L;
  137.       actualtimeout.tv_sec  = 60 * DEFAULT_TIMEOUT;
  138.       timeout = &actualtimeout;
  139. -     s_sin = (struct sockaddr_in *) &server_addr;
  140.   
  141.       /* Get space for receiving packets and composing replies. */
  142.       pktbuf = malloc(MAXPKT);
  143. --- 252,257 ----
  144. ***************
  145. *** 271,284 ****
  146.       bzero((char *) &server_addr, sa_len);
  147.       errno = 0;
  148.       standalone = TRUE;
  149. !     if (getsockname(s, &server_addr, &sa_len) == 0) {
  150.       /*
  151.        * Descriptor 0 is a socket.  Assume we are a child of inetd.
  152.        */
  153. !     if (s_sin->sin_family == AF_INET) {
  154.           standalone = FALSE;
  155. !         bootps_port = ntohs(s_sin->sin_port);
  156.       } else {
  157.           report(LOG_INFO, "getsockname: not an INET socket\n");
  158.       }
  159.       }
  160. --- 269,283 ----
  161.       bzero((char *) &server_addr, sa_len);
  162.       errno = 0;
  163.       standalone = TRUE;
  164. !     if (getsockname(s, (struct sockaddr *) &server_addr, &sa_len) == 0) {
  165.       /*
  166.        * Descriptor 0 is a socket.  Assume we are a child of inetd.
  167.        */
  168. !     if (server_addr.sin_family == AF_INET) {
  169.           standalone = FALSE;
  170. !         bootps_port = ntohs(server_addr.sin_port);
  171.       } else {
  172. +         /* Some other type of socket? */
  173.           report(LOG_INFO, "getsockname: not an INET socket\n");
  174.       }
  175.       }
  176. ***************
  177. *** 470,479 ****
  178.       /*
  179.        * Bind socket to BOOTPS port.
  180.        */
  181. !     s_sin->sin_family = AF_INET;
  182. !     s_sin->sin_addr.s_addr = INADDR_ANY;
  183. !     s_sin->sin_port = htons(bootps_port);
  184. !     if (bind(s, &server_addr, sizeof(*s_sin)) < 0) {
  185.           report(LOG_ERR, "bind: %s\n", get_network_errmsg());
  186.           exit(1);
  187.       }
  188. --- 469,480 ----
  189.       /*
  190.        * Bind socket to BOOTPS port.
  191.        */
  192. !     server_addr.sin_family = AF_INET;
  193. !     server_addr.sin_addr.s_addr = INADDR_ANY;
  194. !     server_addr.sin_port = htons(bootps_port);
  195. !     if (bind(s, (struct sockaddr *) &server_addr,
  196. !          sizeof(server_addr)) < 0)
  197. !     {
  198.           report(LOG_ERR, "bind: %s\n", get_network_errmsg());
  199.           exit(1);
  200.       }
  201. ***************
  202. *** 538,544 ****
  203.           exit(0);
  204.       }
  205.       ca_len = sizeof(client_addr);
  206. !     n = recvfrom(s, pktbuf, MAXPKT, 0, &client_addr, &ca_len);
  207.       if (n <= 0) {
  208.           continue;
  209.       }
  210. --- 539,546 ----
  211.           exit(0);
  212.       }
  213.       ca_len = sizeof(client_addr);
  214. !     n = recvfrom(s, pktbuf, MAXPKT, 0,
  215. !              (struct sockaddr *) &client_addr, &ca_len);
  216.       if (n <= 0) {
  217.           continue;
  218.       }
  219. ***************
  220. *** 860,871 ****
  221.       int forward;
  222.   {
  223.       register struct bootp *bp = (struct bootp *) pktbuf;
  224. !     struct in_addr dst;    /* XXX */
  225. !     struct sockaddr_in *c_sin;
  226.   
  227. !     c_sin = (struct sockaddr_in *) &client_addr;
  228. !     c_sin->sin_port = htons(bootpc_port);
  229.       /*
  230.        * If the client IP address is specified, use that
  231.        * else if gateway IP address is specified, use that
  232. --- 862,870 ----
  233.       int forward;
  234.   {
  235.       register struct bootp *bp = (struct bootp *) pktbuf;
  236. !     struct in_addr dst;
  237.   
  238. !     client_addr.sin_port = htons(bootpc_port);
  239.       /*
  240.        * If the client IP address is specified, use that
  241.        * else if gateway IP address is specified, use that
  242. ***************
  243. *** 876,882 ****
  244.           dst = bp->bp_ciaddr;
  245.       } else if (bp->bp_giaddr.s_addr && forward == 0) {
  246.           dst = bp->bp_giaddr;
  247. !         c_sin->sin_port = htons(bootps_port);
  248.       } else {
  249.           dst = bp->bp_yiaddr;
  250.           setarp(&dst, bp->bp_chaddr, bp->bp_hlen);
  251. --- 875,881 ----
  252.           dst = bp->bp_ciaddr;
  253.       } else if (bp->bp_giaddr.s_addr && forward == 0) {
  254.           dst = bp->bp_giaddr;
  255. !         client_addr.sin_port = htons(bootps_port);
  256.       } else {
  257.           dst = bp->bp_yiaddr;
  258.           setarp(&dst, bp->bp_chaddr, bp->bp_hlen);
  259. ***************
  260. *** 925,934 ****
  261.           }
  262.       }
  263.   
  264. !     c_sin->sin_addr = dst; 
  265.       /* Send reply with same size packet as request used. */
  266.       if (sendto(s, pktbuf, pktlen, 0,
  267. !            &client_addr, sizeof(*c_sin)) < 0) {
  268.           report(LOG_ERR, "sendto: %s\n", get_network_errmsg());
  269.       }
  270.   } /* sendreply */
  271. --- 924,935 ----
  272.           }
  273.       }
  274.   
  275. !     client_addr.sin_addr = dst;
  276.       /* Send reply with same size packet as request used. */
  277.       if (sendto(s, pktbuf, pktlen, 0,
  278. !            (struct sockaddr *) &client_addr,
  279. !            sizeof(client_addr)) < 0)
  280. !     {
  281.           report(LOG_ERR, "sendto: %s\n", get_network_errmsg());
  282.       }
  283.   } /* sendreply */
  284. ***************
  285. *** 965,980 ****
  286.   {
  287.       struct sockaddr_in *si;
  288.       
  289.       bzero((caddr_t)&arpreq, sizeof(arpreq));
  290.       
  291.       arpreq.arp_pa.sa_family = AF_INET;
  292.       si = (struct sockaddr_in *) &arpreq.arp_pa;
  293.       si->sin_addr = *ia;
  294.   
  295. !     arpreq.arp_flags = ATF_INUSE | ATF_COM;
  296. !     
  297.       bcopy(ha, arpreq.arp_ha.sa_data, len);
  298.   
  299.       if (ioctl(s, SIOCSARP, (caddr_t)&arpreq) < 0) {
  300.           report(LOG_ERR, "ioctl(SIOCSARP): %s\n", get_network_errmsg());
  301.       }
  302. --- 966,987 ----
  303.   {
  304.       struct sockaddr_in *si;
  305.   
  306. +     if (debug > 1)
  307. +     report(LOG_INFO, "setarp %s %s (l=%d)\n",
  308. +            inet_ntoa(*ia), haddrtoa(ha, 1), len);
  309.       bzero((caddr_t)&arpreq, sizeof(arpreq));
  310. +     arpreq.arp_flags = ATF_INUSE | ATF_COM;
  311.   
  312. +     /* Set up the protocol address. */
  313.       arpreq.arp_pa.sa_family = AF_INET;
  314.       si = (struct sockaddr_in *) &arpreq.arp_pa;
  315.       si->sin_addr = *ia;
  316.   
  317. !     /* Set up the hardware address. */
  318.       bcopy(ha, arpreq.arp_ha.sa_data, len);
  319.   
  320. +     /* XXX - Why does this fail on Solaris 2.X ? (ENXIO) */
  321.       if (ioctl(s, SIOCSARP, (caddr_t)&arpreq) < 0) {
  322.       report(LOG_ERR, "ioctl(SIOCSARP): %s\n", get_network_errmsg());
  323.       }
  324. ***************
  325. *** 1308,1313 ****
  326. --- 1315,1325 ----
  327.    * One could append additional options when there is room after the
  328.    * end record but this implementation does not do so.  One would need
  329.    * a way to know which options should be "forced" into the list.
  330. +  *
  331. +  * This function is now not really correct.  The client only gets
  332. +  * to set the magic number, not the data.  Oddball clients can be
  333. +  * supported using the "arbitrary vendor data" feature, so this
  334. +  * code should be reverted back to the CMU version. <gwr@mc.com>
  335.    */
  336.   void dovend_rfc1048(bp, hp, bootsize)
  337.       register struct bootp *bp;
  338. ***************
  339. *** 1320,1325 ****
  340. --- 1332,1338 ----
  341.       char *tmpstr;
  342.       unsigned long ul;
  343.       unsigned short us;
  344. +     extern char *index();
  345.       
  346.       /*
  347.        * Compute pointers to beginning and end of option area.
  348.