1 --- a/networking/udhcp/packet.c
2 +++ b/networking/udhcp/packet.c
7 +int udhcp_get_payload_len(struct dhcpMessage *payload)
9 + return sizeof(struct dhcpMessage) - DHCP_OPTIONS_BUFSIZE + end_option(payload->options) + sizeof(payload->options[0]);
12 /* Construct a ip/udp header for a packet, send packet */
13 int udhcp_send_raw_packet(struct dhcpMessage *payload,
20 - IP_UPD_DHCP_SIZE = sizeof(struct udp_dhcp_packet) - CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS,
21 - UPD_DHCP_SIZE = IP_UPD_DHCP_SIZE - offsetof(struct udp_dhcp_packet, udp),
23 + int p_len = udhcp_get_payload_len(payload);
25 fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
29 memset(&dest, 0, sizeof(dest));
30 memset(&packet, 0, sizeof(packet));
31 - packet.data = *payload; /* struct copy */
32 + memcpy(&(packet.data), payload, p_len);
34 dest.sll_family = AF_PACKET;
35 dest.sll_protocol = htons(ETH_P_IP);
37 packet.ip.daddr = dest_ip;
38 packet.udp.source = htons(source_port);
39 packet.udp.dest = htons(dest_port);
40 - /* size, excluding IP header: */
41 - packet.udp.len = htons(UPD_DHCP_SIZE);
42 - /* for UDP checksumming, ip.len is set to UDP packet len */
43 + p_len += sizeof(packet.udp);
44 + packet.udp.len = htons(p_len);
45 packet.ip.tot_len = packet.udp.len;
46 - packet.udp.check = udhcp_checksum(&packet, IP_UPD_DHCP_SIZE);
47 - /* but for sending, it is set to IP packet len */
48 - packet.ip.tot_len = htons(IP_UPD_DHCP_SIZE);
49 + p_len += sizeof(packet.ip);
50 + packet.udp.check = udhcp_checksum(&packet, p_len);
51 + packet.ip.tot_len = htons(p_len);
52 packet.ip.ihl = sizeof(packet.ip) >> 2;
53 packet.ip.version = IPVERSION;
54 packet.ip.ttl = IPDEFTTL;
55 packet.ip.check = udhcp_checksum(&packet.ip, sizeof(packet.ip));
57 - /* Currently we send full-sized DHCP packets (zero padded).
58 - * If you need to change this: last byte of the packet is
59 - * packet.data.options[end_option(packet.data.options)]
61 - result = sendto(fd, &packet, IP_UPD_DHCP_SIZE, 0,
62 + result = sendto(fd, &packet, p_len, 0,
63 (struct sockaddr *) &dest, sizeof(dest));
70 - /* Currently we send full-sized DHCP packets (see above) */
71 - result = safe_write(fd, payload, DHCP_SIZE);
72 + result = safe_write(fd, payload, udhcp_get_payload_len(payload));