Commit 512176dbd81b0afb7185416ab2a28a340978b85b
1 parent
fb6cf1d0
fixed dhcp for windows client
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@784 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
32 additions
and
5 deletions
slirp/bootp.c
... | ... | @@ -33,6 +33,7 @@ |
33 | 33 | |
34 | 34 | typedef struct { |
35 | 35 | uint8_t allocated; |
36 | + uint8_t macaddr[6]; | |
36 | 37 | } BOOTPClient; |
37 | 38 | |
38 | 39 | BOOTPClient bootp_clients[NB_ADDR]; |
... | ... | @@ -63,6 +64,23 @@ static BOOTPClient *get_new_addr(struct in_addr *paddr) |
63 | 64 | return bc; |
64 | 65 | } |
65 | 66 | |
67 | +static BOOTPClient *find_addr(struct in_addr *paddr, const uint8_t *macaddr) | |
68 | +{ | |
69 | + BOOTPClient *bc; | |
70 | + int i; | |
71 | + | |
72 | + for(i = 0; i < NB_ADDR; i++) { | |
73 | + if (!memcmp(macaddr, bootp_clients[i].macaddr, 6)) | |
74 | + goto found; | |
75 | + } | |
76 | + return NULL; | |
77 | + found: | |
78 | + bc = &bootp_clients[i]; | |
79 | + bc->allocated = 1; | |
80 | + paddr->s_addr = htonl(ntohl(special_addr.s_addr) | (i + START_ADDR)); | |
81 | + return bc; | |
82 | +} | |
83 | + | |
66 | 84 | static void dhcp_decode(const uint8_t *buf, int size, |
67 | 85 | int *pmsg_type) |
68 | 86 | { |
... | ... | @@ -131,10 +149,19 @@ static void bootp_reply(struct bootp_t *bp) |
131 | 149 | m->m_data += sizeof(struct udpiphdr); |
132 | 150 | memset(rbp, 0, sizeof(struct bootp_t)); |
133 | 151 | |
134 | - bc = get_new_addr(&daddr.sin_addr); | |
135 | - if (!bc) { | |
136 | - dprintf("no address left\n"); | |
137 | - return; | |
152 | + if (dhcp_msg_type == DHCPDISCOVER) { | |
153 | + bc = get_new_addr(&daddr.sin_addr); | |
154 | + if (!bc) { | |
155 | + dprintf("no address left\n"); | |
156 | + return; | |
157 | + } | |
158 | + memcpy(bc->macaddr, client_ethaddr, 6); | |
159 | + } else { | |
160 | + bc = find_addr(&daddr.sin_addr, bp->bp_hwaddr); | |
161 | + if (!bc) { | |
162 | + dprintf("no address assigned\n"); | |
163 | + return; | |
164 | + } | |
138 | 165 | } |
139 | 166 | dprintf("offered addr=%08x\n", ntohl(daddr.sin_addr.s_addr)); |
140 | 167 | ... | ... |