1 diff -ur busybox-1.19.4.orig/networking/udhcp/dhcpc.c busybox-1.19.4/networking/udhcp/dhcpc.c
2 --- busybox-1.19.4.orig/networking/udhcp/dhcpc.c 2012-09-06 22:33:53.476998721 +0400
3 +++ busybox-1.19.4/networking/udhcp/dhcpc.c 2012-09-07 01:09:46.693372304 +0400
7 #include <netinet/if_ether.h>
8 -#include <netpacket/packet.h>
9 #include <linux/filter.h>
10 +#include <linux/if_packet.h>
12 /* struct client_config_t client_config is in bb_common_bufsiz1 */
15 static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
19 struct ip_udp_dhcp_packet packet;
21 + unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
22 + struct iovec iov = {
23 + .iov_base = &packet,
24 + .iov_len = sizeof(packet),
26 + struct msghdr msg = {
29 + .msg_control = cmsgbuf,
30 + .msg_controllen = sizeof(cmsgbuf),
32 + struct cmsghdr *cmsg;
34 memset(&packet, 0, sizeof(packet));
35 - bytes = safe_read(fd, &packet, sizeof(packet));
37 + bytes = recvmsg(fd, &msg, 0);
38 + } while (bytes < 0 && errno == EINTR);
41 log1("Packet read error, ignoring");
42 /* NB: possible down interface, etc. Caller should pause. */
43 return bytes; /* returns -1 */
46 + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
47 + if (cmsg->cmsg_level == SOL_PACKET &&
48 + cmsg->cmsg_type == PACKET_AUXDATA) {
49 + struct tpacket_auxdata *aux = (void *)CMSG_DATA(cmsg);
50 + nocsum = aux->tp_status & TP_STATUS_CSUMNOTREADY;
54 if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) {
55 log1("Packet is too short, ignoring");
58 packet.ip.tot_len = packet.udp.len; /* yes, this is needed */
59 check = packet.udp.check;
61 - if (check && check != udhcp_checksum(&packet, bytes)) {
62 + if (!nocsum && check && check != udhcp_checksum(&packet, bytes)) {
63 log1("Packet with bad UDP checksum received, ignoring");
69 struct sockaddr_ll sock;
75 log1("Attached filter to raw socket fd %d", fd); // log?
79 + if (setsockopt(fd, SOL_PACKET, PACKET_AUXDATA, &val,
81 + if (errno != ENOPROTOOPT)
82 + log1("Failed to set auxiliary packet data for socket fd %d", fd);
85 log1("Created raw socket");