aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/packet.c')
-rw-r--r--networking/udhcp/packet.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index ae06d53cc..8cf9fe283 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -20,7 +20,7 @@
20#include "options.h" 20#include "options.h"
21 21
22 22
23void init_header(struct dhcpMessage *packet, char type) 23void udhcp_init_header(struct dhcpMessage *packet, char type)
24{ 24{
25 memset(packet, 0, sizeof(struct dhcpMessage)); 25 memset(packet, 0, sizeof(struct dhcpMessage));
26 switch (type) { 26 switch (type) {
@@ -44,7 +44,7 @@ void init_header(struct dhcpMessage *packet, char type)
44 44
45 45
46/* read a packet from socket fd, return -1 on read error, -2 on packet error */ 46/* read a packet from socket fd, return -1 on read error, -2 on packet error */
47int get_packet(struct dhcpMessage *packet, int fd) 47int udhcp_get_packet(struct dhcpMessage *packet, int fd)
48{ 48{
49 static const char broken_vendors[][8] = { 49 static const char broken_vendors[][8] = {
50 "MSFT 98", 50 "MSFT 98",
@@ -82,7 +82,7 @@ int get_packet(struct dhcpMessage *packet, int fd)
82} 82}
83 83
84 84
85uint16_t checksum(void *addr, int count) 85uint16_t udhcp_checksum(void *addr, int count)
86{ 86{
87 /* Compute Internet Checksum for "count" bytes 87 /* Compute Internet Checksum for "count" bytes
88 * beginning at location "addr". 88 * beginning at location "addr".
@@ -113,7 +113,7 @@ uint16_t checksum(void *addr, int count)
113 113
114 114
115/* Construct a ip/udp header for a packet, and specify the source and dest hardware address */ 115/* Construct a ip/udp header for a packet, and specify the source and dest hardware address */
116int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, 116int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
117 uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex) 117 uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex)
118{ 118{
119 int fd; 119 int fd;
@@ -148,13 +148,13 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
148 packet.udp.len = htons(sizeof(packet.udp) + sizeof(struct dhcpMessage)); /* cheat on the psuedo-header */ 148 packet.udp.len = htons(sizeof(packet.udp) + sizeof(struct dhcpMessage)); /* cheat on the psuedo-header */
149 packet.ip.tot_len = packet.udp.len; 149 packet.ip.tot_len = packet.udp.len;
150 memcpy(&(packet.data), payload, sizeof(struct dhcpMessage)); 150 memcpy(&(packet.data), payload, sizeof(struct dhcpMessage));
151 packet.udp.check = checksum(&packet, sizeof(struct udp_dhcp_packet)); 151 packet.udp.check = udhcp_checksum(&packet, sizeof(struct udp_dhcp_packet));
152 152
153 packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet)); 153 packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet));
154 packet.ip.ihl = sizeof(packet.ip) >> 2; 154 packet.ip.ihl = sizeof(packet.ip) >> 2;
155 packet.ip.version = IPVERSION; 155 packet.ip.version = IPVERSION;
156 packet.ip.ttl = IPDEFTTL; 156 packet.ip.ttl = IPDEFTTL;
157 packet.ip.check = checksum(&(packet.ip), sizeof(packet.ip)); 157 packet.ip.check = udhcp_checksum(&(packet.ip), sizeof(packet.ip));
158 158
159 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest)); 159 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest));
160 if (result <= 0) { 160 if (result <= 0) {
@@ -166,7 +166,7 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
166 166
167 167
168/* Let the kernel do all the work for packet generation */ 168/* Let the kernel do all the work for packet generation */
169int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, 169int udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
170 uint32_t dest_ip, int dest_port) 170 uint32_t dest_ip, int dest_port)
171{ 171{
172 int n = 1; 172 int n = 1;