Changeset 7809 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- Apr 8, 2008 2:33:21 PM (17 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/bootp.c
r5332 r7809 85 85 86 86 static void dhcp_decode(const uint8_t *buf, int size, 87 int *pmsg_type )87 int *pmsg_type, struct in_addr *req_ip) 88 88 { 89 89 const uint8_t *p, *p_end; … … 113 113 114 114 switch(tag) { 115 case RFC2132_REQ_ADDR: 116 if (len >= 4) 117 *req_ip = *(struct in_addr*)p; 118 break; 115 119 case RFC2132_MSG_TYPE: 116 120 if (len >= 1) … … 134 138 int dhcp_msg_type, val; 135 139 uint8_t *q; 140 struct in_addr requested_ip; /* the requested IP in DHCPREQUEST */ 141 int send_nak = 0; 142 uint32_t ipv4_addr; 136 143 137 144 /* extract exact DHCP msg type */ 138 dhcp_decode(bp->bp_vend, DHCP_OPT_LEN, &dhcp_msg_type); 145 requested_ip.s_addr = 0xffffffff; 146 dhcp_decode(bp->bp_vend, DHCP_OPT_LEN, &dhcp_msg_type, &requested_ip); 139 147 dprintf("bootp packet op=%d msgtype=%d\n", bp->bp_op, dhcp_msg_type); 140 148 … … 143 151 144 152 if (dhcp_msg_type == DHCPRELEASE) { 145 uint32_taddr = ntohl(bp->bp_ciaddr.s_addr);153 ipv4_addr = ntohl(bp->bp_ciaddr.s_addr); 146 154 release_addr(pData, &bp->bp_ciaddr); 147 155 LogRel(("NAT: DHCP released IP address %u.%u.%u.%u\n", 148 addr >> 24, (addr >> 16) & 0xff, (addr >> 8) & 0xff,addr & 0xff));156 ipv4_addr >> 24, (ipv4_addr >> 16) & 0xff, (ipv4_addr >> 8) & 0xff, ipv4_addr & 0xff)); 149 157 dprintf("released addr=%08x\n", ntohl(bp->bp_ciaddr.s_addr)); 150 158 /* This message is not to be answered in any way. */ … … 190 198 RTStrPrintf((char*)rbp->bp_file, sizeof(rbp->bp_file), "%s", bootp_filename); 191 199 192 {193 uint32_t addr = ntohl(daddr.sin_addr.s_addr);194 LogRel(("NAT: DHCP offered IP address %u.%u.%u.%u\n",195 addr >> 24, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff));196 }197 dprintf("offered addr=%08x\n", ntohl(daddr.sin_addr.s_addr));198 199 200 saddr.sin_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS); 200 201 saddr.sin_port = htons(BOOTP_SERVER); … … 222 223 *q++ = RFC2132_MSG_TYPE; 223 224 *q++ = 1; 224 *q++ = DHCPACK; 225 if ( requested_ip.s_addr != 0xffffffff 226 && requested_ip.s_addr != daddr.sin_addr.s_addr) 227 { 228 /* network changed */ 229 *q++ = DHCPNAK; 230 send_nak = 1; 231 } 232 else 233 *q++ = DHCPACK; 234 } 235 236 if (send_nak) 237 { 238 ipv4_addr = ntohl(requested_ip.s_addr); 239 LogRel(("NAT: Client requested IP address %u.%u.%u.%u -- sending NAK\n", 240 ipv4_addr >> 24, (ipv4_addr >> 16) & 0xff, (ipv4_addr >> 8) & 0xff, ipv4_addr & 0xff)); 241 } 242 else 243 { 244 ipv4_addr = ntohl(daddr.sin_addr.s_addr); 245 LogRel(("NAT: DHCP offered IP address %u.%u.%u.%u\n", 246 ipv4_addr >> 24, (ipv4_addr >> 16) & 0xff, (ipv4_addr >> 8) & 0xff, ipv4_addr & 0xff)); 247 dprintf("offered addr=%08x\n", ntohl(daddr.sin_addr.s_addr)); 225 248 } 226 249 … … 231 254 memcpy(q, &saddr.sin_addr, 4); 232 255 q += 4; 233 256 } 257 258 if (!send_nak && 259 (dhcp_msg_type == DHCPDISCOVER || 260 dhcp_msg_type == DHCPREQUEST)) { 234 261 *q++ = RFC1533_NETMASK; 235 262 *q++ = 4; -
trunk/src/VBox/Devices/Network/slirp/bootp.h
r1076 r7809 72 72 #define DHCPREQUEST 3 73 73 #define DHCPACK 5 74 #define DHCPNAK 6 74 75 #define DHCPRELEASE 7 75 76
Note:
See TracChangeset
for help on using the changeset viewer.