aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/packet.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-18 19:51:32 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-18 19:51:32 +0000
commit5a3395bc01cd4b11309595a6ecdaf32f8279f378 (patch)
tree1e63aa591a05e9ec75aefdcd639ca4188e583648 /networking/udhcp/packet.c
parentabfc4cf6d8b9c59724aceb70df5081a1368fdb62 (diff)
downloadbusybox-w32-5a3395bc01cd4b11309595a6ecdaf32f8279f378.tar.gz
busybox-w32-5a3395bc01cd4b11309595a6ecdaf32f8279f378.tar.bz2
busybox-w32-5a3395bc01cd4b11309595a6ecdaf32f8279f378.zip
udhcp: fix indentation and style.
Eliminate (group) a lot of smallish *.h files Remove lots of unneeded #includes
Diffstat (limited to 'networking/udhcp/packet.c')
-rw-r--r--networking/udhcp/packet.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index e861b825a..e79542d08 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -1,10 +1,6 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2#include <unistd.h> 2
3#include <string.h>
4#include <netinet/in.h> 3#include <netinet/in.h>
5#include <sys/types.h>
6#include <sys/socket.h>
7#include <features.h>
8#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION 4#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
9#include <netpacket/packet.h> 5#include <netpacket/packet.h>
10#include <net/ethernet.h> 6#include <net/ethernet.h>
@@ -13,10 +9,8 @@
13#include <linux/if_packet.h> 9#include <linux/if_packet.h>
14#include <linux/if_ether.h> 10#include <linux/if_ether.h>
15#endif 11#endif
16#include <errno.h>
17 12
18#include "common.h" 13#include "common.h"
19#include "packet.h"
20#include "dhcpd.h" 14#include "dhcpd.h"
21#include "options.h" 15#include "options.h"
22 16
@@ -70,8 +64,9 @@ int udhcp_get_packet(struct dhcpMessage *packet, int fd)
70 64
71 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) { 65 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) {
72 for (i = 0; broken_vendors[i][0]; i++) { 66 for (i = 0; broken_vendors[i][0]; i++) {
73 if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) && 67 if (vendor[OPT_LEN - 2] == (uint8_t)strlen(broken_vendors[i])
74 !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])) { 68 && !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])
69 ) {
75 DEBUG("broken client (%s), forcing broadcast", 70 DEBUG("broken client (%s), forcing broadcast",
76 broken_vendors[i]); 71 broken_vendors[i]);
77 packet->flags |= htons(BROADCAST_FLAG); 72 packet->flags |= htons(BROADCAST_FLAG);
@@ -114,15 +109,17 @@ uint16_t udhcp_checksum(void *addr, int count)
114 109
115 110
116/* Construct a ip/udp header for a packet, and specify the source and dest hardware address */ 111/* Construct a ip/udp header for a packet, and specify the source and dest hardware address */
117int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, 112int udhcp_raw_packet(struct dhcpMessage *payload,
118 uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex) 113 uint32_t source_ip, int source_port,
114 uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex)
119{ 115{
120 int fd; 116 int fd;
121 int result; 117 int result;
122 struct sockaddr_ll dest; 118 struct sockaddr_ll dest;
123 struct udp_dhcp_packet packet; 119 struct udp_dhcp_packet packet;
124 120
125 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { 121 fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
122 if (fd < 0) {
126 bb_perror_msg("socket"); 123 bb_perror_msg("socket");
127 return -1; 124 return -1;
128 } 125 }
@@ -157,7 +154,8 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
157 packet.ip.ttl = IPDEFTTL; 154 packet.ip.ttl = IPDEFTTL;
158 packet.ip.check = udhcp_checksum(&(packet.ip), sizeof(packet.ip)); 155 packet.ip.check = udhcp_checksum(&(packet.ip), sizeof(packet.ip));
159 156
160 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest)); 157 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0,
158 (struct sockaddr *) &dest, sizeof(dest));
161 if (result <= 0) { 159 if (result <= 0) {
162 bb_perror_msg("sendto"); 160 bb_perror_msg("sendto");
163 } 161 }
@@ -167,14 +165,16 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
167 165
168 166
169/* Let the kernel do all the work for packet generation */ 167/* Let the kernel do all the work for packet generation */
170int udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, 168int udhcp_kernel_packet(struct dhcpMessage *payload,
171 uint32_t dest_ip, int dest_port) 169 uint32_t source_ip, int source_port,
170 uint32_t dest_ip, int dest_port)
172{ 171{
173 int n = 1; 172 int n = 1;
174 int fd, result; 173 int fd, result;
175 struct sockaddr_in client; 174 struct sockaddr_in client;
176 175
177 if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) 176 fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
177 if (fd < 0)
178 return -1; 178 return -1;
179 179
180 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) { 180 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) {