Home | History | Annotate | Line # | Download | only in libsa
bootp.c revision 1.34.2.2
      1  1.34.2.2       jym /*	$NetBSD: bootp.c,v 1.34.2.2 2009/07/23 23:32:45 jym Exp $	*/
      2       1.2       cgd 
      3       1.1    brezak /*
      4       1.1    brezak  * Copyright (c) 1992 Regents of the University of California.
      5       1.1    brezak  * All rights reserved.
      6       1.1    brezak  *
      7       1.1    brezak  * This software was developed by the Computer Systems Engineering group
      8       1.1    brezak  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9       1.1    brezak  * contributed to Berkeley.
     10       1.1    brezak  *
     11       1.1    brezak  * Redistribution and use in source and binary forms, with or without
     12       1.1    brezak  * modification, are permitted provided that the following conditions
     13       1.1    brezak  * are met:
     14       1.1    brezak  * 1. Redistributions of source code must retain the above copyright
     15       1.1    brezak  *    notice, this list of conditions and the following disclaimer.
     16       1.1    brezak  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1    brezak  *    notice, this list of conditions and the following disclaimer in the
     18       1.1    brezak  *    documentation and/or other materials provided with the distribution.
     19       1.1    brezak  * 3. All advertising materials mentioning features or use of this software
     20       1.1    brezak  *    must display the following acknowledgement:
     21       1.1    brezak  *	This product includes software developed by the University of
     22       1.1    brezak  *	California, Lawrence Berkeley Laboratory and its contributors.
     23       1.1    brezak  * 4. Neither the name of the University nor the names of its contributors
     24       1.1    brezak  *    may be used to endorse or promote products derived from this software
     25       1.1    brezak  *    without specific prior written permission.
     26       1.1    brezak  *
     27       1.1    brezak  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28       1.1    brezak  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29       1.1    brezak  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30       1.1    brezak  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31       1.1    brezak  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32       1.1    brezak  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33       1.1    brezak  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34       1.1    brezak  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35       1.1    brezak  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36       1.1    brezak  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37       1.1    brezak  * SUCH DAMAGE.
     38       1.1    brezak  *
     39       1.2       cgd  * @(#) Header: bootp.c,v 1.4 93/09/11 03:13:51 leres Exp  (LBL)
     40       1.1    brezak  */
     41       1.1    brezak 
     42      1.22   thorpej #include <sys/param.h>
     43       1.1    brezak #include <netinet/in.h>
     44       1.1    brezak #include <netinet/in_systm.h>
     45       1.1    brezak 
     46      1.18   thorpej #ifdef _STANDALONE
     47      1.18   thorpej #include <lib/libkern/libkern.h>
     48      1.18   thorpej #else
     49      1.18   thorpej #include <string.h>
     50      1.18   thorpej #endif
     51      1.18   thorpej 
     52       1.1    brezak #include "stand.h"
     53       1.1    brezak #include "net.h"
     54       1.1    brezak #include "bootp.h"
     55       1.1    brezak 
     56      1.13  drochner struct in_addr servip;
     57      1.16  drochner #ifdef SUPPORT_LINUX
     58      1.16  drochner char linuxcmdline[256];
     59      1.16  drochner #ifndef TAG_LINUX_CMDLINE
     60      1.16  drochner #define TAG_LINUX_CMDLINE 123
     61      1.16  drochner #endif
     62      1.16  drochner #endif
     63      1.13  drochner 
     64       1.1    brezak static n_long	nmask, smask;
     65       1.1    brezak 
     66      1.33   tsutsui static satime_t	bot;
     67       1.1    brezak 
     68       1.1    brezak static	char vm_rfc1048[4] = VM_RFC1048;
     69      1.12  drochner #ifdef BOOTP_VEND_CMU
     70       1.1    brezak static	char vm_cmu[4] = VM_CMU;
     71      1.12  drochner #endif
     72       1.1    brezak 
     73       1.1    brezak /* Local forwards */
     74      1.34   tsutsui static	ssize_t bootpsend(struct iodesc *, void *, size_t);
     75      1.34   tsutsui static	ssize_t bootprecv(struct iodesc *, void *, size_t, saseconds_t);
     76      1.34   tsutsui static	int vend_rfc1048(u_char *, u_int);
     77      1.12  drochner #ifdef BOOTP_VEND_CMU
     78      1.34   tsutsui static	void vend_cmu(u_char *);
     79      1.12  drochner #endif
     80      1.12  drochner 
     81      1.12  drochner #ifdef SUPPORT_DHCP
     82      1.12  drochner static char expected_dhcpmsgtype = -1, dhcp_ok;
     83      1.12  drochner struct in_addr dhcp_serverip;
     84      1.12  drochner #endif
     85       1.1    brezak 
     86      1.20   thorpej /*
     87      1.20   thorpej  * Boot programs can patch this at run-time to change the behavior
     88      1.20   thorpej  * of bootp/dhcp.
     89      1.20   thorpej  */
     90      1.20   thorpej int bootp_flags;
     91      1.20   thorpej 
     92  1.34.2.2       jym static void
     93  1.34.2.2       jym bootp_addvend(u_char *area)
     94  1.34.2.2       jym {
     95  1.34.2.2       jym #ifdef SUPPORT_DHCP
     96  1.34.2.2       jym 	char vci[64];
     97  1.34.2.2       jym 	int vcilen;
     98  1.34.2.2       jym 
     99  1.34.2.2       jym 	*area++ = TAG_PARAM_REQ;
    100  1.34.2.2       jym 	*area++ = 6;
    101  1.34.2.2       jym 	*area++ = TAG_SUBNET_MASK;
    102  1.34.2.2       jym 	*area++ = TAG_GATEWAY;
    103  1.34.2.2       jym 	*area++ = TAG_HOSTNAME;
    104  1.34.2.2       jym 	*area++ = TAG_DOMAINNAME;
    105  1.34.2.2       jym 	*area++ = TAG_ROOTPATH;
    106  1.34.2.2       jym 	*area++ = TAG_SWAPSERVER;
    107  1.34.2.2       jym 
    108  1.34.2.2       jym 	/* Insert a NetBSD Vendor Class Identifier option. */
    109  1.34.2.2       jym 	sprintf(vci, "NetBSD:%s:libsa", MACHINE);
    110  1.34.2.2       jym 	vcilen = strlen(vci);
    111  1.34.2.2       jym 	*area++ = TAG_CLASSID;
    112  1.34.2.2       jym 	*area++ = vcilen;
    113  1.34.2.2       jym 	(void)memcpy(area, vci, vcilen);
    114  1.34.2.2       jym 	area += vcilen;
    115  1.34.2.2       jym #endif
    116  1.34.2.2       jym 	*area = TAG_END;
    117  1.34.2.2       jym }
    118  1.34.2.2       jym 
    119      1.21       wiz /* Fetch required bootp information */
    120       1.1    brezak void
    121      1.31     isaki bootp(int sock)
    122       1.1    brezak {
    123       1.1    brezak 	struct iodesc *d;
    124      1.19  augustss 	struct bootp *bp;
    125       1.1    brezak 	struct {
    126       1.1    brezak 		u_char header[HEADER_SIZE];
    127       1.1    brezak 		struct bootp wbootp;
    128       1.1    brezak 	} wbuf;
    129       1.3   mycroft 	struct {
    130       1.3   mycroft 		u_char header[HEADER_SIZE];
    131       1.3   mycroft 		struct bootp rbootp;
    132       1.1    brezak 	} rbuf;
    133  1.34.2.2       jym 	unsigned int index;
    134       1.1    brezak 
    135       1.1    brezak #ifdef BOOTP_DEBUG
    136       1.1    brezak  	if (debug)
    137      1.10  christos 		printf("bootp: socket=%d\n", sock);
    138       1.1    brezak #endif
    139       1.1    brezak 	if (!bot)
    140       1.1    brezak 		bot = getsecs();
    141      1.26     perry 
    142       1.1    brezak 	if (!(d = socktodesc(sock))) {
    143      1.10  christos 		printf("bootp: bad socket. %d\n", sock);
    144       1.1    brezak 		return;
    145       1.1    brezak 	}
    146       1.1    brezak #ifdef BOOTP_DEBUG
    147       1.1    brezak  	if (debug)
    148      1.12  drochner 		printf("bootp: d=%lx\n", (long)d);
    149       1.1    brezak #endif
    150       1.4   mycroft 
    151       1.1    brezak 	bp = &wbuf.wbootp;
    152      1.32  christos 	(void)memset(bp, 0, sizeof(*bp));
    153       1.1    brezak 
    154       1.1    brezak 	bp->bp_op = BOOTREQUEST;
    155       1.1    brezak 	bp->bp_htype = 1;		/* 10Mb Ethernet (48 bits) */
    156       1.1    brezak 	bp->bp_hlen = 6;
    157       1.7        pk 	bp->bp_xid = htonl(d->xid);
    158       1.1    brezak 	MACPY(d->myea, bp->bp_chaddr);
    159      1.32  christos 	(void)strncpy((char *)bp->bp_file, bootfile, sizeof(bp->bp_file));
    160      1.32  christos 	(void)memcpy(bp->bp_vend, vm_rfc1048, sizeof(vm_rfc1048));
    161  1.34.2.2       jym 	index = 4;
    162      1.12  drochner #ifdef SUPPORT_DHCP
    163  1.34.2.2       jym 	bp->bp_vend[index++] = TAG_DHCP_MSGTYPE;
    164  1.34.2.2       jym 	bp->bp_vend[index++] = 1;
    165  1.34.2.2       jym 	bp->bp_vend[index++] = DHCPDISCOVER;
    166      1.12  drochner #endif
    167  1.34.2.2       jym 	bootp_addvend(&bp->bp_vend[index]);
    168       1.1    brezak 
    169      1.14  drochner 	d->myip.s_addr = INADDR_ANY;
    170       1.7        pk 	d->myport = htons(IPPORT_BOOTPC);
    171       1.7        pk 	d->destip.s_addr = INADDR_BROADCAST;
    172       1.7        pk 	d->destport = htons(IPPORT_BOOTPS);
    173       1.1    brezak 
    174      1.12  drochner #ifdef SUPPORT_DHCP
    175      1.12  drochner 	expected_dhcpmsgtype = DHCPOFFER;
    176      1.12  drochner 	dhcp_ok = 0;
    177      1.12  drochner #endif
    178      1.12  drochner 
    179      1.15  drochner 	if (sendrecv(d,
    180      1.12  drochner 		    bootpsend, bp, sizeof(*bp),
    181      1.12  drochner 		    bootprecv, &rbuf.rbootp, sizeof(rbuf.rbootp))
    182      1.12  drochner 	   == -1) {
    183      1.15  drochner 		printf("bootp: no reply\n");
    184      1.15  drochner 		return;
    185      1.12  drochner 	}
    186      1.12  drochner 
    187      1.12  drochner #ifdef SUPPORT_DHCP
    188      1.15  drochner 	if (dhcp_ok) {
    189      1.12  drochner 		u_int32_t leasetime;
    190  1.34.2.2       jym 		index = 6;
    191  1.34.2.2       jym 		bp->bp_vend[index++] = DHCPREQUEST;
    192  1.34.2.2       jym 		bp->bp_vend[index++] = TAG_REQ_ADDR;
    193  1.34.2.2       jym 		bp->bp_vend[index++] = 4;
    194      1.32  christos 		(void)memcpy(&bp->bp_vend[9], &rbuf.rbootp.bp_yiaddr, 4);
    195  1.34.2.2       jym 		index += 4;
    196  1.34.2.2       jym 		bp->bp_vend[index++] = TAG_SERVERID;
    197  1.34.2.2       jym 		bp->bp_vend[index++] = 4;
    198  1.34.2.2       jym 		(void)memcpy(&bp->bp_vend[index], &dhcp_serverip.s_addr, 4);
    199  1.34.2.2       jym 		index += 4;
    200  1.34.2.2       jym 		bp->bp_vend[index++] = TAG_LEASETIME;
    201  1.34.2.2       jym 		bp->bp_vend[index++] = 4;
    202      1.12  drochner 		leasetime = htonl(300);
    203  1.34.2.2       jym 		(void)memcpy(&bp->bp_vend[index], &leasetime, 4);
    204  1.34.2.2       jym 		index += 4;
    205  1.34.2.2       jym 		bootp_addvend(&bp->bp_vend[index]);
    206      1.12  drochner 
    207      1.12  drochner 		expected_dhcpmsgtype = DHCPACK;
    208      1.12  drochner 
    209      1.15  drochner 		if (sendrecv(d,
    210      1.12  drochner 			    bootpsend, bp, sizeof(*bp),
    211      1.12  drochner 			    bootprecv, &rbuf.rbootp, sizeof(rbuf.rbootp))
    212      1.12  drochner 		   == -1) {
    213      1.12  drochner 			printf("DHCPREQUEST failed\n");
    214      1.12  drochner 			return;
    215      1.12  drochner 		}
    216      1.12  drochner 	}
    217      1.12  drochner #endif
    218      1.12  drochner 
    219      1.12  drochner 	myip = d->myip = rbuf.rbootp.bp_yiaddr;
    220      1.13  drochner 	servip = rbuf.rbootp.bp_siaddr;
    221      1.15  drochner 	if (rootip.s_addr == INADDR_ANY)
    222      1.15  drochner 		rootip = servip;
    223      1.32  christos 	(void)memcpy(bootfile, rbuf.rbootp.bp_file, sizeof(bootfile));
    224      1.12  drochner 	bootfile[sizeof(bootfile) - 1] = '\0';
    225      1.12  drochner 
    226      1.12  drochner 	if (IN_CLASSA(myip.s_addr))
    227      1.12  drochner 		nmask = IN_CLASSA_NET;
    228      1.12  drochner 	else if (IN_CLASSB(myip.s_addr))
    229      1.12  drochner 		nmask = IN_CLASSB_NET;
    230      1.12  drochner 	else
    231      1.12  drochner 		nmask = IN_CLASSC_NET;
    232      1.12  drochner #ifdef BOOTP_DEBUG
    233      1.12  drochner 	if (debug)
    234      1.12  drochner 		printf("'native netmask' is %s\n", intoa(nmask));
    235      1.12  drochner #endif
    236      1.12  drochner 
    237      1.12  drochner 	/* Get subnet (or natural net) mask */
    238      1.12  drochner 	netmask = nmask;
    239      1.12  drochner 	if (smask)
    240      1.12  drochner 		netmask = smask;
    241      1.12  drochner #ifdef BOOTP_DEBUG
    242      1.12  drochner 	if (debug)
    243      1.12  drochner 		printf("mask: %s\n", intoa(netmask));
    244      1.12  drochner #endif
    245      1.12  drochner 
    246      1.12  drochner 	/* We need a gateway if root is on a different net */
    247      1.12  drochner 	if (!SAMENET(myip, rootip, netmask)) {
    248      1.12  drochner #ifdef BOOTP_DEBUG
    249      1.12  drochner 		if (debug)
    250      1.12  drochner 			printf("need gateway for root ip\n");
    251      1.12  drochner #endif
    252      1.12  drochner 	}
    253      1.12  drochner 
    254      1.12  drochner 	/* Toss gateway if on a different net */
    255      1.12  drochner 	if (!SAMENET(myip, gateip, netmask)) {
    256      1.12  drochner #ifdef BOOTP_DEBUG
    257      1.12  drochner 		if (debug)
    258      1.12  drochner 			printf("gateway ip (%s) bad\n", inet_ntoa(gateip));
    259      1.12  drochner #endif
    260      1.12  drochner 		gateip.s_addr = 0;
    261      1.12  drochner 	}
    262      1.22   thorpej 
    263      1.30    martin #ifdef BOOTP_DEBUG
    264      1.30    martin 	if (debug) {
    265      1.30    martin 		printf("client addr: %s\n", inet_ntoa(myip));
    266      1.30    martin 		if (smask)
    267      1.30    martin 			printf("subnet mask: %s\n", intoa(smask));
    268      1.30    martin 		if (gateip.s_addr != 0)
    269      1.30    martin 			printf("net gateway: %s\n", inet_ntoa(gateip));
    270      1.30    martin 		printf("server addr: %s\n", inet_ntoa(rootip));
    271      1.30    martin 		if (rootpath[0] != '\0')
    272      1.30    martin 			printf("server path: %s\n", rootpath);
    273      1.30    martin 		if (bootfile[0] != '\0')
    274      1.30    martin 			printf("file name: %s\n", bootfile);
    275      1.30    martin 	}
    276      1.30    martin #endif
    277       1.4   mycroft 
    278       1.4   mycroft 	/* Bump xid so next request will be unique. */
    279       1.4   mycroft 	++d->xid;
    280       1.1    brezak }
    281       1.1    brezak 
    282       1.1    brezak /* Transmit a bootp request */
    283       1.6        pk static ssize_t
    284      1.31     isaki bootpsend(struct iodesc *d, void *pkt, size_t len)
    285       1.1    brezak {
    286      1.19  augustss 	struct bootp *bp;
    287       1.1    brezak 
    288       1.1    brezak #ifdef BOOTP_DEBUG
    289       1.1    brezak 	if (debug)
    290      1.12  drochner 		printf("bootpsend: d=%lx called.\n", (long)d);
    291       1.1    brezak #endif
    292       1.3   mycroft 
    293       1.1    brezak 	bp = pkt;
    294       1.7        pk 	bp->bp_secs = htons((u_short)(getsecs() - bot));
    295       1.3   mycroft 
    296       1.1    brezak #ifdef BOOTP_DEBUG
    297       1.1    brezak 	if (debug)
    298      1.10  christos 		printf("bootpsend: calling sendudp\n");
    299       1.1    brezak #endif
    300       1.3   mycroft 
    301      1.31     isaki 	return sendudp(d, pkt, len);
    302       1.1    brezak }
    303       1.1    brezak 
    304       1.6        pk static ssize_t
    305      1.33   tsutsui bootprecv(struct iodesc *d, void *pkt, size_t len, saseconds_t tleft)
    306       1.1    brezak {
    307      1.19  augustss 	ssize_t n;
    308      1.19  augustss 	struct bootp *bp;
    309       1.1    brezak 
    310      1.12  drochner #ifdef BOOTP_DEBUGx
    311       1.1    brezak 	if (debug)
    312      1.12  drochner 		printf("bootp_recvoffer: called\n");
    313       1.1    brezak #endif
    314       1.3   mycroft 
    315       1.6        pk 	n = readudp(d, pkt, len, tleft);
    316      1.25      fvdl 	if (n == -1 || (size_t)n < sizeof(struct bootp) - BOOTP_VENDSIZE)
    317       1.3   mycroft 		goto bad;
    318       1.3   mycroft 
    319       1.3   mycroft 	bp = (struct bootp *)pkt;
    320      1.26     perry 
    321       1.1    brezak #ifdef BOOTP_DEBUG
    322       1.1    brezak 	if (debug)
    323      1.12  drochner 		printf("bootprecv: checked.  bp = 0x%lx, n = %d\n",
    324      1.12  drochner 		    (long)bp, (int)n);
    325       1.1    brezak #endif
    326       1.7        pk 	if (bp->bp_xid != htonl(d->xid)) {
    327       1.1    brezak #ifdef BOOTP_DEBUG
    328       1.1    brezak 		if (debug) {
    329      1.12  drochner 			printf("bootprecv: expected xid 0x%lx, got 0x%x\n",
    330       1.7        pk 			    d->xid, ntohl(bp->bp_xid));
    331       1.1    brezak 		}
    332       1.1    brezak #endif
    333       1.3   mycroft 		goto bad;
    334       1.1    brezak 	}
    335       1.1    brezak 
    336      1.15  drochner 	/* protect against bogus addresses sent by DHCP servers */
    337      1.15  drochner 	if (bp->bp_yiaddr.s_addr == INADDR_ANY ||
    338      1.15  drochner 	    bp->bp_yiaddr.s_addr == INADDR_BROADCAST)
    339      1.15  drochner 		goto bad;
    340      1.15  drochner 
    341       1.1    brezak #ifdef BOOTP_DEBUG
    342       1.1    brezak 	if (debug)
    343      1.10  christos 		printf("bootprecv: got one!\n");
    344       1.1    brezak #endif
    345       1.1    brezak 
    346      1.12  drochner 	/* Suck out vendor info */
    347      1.27  junyoung 	if (memcmp(vm_rfc1048, bp->bp_vend, sizeof(vm_rfc1048)) == 0) {
    348      1.15  drochner 		if (vend_rfc1048(bp->bp_vend, sizeof(bp->bp_vend)) != 0)
    349      1.15  drochner 			goto bad;
    350       1.1    brezak 	}
    351      1.12  drochner #ifdef BOOTP_VEND_CMU
    352      1.27  junyoung 	else if (memcmp(vm_cmu, bp->bp_vend, sizeof(vm_cmu)) == 0)
    353       1.1    brezak 		vend_cmu(bp->bp_vend);
    354      1.12  drochner #endif
    355       1.1    brezak 	else
    356      1.10  christos 		printf("bootprecv: unknown vendor 0x%lx\n", (long)bp->bp_vend);
    357       1.1    brezak 
    358      1.31     isaki 	return n;
    359       1.3   mycroft bad:
    360       1.3   mycroft 	errno = 0;
    361      1.31     isaki 	return -1;
    362       1.1    brezak }
    363       1.1    brezak 
    364      1.12  drochner static int
    365      1.31     isaki vend_rfc1048(u_char *cp, u_int len)
    366       1.1    brezak {
    367      1.19  augustss 	u_char *ep;
    368      1.19  augustss 	int size;
    369      1.19  augustss 	u_char tag;
    370       1.1    brezak 
    371       1.1    brezak #ifdef BOOTP_DEBUG
    372       1.1    brezak 	if (debug)
    373      1.10  christos 		printf("vend_rfc1048 bootp info. len=%d\n", len);
    374       1.1    brezak #endif
    375       1.1    brezak 	ep = cp + len;
    376       1.1    brezak 
    377       1.1    brezak 	/* Step over magic cookie */
    378       1.8       cgd 	cp += sizeof(int);
    379       1.1    brezak 
    380       1.1    brezak 	while (cp < ep) {
    381       1.1    brezak 		tag = *cp++;
    382       1.1    brezak 		size = *cp++;
    383       1.1    brezak 		if (tag == TAG_END)
    384       1.1    brezak 			break;
    385       1.1    brezak 
    386  1.34.2.1       jym 		if (tag == TAG_SUBNET_MASK && size >= sizeof(smask)) {
    387      1.32  christos 			(void)memcpy(&smask, cp, sizeof(smask));
    388       1.1    brezak 		}
    389  1.34.2.1       jym 		if (tag == TAG_GATEWAY && size >= sizeof(gateip.s_addr)) {
    390      1.32  christos 			(void)memcpy(&gateip.s_addr, cp, sizeof(gateip.s_addr));
    391       1.1    brezak 		}
    392  1.34.2.1       jym 		if (tag == TAG_SWAPSERVER && size >= sizeof(rootip.s_addr)) {
    393      1.12  drochner 			/* let it override bp_siaddr */
    394      1.32  christos 			(void)memcpy(&rootip.s_addr, cp, sizeof(rootip.s_addr));
    395       1.1    brezak 		}
    396  1.34.2.1       jym 	        if (tag == TAG_ROOTPATH && size < sizeof(rootpath)) {
    397       1.7        pk 			strncpy(rootpath, (char *)cp, sizeof(rootpath));
    398       1.1    brezak 			rootpath[size] = '\0';
    399       1.1    brezak 		}
    400  1.34.2.1       jym 		if (tag == TAG_HOSTNAME && size < sizeof(hostname)) {
    401       1.7        pk 			strncpy(hostname, (char *)cp, sizeof(hostname));
    402       1.1    brezak 			hostname[size] = '\0';
    403       1.1    brezak 		}
    404      1.12  drochner #ifdef SUPPORT_DHCP
    405      1.12  drochner 		if (tag == TAG_DHCP_MSGTYPE) {
    406      1.15  drochner 			if (*cp != expected_dhcpmsgtype)
    407      1.31     isaki 				return -1;
    408      1.12  drochner 			dhcp_ok = 1;
    409      1.12  drochner 		}
    410  1.34.2.1       jym 		if (tag == TAG_SERVERID &&
    411  1.34.2.1       jym 		    size >= sizeof(dhcp_serverip.s_addr))
    412  1.34.2.1       jym 		{
    413      1.32  christos 			(void)memcpy(&dhcp_serverip.s_addr, cp,
    414      1.12  drochner 			      sizeof(dhcp_serverip.s_addr));
    415      1.16  drochner 		}
    416      1.16  drochner #endif
    417      1.16  drochner #ifdef SUPPORT_LINUX
    418  1.34.2.1       jym 		if (tag == TAG_LINUX_CMDLINE && size < sizeof(linuxcmdline)) {
    419      1.16  drochner 			strncpy(linuxcmdline, (char *)cp, sizeof(linuxcmdline));
    420      1.16  drochner 			linuxcmdline[size] = '\0';
    421       1.1    brezak 		}
    422      1.12  drochner #endif
    423       1.1    brezak 		cp += size;
    424       1.1    brezak 	}
    425      1.31     isaki 	return 0;
    426       1.1    brezak }
    427      1.12  drochner 
    428      1.12  drochner #ifdef BOOTP_VEND_CMU
    429      1.12  drochner static void
    430      1.31     isaki vend_cmu(u_char *cp)
    431      1.12  drochner {
    432      1.19  augustss 	struct cmu_vend *vp;
    433      1.12  drochner 
    434      1.12  drochner #ifdef BOOTP_DEBUG
    435      1.12  drochner 	if (debug)
    436      1.12  drochner 		printf("vend_cmu bootp info.\n");
    437      1.12  drochner #endif
    438      1.12  drochner 	vp = (struct cmu_vend *)cp;
    439      1.12  drochner 
    440      1.12  drochner 	if (vp->v_smask.s_addr != 0) {
    441      1.12  drochner 		smask = vp->v_smask.s_addr;
    442      1.12  drochner 	}
    443      1.12  drochner 	if (vp->v_dgate.s_addr != 0) {
    444      1.12  drochner 		gateip = vp->v_dgate;
    445      1.12  drochner 	}
    446      1.12  drochner }
    447      1.12  drochner #endif
    448