Revision 512176db slirp/bootp.c
b/slirp/bootp.c | ||
---|---|---|
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 | 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 | 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 |
|
Also available in: Unified diff