fixed dhcp for windows client
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@784 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
fb6cf1d09c
commit
512176dbd8
@ -33,6 +33,7 @@
|
||||
|
||||
typedef struct {
|
||||
uint8_t allocated;
|
||||
uint8_t macaddr[6];
|
||||
} BOOTPClient;
|
||||
|
||||
BOOTPClient bootp_clients[NB_ADDR];
|
||||
@ -63,6 +64,23 @@ static BOOTPClient *get_new_addr(struct in_addr *paddr)
|
||||
return bc;
|
||||
}
|
||||
|
||||
static BOOTPClient *find_addr(struct in_addr *paddr, const uint8_t *macaddr)
|
||||
{
|
||||
BOOTPClient *bc;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < NB_ADDR; i++) {
|
||||
if (!memcmp(macaddr, bootp_clients[i].macaddr, 6))
|
||||
goto found;
|
||||
}
|
||||
return NULL;
|
||||
found:
|
||||
bc = &bootp_clients[i];
|
||||
bc->allocated = 1;
|
||||
paddr->s_addr = htonl(ntohl(special_addr.s_addr) | (i + START_ADDR));
|
||||
return bc;
|
||||
}
|
||||
|
||||
static void dhcp_decode(const uint8_t *buf, int size,
|
||||
int *pmsg_type)
|
||||
{
|
||||
@ -131,10 +149,19 @@ static void bootp_reply(struct bootp_t *bp)
|
||||
m->m_data += sizeof(struct udpiphdr);
|
||||
memset(rbp, 0, sizeof(struct bootp_t));
|
||||
|
||||
bc = get_new_addr(&daddr.sin_addr);
|
||||
if (!bc) {
|
||||
dprintf("no address left\n");
|
||||
return;
|
||||
if (dhcp_msg_type == DHCPDISCOVER) {
|
||||
bc = get_new_addr(&daddr.sin_addr);
|
||||
if (!bc) {
|
||||
dprintf("no address left\n");
|
||||
return;
|
||||
}
|
||||
memcpy(bc->macaddr, client_ethaddr, 6);
|
||||
} else {
|
||||
bc = find_addr(&daddr.sin_addr, bp->bp_hwaddr);
|
||||
if (!bc) {
|
||||
dprintf("no address assigned\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
dprintf("offered addr=%08x\n", ntohl(daddr.sin_addr.s_addr));
|
||||
|
||||
|
@ -74,7 +74,7 @@ static int get_dns_addr(struct in_addr *pdns_addr)
|
||||
|
||||
void slirp_init(void)
|
||||
{
|
||||
debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
|
||||
// debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
|
||||
|
||||
link_up = 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user