📄 bootp.c
字号:
/* Fill in the file name we wish to boot. */
strncpy((char *)out_bp->bp_file, (const char *)file_name,
sizeof(out_bp->bp_file));
/* Create a port to send the packet through. */
*port_num = makeuport(IPPORT_BOOTPC);
/* Fill in some of the fields that were not set up in makeuport. */
uprt = uportlist[*port_num];
/* Get his IP number. */
memcpy (uprt->out.i.ipdest, broadip, 4);
/* Get his port number. */
uprt->out.u.dest = intswap(IPPORT_BOOTPS);
/* Get my port number. */
uprt->out.u.source = intswap(IPPORT_BOOTPC);
return(uprt);
} /* end bootp_init routine */
/****************************************************************************/
/* FUNCTION */
/* */
/* parse_in_bp */
/* */
/* DESCRIPTION */
/* */
/* This routine will handle the parseing of the incomming bootp packets. */
/* */
/* AUTHOR */
/* */
/* Craig L. Meredith, Accelerated Technology Inc. */
/* */
/* CALLED BY */
/* */
/* No functions call this function */
/* */
/* CALLS */
/* */
/* netsetip */
/* comparen */
/* memcpy */
/* netsetmask */
/* Smadd */
/* strncpy */
/* strlen */
/* strchr */
/* */
/* INPUTS */
/* */
/* struct bootp * : Pointer to the bootp packet that we are to process. */
/* */
/* OUTPUTS */
/* */
/* sint : Returns a status of 0 if ok, else -1 fail. */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* Craig L. Meredith 04/10/93 Initial version. */
/* */
/****************************************************************************/
static int16 parse_in_bp (struct bootp *bp, uint8 *file_name)
{
sint x, items, len;
uchar *ptr;
uint8 message[80];
int16 gateway = 0, nameserver = 0;
struct machinfo *sp;
extern struct config Scon;
extern struct machinfo *Sns;
/* Get my IP address. */
memcpy (Scon.myipnum, &bp->bp_yiaddr.is_ip_addrs[0], 4);
/* set my ip address */
netsetip (Scon.myipnum);
/* Get the file name that was returned. */
strncpy((char *)file_name, (const char *)bp->bp_file, sizeof(bp->bp_file));
/* Was the reply of the RFC 1048 style?
* If so process the information in the vendor sectio.
*/
if (comparen (bp->bp_vend, VM_RFC1048, 4))
{
/* Step past the magic cookie that identifies this as an RFC 1048
* style response.
*/
ptr = bp->bp_vend + 4;
/* Parse the vendor section. */
while ((*ptr != 255) && ((ptr - bp->bp_vend) < 64))
{
switch (*ptr)
{
case 0: /* nop padding, used to align fields to word */
ptr++; /* boundries. */
break;
case 1: /* subnet mask */
len =* (ptr + 1);
ptr += 2;
netsetmask (ptr);
ptr += len;
break;
case 2: /* time offset */
ptr += 3;
break;
case 3: /* gateways */
len =* (ptr + 1);
items = len/4;
ptr += 2;
for (x = 0; x < items; x++)
{
/* convert each of the numbers into ascii characters */
message[0] = (*ptr + 0x30);
message[1] = '.';
message[2] = (*(ptr+1) + 0x30);
message[3] = '.';
message[4] = (*(ptr+2) + 0x30);
message[5] = '.';
message[6] = (*(ptr+3) + 0x30);
sp = Smadd ((int8 *)message);
if (!sp)
{
/* ERROR Out of Memory Adding Gateway-Smadd()\n\r */
return (-1);
}
gateway++;
sp->gateway = (uchar)gateway;
memcpy (&sp->hostip.is_ip_addrs[0],
ptr, sizeof (struct id_struct));
sp->mstat = HFILE;
ptr += 4;
}
break;
case 4: /* time servers */
case 5: /* IEN = 116 name server */
ptr += 3;
break;
case 6: /* domain name server */
len =* (ptr + 1);
items = len / 4;
ptr += 2;
for (x = 0; x < items; x++)
{
/* convert each of the numbers into ascii characters */
message[0] = (*ptr + 0x30);
message[1] = '.';
message[2] = (*(ptr+1) + 0x30);
message[3] = '.';
message[4] = (*(ptr+2) + 0x30);
message[5] = '.';
message[6] = (*(ptr+3) + 0x30);
sp = Smadd((int8 *)message);
if (!sp)
{
/* ERROR Out of Memory Adding Nameserver-Smadd()\n\r */
return (-1);
}
nameserver++;
sp->nameserv = (uchar)nameserver;
memcpy (&sp->hostip.is_ip_addrs[0],
ptr, sizeof (struct id_struct));
sp->mstat = HFILE;
if (!Sns)
{
Sns = sp;
}
ptr += 4;
}
Scon.nstype = 1;
break;
case 7: /* log server */
case 8: /* cookie server */
case 9: /* lpr server */
case 10: /* impress server */
case 11: /* rlp server */
ptr += 3;
break;
case 12: /* client host name */
len =* (ptr + 1);
strncpy ((int8 *)message, (const int8 *)ptr + 2, (uint16)len);
message[len] = 0;
sp = Smadd ((int8 *)message);
if(!sp)
{
/* ERROR Out of Memory Adding client name-Smadd()\n\r */
return (-1);
}
if (!strlen ((const char *) Scon.me))
{
strncpy ((int8 *) Scon.me, (const int8 *) sp->hname, 31);
}
Scon.me[31] = 0;
ptr += len+2;
break;
case 255:
break;
default:
ptr += 3;
break;
} /* end switch */
} /* end while */
} /* end if comparen */
if (!gateway)
{ /* if none were in the rfc1048 vend packet,
add the default gateway as an entry */
ptr = bp->bp_giaddr.is_ip_addrs;
/* convert each of the numbers into ascii characters */
message[0] = (*ptr + 0x30);
message[1] = '.';
message[2] = (*(ptr+1) + 0x30);
message[3] = '.';
message[4] = (*(ptr+2) + 0x30);
message[5] = '.';
message[6] = (*(ptr+3) + 0x30);
sp = Smadd ((int8 *)message);
if (!sp)
{
/* ERROR Out of Memory Adding Gateway-Smadd()\n\r */
return (-1);
}
gateway++;
sp->gateway = (uchar)gateway;
memcpy (&sp->hostip.is_ip_addrs[0],
ptr, sizeof (struct id_struct));
sp->mstat = HFILE;
}
return (0);
} /* end parse_in_bp routine */
/****************************************************************************/
/* FUNCTION */
/* */
/* bootp_cleanup */
/* */
/* DESCRIPTION */
/* */
/* This routine will deallocate any memory allocated by bootp, and */
/* deallocate the port so that it can be reused. */
/* */
/* AUTHOR */
/* */
/* Glen Johnson, Accelerated Technology Inc. */
/* */
/* CALLED BY */
/* */
/* NU_Bootp */
/* */
/* CALLS */
/* */
/* NU_Deallocate_Memory */
/* */
/* INPUTS */
/* */
/* port_num : The port that will be deallocated. */
/* */
/* OUTPUTS */
/* */
/* none */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* Glen Johnson 01/12/95 Initial version. */
/* */
/****************************************************************************/
void bootp_cleanup(int16 port_num)
{
#if SNMP_INCLUDED
/* Update the UDP Listen Table. */
SNMP_udpListenTableUpdate(SNMP_DELETE, nnipnum,
intswap(uportlist[port_num]->in.u.dest));
#endif
#ifdef PLUS
/* Deallocate the memory used for the udp port. */
NU_Deallocate_Memory((uint *) uportlist[port_num]);
#else
/* Clear this port list entry. */
NU_Dealloc_Memory((unsigned int *) uportlist[port_num]);
#endif
/* Return this port back to the system. */
uportlist[port_num] = NU_NULL;
}
/****************************************************************************/
/* FUNCTION */
/* */
/* BOOTP_Rand */
/* */
/* DESCRIPTION */
/* */
/* Return a random number. We don't have a true rand function, so this */
/* will have to do for now. */
/* */
/* AUTHOR */
/* */
/* Glen Johnson, Accelerated Technology Inc. */
/* */
/****************************************************************************/
static INT BOOTP_Rand(VOID)
{
return(NU_Retrieve_Clock());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -