Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

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

    r2725 r3232  
    2323 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    2424 */
     25#include "common.h"
    2526#include <net/if.h>
    26 #if (defined(__GLIBC__) && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
    27 # include <netpacket/packet.h>
    28 # include <net/ethernet.h>
    29 #else
    30 # include <asm/types.h>
    31 # include <linux/if_packet.h>
    32 # include <linux/if_ether.h>
    33 #endif
    34 
    35 #include "common.h"
    3627
    3728int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac)
    3829{
     30    /* char buffer instead of bona-fide struct avoids aliasing warning */
     31    char ifr_buf[sizeof(struct ifreq)];
     32    struct ifreq *const ifr = (void *)ifr_buf;
     33
    3934    int fd;
    40     struct ifreq ifr;
    4135    struct sockaddr_in *our_ip;
    4236
    43     memset(&ifr, 0, sizeof(ifr));
     37    memset(ifr, 0, sizeof(*ifr));
    4438    fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
    4539
    46     ifr.ifr_addr.sa_family = AF_INET;
    47     strncpy_IFNAMSIZ(ifr.ifr_name, interface);
     40    ifr->ifr_addr.sa_family = AF_INET;
     41    strncpy_IFNAMSIZ(ifr->ifr_name, interface);
    4842    if (nip) {
    49         if (ioctl_or_perror(fd, SIOCGIFADDR, &ifr,
     43        if (ioctl_or_perror(fd, SIOCGIFADDR, ifr,
    5044            "is interface %s up and configured?", interface)
    5145        ) {
     
    5347            return -1;
    5448        }
    55         our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
     49        our_ip = (struct sockaddr_in *) &ifr->ifr_addr;
    5650        *nip = our_ip->sin_addr.s_addr;
    5751        log1("IP %s", inet_ntoa(our_ip->sin_addr));
     
    5953
    6054    if (ifindex) {
    61         if (ioctl_or_warn(fd, SIOCGIFINDEX, &ifr) != 0) {
     55        if (ioctl_or_warn(fd, SIOCGIFINDEX, ifr) != 0) {
    6256            close(fd);
    6357            return -1;
    6458        }
    65         log1("Adapter index %d", ifr.ifr_ifindex);
    66         *ifindex = ifr.ifr_ifindex;
     59        log1("Adapter index %d", ifr->ifr_ifindex);
     60        *ifindex = ifr->ifr_ifindex;
    6761    }
    6862
    6963    if (mac) {
    70         if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) {
     64        if (ioctl_or_warn(fd, SIOCGIFHWADDR, ifr) != 0) {
    7165            close(fd);
    7266            return -1;
    7367        }
    74         memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);
     68        memcpy(mac, ifr->ifr_hwaddr.sa_data, 6);
    7569        log1("MAC %02x:%02x:%02x:%02x:%02x:%02x",
    7670            mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
     
    8781    int fd;
    8882    struct sockaddr_in addr;
     83    char *colon;
    8984
    9085    log1("Opening listen socket on *:%d %s", port, inf);
     
    9590        bb_perror_msg_and_die("SO_BROADCAST");
    9691
    97     /* NB: bug 1032 says this doesn't work on ethernet aliases (ethN:M) */
     92    /* SO_BINDTODEVICE doesn't work on ethernet aliases (ethN:M) */
     93    colon = strrchr(inf, ':');
     94    if (colon)
     95        *colon = '\0';
     96
    9897    if (setsockopt_bindtodevice(fd, inf))
    9998        xfunc_die(); /* warning is already printed */
     99
     100    if (colon)
     101        *colon = ':';
    100102
    101103    memset(&addr, 0, sizeof(addr));
Note: See TracChangeset for help on using the changeset viewer.