bootp.c revision 83b271639501085928c51fadb6e86f8481c66dda
/*
*
* Copyright (c) 2004 Fabrice Bellard
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <slirp.h>
/* XXX: only DHCP is supported */
{
int i;
for(i = 0; i < NB_ADDR; i++)
{
if (!bootp_clients[i].allocated)
{
bc = &bootp_clients[i];
return bc;
}
}
return NULL;
}
{
unsigned i;
if (i >= NB_ADDR)
return 0;
bootp_clients[i].allocated = 0;
return 1;
}
{
int i;
for(i = 0; i < NB_ADDR; i++)
{
{
bc = &bootp_clients[i];
return bc;
}
}
return NULL;
}
{
*pmsg_type = 0;
p = buf;
if (size < 5)
return;
return;
p += 4;
while (p < p_end)
{
tag = p[0];
if (tag == RFC1533_PAD)
p++;
else if (tag == RFC1533_END)
break;
else
{
p++;
if (p >= p_end)
break;
len = *p++;
switch(tag)
{
case RFC2132_REQ_ADDR:
if (len >= 4)
break;
case RFC2132_MSG_TYPE:
if (len >= 1)
*pmsg_type = p[0];
break;
default:
break;
}
p += len;
}
}
}
{
struct mbuf *m;
struct in_addr dns_addr_dhcp;
int dhcp_msg_type, val;
uint8_t *q;
int send_nak = 0;
/* extract exact DHCP msg type */
if (dhcp_msg_type == 0)
if (dhcp_msg_type == DHCPRELEASE)
{
int rc;
LogRel(("NAT: %s %R[IP4]\n",
/* This message is not to be answered in any way. */
return;
}
if ( dhcp_msg_type != DHCPDISCOVER
&& dhcp_msg_type != DHCPREQUEST)
return;
/* XXX: this is a hack to get the client mac address */
return;
#ifndef VBOX_WITH_SIMPLIFIED_SLIRP_SYNC
#endif
if (dhcp_msg_type == DHCPDISCOVER)
{
/* Do not allocate a new lease for clients that forgot that they had a lease. */
if (!bc)
{
if (!bc)
{
LogRel(("NAT: DHCP no IP address left\n"));
Log(("no address left\n"));
return;
}
}
}
else
{
if (!bc)
{
/* if never assigned, behaves as if it was already
assigned (windows fix because it remembers its address) */
goto new_addr;
}
}
if ( tftp_prefix
&& bootp_filename)
q += 4;
if (dhcp_msg_type == DHCPDISCOVER)
{
*q++ = RFC2132_MSG_TYPE;
*q++ = 1;
*q++ = DHCPOFFER;
}
else if (dhcp_msg_type == DHCPREQUEST)
{
*q++ = RFC2132_MSG_TYPE;
*q++ = 1;
{
/* network changed */
*q++ = DHCPNAK;
send_nak = 1;
}
else
*q++ = DHCPACK;
}
if (send_nak)
LogRel(("NAT: Client requested IP address %R[IP4] -- sending NAK\n",
&requested_ip));
else
LogRel(("NAT: DHCP offered IP address %R[IP4]\n",
if ( dhcp_msg_type == DHCPDISCOVER
|| dhcp_msg_type == DHCPREQUEST)
{
*q++ = RFC2132_SRV_ID;
*q++ = 4;
q += 4;
}
if (!send_nak &&
|| dhcp_msg_type == DHCPREQUEST))
{
*q++ = RFC1533_NETMASK;
*q++ = 4;
*q++ = RFC1533_GATEWAY;
*q++ = 4;
q += 4;
*q++ = RFC1533_DNS;
*q++ = 4;
q += 4;
*q++ = RFC2132_LEASE_TIME;
*q++ = 4;
q += 4;
if (*slirp_hostname)
{
*q++ = RFC1533_HOSTNAME;
*q++ = val;
q += val;
}
{
*q++ = RFC1533_DOMAINNAME;
*q++ = val;
q += val;
}
}
*q++ = RFC1533_END;
- sizeof(struct ip)
- sizeof(struct udphdr);
+ sizeof(struct ip);
#endif
/* Reply to the broadcast address, as some clients perform paranoid checks. */
}
{
}