Changeset 3306 for branches/3.2


Ignore:
Timestamp:
Jul 2, 2014, 10:34:07 PM (5 years ago)
Author:
bruno
Message:
  • Fix busybox 1.21.1 to support back old distributions such as RHEL3 and RHEL4 or SLES9 by avoiding usgae of the struct tpacket_auxdata
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/networking/udhcp/dhcpc.c

    r3232 r3306  
    2626#include "dhcpc.h"
    2727
    28 #include <netinet/if_ether.h>
     28#include <asm/types.h>
     29#if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION)
     30# include <netpacket/packet.h>
     31# include <net/ethernet.h>
     32#else
     33# include <linux/if_packet.h>
     34# include <linux/if_ether.h>
     35#endif
    2936#include <linux/filter.h>
    30 #include <linux/if_packet.h>
    3137
    3238/* "struct client_config_t client_config" is in bb_common_bufsiz1 */
     
    837843    struct ip_udp_dhcp_packet packet;
    838844    uint16_t check;
     845#ifdef PACKET_AUXDATA
    839846    unsigned char cmsgbuf[CMSG_LEN(sizeof(struct tpacket_auxdata))];
     847    struct cmsghdr *cmsg;
     848#endif
    840849    struct iovec iov;
    841850    struct msghdr msg;
    842     struct cmsghdr *cmsg;
    843 
     851
     852#ifdef PACKET_AUXDATA
    844853    /* used to use just safe_read(fd, &packet, sizeof(packet))
    845854     * but we need to check for TP_STATUS_CSUMNOTREADY :(
     
    863872        break;
    864873    }
     874#else
     875    memset(&packet, 0, sizeof(packet));
     876    bytes = safe_read(fd, &packet, sizeof(packet));
     877    if (bytes < 0) {
     878        log1("Packet read error, ignoring");
     879        /* NB: possible down interface, etc. Caller should pause. */
     880        return bytes; /* returns -1 */
     881    }
     882#endif
    865883
    866884    if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) {
     
    898916    }
    899917
     918#ifdef PACKET_AUXDATA
    900919    for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
    901920        if (cmsg->cmsg_level == SOL_PACKET
     
    911930        }
    912931    }
     932#endif
    913933
    914934    /* verify UDP checksum. IP header has to be modified for this */
     
    922942        return -2;
    923943    }
     944#ifdef PACKET_AUXDATA
    924945 skip_udp_sum_check:
     946#endif
    925947
    926948    if (packet.data.cookie != htonl(DHCP_MAGIC)) {
     
    10331055    }
    10341056
     1057#ifdef PACKET_AUXDATA
    10351058    if (setsockopt(fd, SOL_PACKET, PACKET_AUXDATA,
    10361059            &const_int_1, sizeof(int)) < 0
     
    10391062            log1("Can't set PACKET_AUXDATA on raw socket");
    10401063    }
     1064#else
     1065    sock.sll_family = AF_PACKET;
     1066    sock.sll_protocol = htons(ETH_P_IP);
     1067    sock.sll_ifindex = ifindex;
     1068    xbind(fd, (struct sockaddr *) &sock, sizeof(sock));
     1069#endif
    10411070
    10421071    log1("Created raw socket");
Note: See TracChangeset for help on using the changeset viewer.