Changes in uspace/srv/net/dhcp/dhcp.c [b7155d7:3e6bca8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/dhcp/dhcp.c
rb7155d7 r3e6bca8 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 47 47 #include <io/log.h> 48 48 #include <loc.h> 49 #include <rndgen.h>50 49 #include <stdio.h> 51 50 #include <stdlib.h> … … 96 95 /** DNS server */ 97 96 inet_addr_t dns_server; 98 /** Transaction ID */99 uint32_t xid;100 97 } dhcp_offer_t; 101 98 … … 117 114 /** Last received offer */ 118 115 dhcp_offer_t offer; 119 /** Random number generator */120 rndgen_t *rndgen;121 116 } dhcp_link_t; 122 117 … … 159 154 dhcp_hdr_t *hdr = (dhcp_hdr_t *)msgbuf; 160 155 uint8_t *opt = msgbuf + sizeof(dhcp_hdr_t); 161 uint32_t xid;162 errno_t rc;163 size_t i;164 165 rc = rndgen_uint32(dlink->rndgen, &xid);166 if (rc != EOK)167 return rc;168 156 169 157 memset(msgbuf, 0, MAX_MSG_SIZE); … … 171 159 hdr->htype = 1; /* AHRD_ETHERNET */ 172 160 hdr->hlen = ETH_ADDR_SIZE; 173 hdr->xid = host2uint32_t_be( xid);174 hdr->flags = host2uint16_t_be(flag_broadcast);161 hdr->xid = host2uint32_t_be(42); 162 hdr->flags = flag_broadcast; 175 163 176 164 eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr); 177 165 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); 178 166 179 i = 0; 180 181 opt[i++] = opt_msg_type; 182 opt[i++] = 1; 183 opt[i++] = msg_dhcpdiscover; 184 185 opt[i++] = opt_param_req_list; 186 opt[i++] = 3; 187 opt[i++] = 1; /* subnet mask */ 188 opt[i++] = 6; /* DNS server */ 189 opt[i++] = 3; /* router */ 190 191 opt[i++] = opt_end; 192 193 return dhcp_send(&dlink->dt, msgbuf, sizeof(dhcp_hdr_t) + i); 167 opt[0] = opt_msg_type; 168 opt[1] = 1; 169 opt[2] = msg_dhcpdiscover; 170 opt[3] = opt_end; 171 172 return dhcp_send(&dlink->dt, msgbuf, sizeof(dhcp_hdr_t) + 4); 194 173 } 195 174 … … 204 183 hdr->htype = 1; /* AHRD_ETHERNET */ 205 184 hdr->hlen = 6; 206 hdr->xid = host2uint32_t_be(offer->xid); 207 hdr->flags = host2uint16_t_be(flag_broadcast); 185 hdr->xid = host2uint32_t_be(42); 186 hdr->flags = flag_broadcast; 187 hdr->ciaddr = host2uint32_t_be(offer->oaddr.addr); 208 188 eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr); 209 189 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); … … 278 258 279 259 inet_naddr_set(yiaddr.addr, 0, &offer->oaddr); 280 offer->xid = uint32_t_be2host(hdr->xid);281 260 282 261 msgb = (uint8_t *)msg; … … 478 457 return ENOMEM; 479 458 480 rc = rndgen_create(&dlink->rndgen);481 if (rc != EOK)482 goto error;483 484 459 dlink->link_id = link_id; 485 460 dlink->timeout = fibril_timer_create(NULL); … … 519 494 return EOK; 520 495 error: 521 if (dlink != NULL && dlink->rndgen != NULL)522 rndgen_destroy(dlink->rndgen);523 496 if (dlink != NULL && dlink->timeout != NULL) 524 497 fibril_timer_destroy(dlink->timeout);
Note:
See TracChangeset
for help on using the changeset viewer.