Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libstand/bootp.c
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
static char expected_dhcpmsgtype = -1, dhcp_ok; | static char expected_dhcpmsgtype = -1, dhcp_ok; | ||||
struct in_addr dhcp_serverip; | struct in_addr dhcp_serverip; | ||||
#endif | #endif | ||||
struct bootp *bootp_response; | struct bootp *bootp_response; | ||||
size_t bootp_response_size; | size_t bootp_response_size; | ||||
/* Fetch required bootp infomation */ | /* Fetch required bootp infomation */ | ||||
void | void | ||||
bootp(int sock, int flag) | bootp(int sock) | ||||
{ | { | ||||
void *pkt; | void *pkt; | ||||
struct iodesc *d; | struct iodesc *d; | ||||
struct bootp *bp; | struct bootp *bp; | ||||
struct { | struct { | ||||
u_char header[HEADER_SIZE]; | u_char header[HEADER_SIZE]; | ||||
struct bootp wbootp; | struct bootp wbootp; | ||||
} wbuf; | } wbuf; | ||||
Show All 26 Lines | #endif | ||||
strncpy(bp->bp_file, bootfile, sizeof(bp->bp_file)); | strncpy(bp->bp_file, bootfile, sizeof(bp->bp_file)); | ||||
bcopy(vm_rfc1048, bp->bp_vend, sizeof(vm_rfc1048)); | bcopy(vm_rfc1048, bp->bp_vend, sizeof(vm_rfc1048)); | ||||
#ifdef SUPPORT_DHCP | #ifdef SUPPORT_DHCP | ||||
bp->bp_vend[4] = TAG_DHCP_MSGTYPE; | bp->bp_vend[4] = TAG_DHCP_MSGTYPE; | ||||
bp->bp_vend[5] = 1; | bp->bp_vend[5] = 1; | ||||
bp->bp_vend[6] = DHCPDISCOVER; | bp->bp_vend[6] = DHCPDISCOVER; | ||||
/* | /* | ||||
* If we are booting from PXE, we want to send the string | * We are booting from PXE, we want to send the string | ||||
* 'PXEClient' to the DHCP server so you have the option of | * 'PXEClient' to the DHCP server so you have the option of | ||||
* only responding to PXE aware dhcp requests. | * only responding to PXE aware dhcp requests. | ||||
*/ | */ | ||||
if (flag & BOOTP_PXE) { | |||||
bp->bp_vend[7] = TAG_CLASSID; | bp->bp_vend[7] = TAG_CLASSID; | ||||
bp->bp_vend[8] = 9; | bp->bp_vend[8] = 9; | ||||
bcopy("PXEClient", &bp->bp_vend[9], 9); | bcopy("PXEClient", &bp->bp_vend[9], 9); | ||||
bp->bp_vend[18] = TAG_USER_CLASS; | bp->bp_vend[18] = TAG_USER_CLASS; | ||||
/* len of each user class + number of user class */ | /* len of each user class + number of user class */ | ||||
bp->bp_vend[19] = 8; | bp->bp_vend[19] = 8; | ||||
/* len of the first user class */ | /* len of the first user class */ | ||||
bp->bp_vend[20] = 7; | bp->bp_vend[20] = 7; | ||||
bcopy("FREEBSD", &bp->bp_vend[21], 7); | bcopy("FREEBSD", &bp->bp_vend[21], 7); | ||||
bp->bp_vend[28] = TAG_PARAM_REQ; | bp->bp_vend[28] = TAG_PARAM_REQ; | ||||
bp->bp_vend[29] = 7; | bp->bp_vend[29] = 7; | ||||
bp->bp_vend[30] = TAG_ROOTPATH; | bp->bp_vend[30] = TAG_ROOTPATH; | ||||
bp->bp_vend[31] = TAG_HOSTNAME; | bp->bp_vend[31] = TAG_HOSTNAME; | ||||
bp->bp_vend[32] = TAG_SWAPSERVER; | bp->bp_vend[32] = TAG_SWAPSERVER; | ||||
bp->bp_vend[33] = TAG_GATEWAY; | bp->bp_vend[33] = TAG_GATEWAY; | ||||
bp->bp_vend[34] = TAG_SUBNET_MASK; | bp->bp_vend[34] = TAG_SUBNET_MASK; | ||||
bp->bp_vend[35] = TAG_INTF_MTU; | bp->bp_vend[35] = TAG_INTF_MTU; | ||||
bp->bp_vend[36] = TAG_SERVERID; | bp->bp_vend[36] = TAG_SERVERID; | ||||
bp->bp_vend[37] = TAG_END; | bp->bp_vend[37] = TAG_END; | ||||
} else | |||||
bp->bp_vend[7] = TAG_END; | |||||
#else | #else | ||||
bp->bp_vend[4] = TAG_END; | bp->bp_vend[4] = TAG_END; | ||||
#endif | #endif | ||||
d->myip.s_addr = INADDR_ANY; | d->myip.s_addr = INADDR_ANY; | ||||
d->myport = htons(IPPORT_BOOTPC); | d->myport = htons(IPPORT_BOOTPC); | ||||
d->destip.s_addr = INADDR_BROADCAST; | d->destip.s_addr = INADDR_BROADCAST; | ||||
d->destport = htons(IPPORT_BOOTPS); | d->destport = htons(IPPORT_BOOTPS); | ||||
Show All 19 Lines | if(dhcp_ok) { | ||||
bcopy(&rbootp->bp_yiaddr, &bp->bp_vend[9], 4); | bcopy(&rbootp->bp_yiaddr, &bp->bp_vend[9], 4); | ||||
bp->bp_vend[13] = TAG_SERVERID; | bp->bp_vend[13] = TAG_SERVERID; | ||||
bp->bp_vend[14] = 4; | bp->bp_vend[14] = 4; | ||||
bcopy(&dhcp_serverip.s_addr, &bp->bp_vend[15], 4); | bcopy(&dhcp_serverip.s_addr, &bp->bp_vend[15], 4); | ||||
bp->bp_vend[19] = TAG_LEASETIME; | bp->bp_vend[19] = TAG_LEASETIME; | ||||
bp->bp_vend[20] = 4; | bp->bp_vend[20] = 4; | ||||
leasetime = htonl(300); | leasetime = htonl(300); | ||||
bcopy(&leasetime, &bp->bp_vend[21], 4); | bcopy(&leasetime, &bp->bp_vend[21], 4); | ||||
if (flag & BOOTP_PXE) { | |||||
bp->bp_vend[25] = TAG_CLASSID; | bp->bp_vend[25] = TAG_CLASSID; | ||||
bp->bp_vend[26] = 9; | bp->bp_vend[26] = 9; | ||||
bcopy("PXEClient", &bp->bp_vend[27], 9); | bcopy("PXEClient", &bp->bp_vend[27], 9); | ||||
bp->bp_vend[36] = TAG_END; | bp->bp_vend[36] = TAG_END; | ||||
} else | |||||
bp->bp_vend[25] = TAG_END; | |||||
expected_dhcpmsgtype = DHCPACK; | expected_dhcpmsgtype = DHCPACK; | ||||
free(pkt); | free(pkt); | ||||
if(sendrecv(d, | if(sendrecv(d, | ||||
bootpsend, bp, sizeof(*bp), | bootpsend, bp, sizeof(*bp), | ||||
bootprecv, &pkt, (void **)&rbootp) == -1) { | bootprecv, &pkt, (void **)&rbootp) == -1) { | ||||
printf("DHCPREQUEST failed\n"); | printf("DHCPREQUEST failed\n"); | ||||
▲ Show 20 Lines • Show All 578 Lines • Show Last 20 Lines |