Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/networking/nameif.c

    r821 r1765  
     1/* vi: set sw=4 ts=4: */
    12/*
    23 * nameif.c - Naming Interfaces based on MAC address for busybox.
     
    910 */
    1011
    11 #include "busybox.h"
    12 
    13 #include <sys/syslog.h>
    14 #include <sys/socket.h>
    15 #include <sys/ioctl.h>
    16 #include <errno.h>
    17 #include <string.h>
    18 #include <unistd.h>
     12#include "libbb.h"
     13#include <syslog.h>
    1914#include <net/if.h>
    2015#include <netinet/ether.h>
     
    4742} mactable_t;
    4843
    49 static unsigned long flags;
    50 
    51 static void serror(const char *s, ...) ATTRIBUTE_NORETURN;
    52 
    53 static void serror(const char *s, ...)
    54 {
    55     va_list ap;
    56 
    57     va_start(ap, s);
    58 
    59     if (flags & 1) {
    60         openlog(bb_applet_name, 0, LOG_LOCAL0);
    61         vsyslog(LOG_ERR, s, ap);
    62         closelog();
    63     } else {
    64         bb_verror_msg(s, ap);
    65         putc('\n', stderr);
    66     }
    67     va_end(ap);
    68 
    69     exit(EXIT_FAILURE);
    70 }
    71 
    7244/* Check ascii str_macaddr, convert and copy to *mac */
    7345static struct ether_addr *cc_macaddr(const char *str_macaddr)
     
    7749    lmac = ether_aton(str_macaddr);
    7850    if (lmac == NULL)
    79         serror("cannot parse MAC %s", str_macaddr);
     51        bb_error_msg_and_die("cannot parse MAC %s", str_macaddr);
    8052    mac = xmalloc(ETH_ALEN);
    8153    memcpy(mac, lmac, ETH_ALEN);
     
    8456}
    8557
     58int nameif_main(int argc, char **argv);
    8659int nameif_main(int argc, char **argv)
    8760{
     
    9467    mactable_t *ch;
    9568
    96     flags = bb_getopt_ulflags(argc, argv, "sc:", &fname);
     69    if (1 & getopt32(argv, "sc:", &fname)) {
     70        openlog(applet_name, 0, LOG_LOCAL0);
     71        logmode = LOGMODE_SYSLOG;
     72    }
    9773
    9874    if ((argc - optind) & 1)
     
    10379
    10480        while (*a) {
    105 
    10681            if (strlen(*a) > IF_NAMESIZE)
    107                 serror("interface name `%s' too long", *a);
     82                bb_error_msg_and_die("interface name '%s' "
     83                        "too long", *a);
    10884            ch = xzalloc(sizeof(mactable_t));
    109             ch->ifname = bb_xstrdup(*a++);
     85            ch->ifname = xstrdup(*a++);
    11086            ch->mac = cc_macaddr(*a++);
    11187            if (clist)
     
    11591        }
    11692    } else {
    117         ifh = bb_xfopen(fname, "r");
     93        ifh = xfopen(fname, "r");
    11894
    119         while ((line = bb_get_line_from_file(ifh)) != NULL) {
     95        while ((line = xmalloc_fgets(ifh)) != NULL) {
    12096            char *line_ptr;
    12197            size_t name_length;
     
    128104            name_length = strcspn(line_ptr, " \t");
    129105            ch = xzalloc(sizeof(mactable_t));
    130             ch->ifname = bb_xstrndup(line_ptr, name_length);
     106            ch->ifname = xstrndup(line_ptr, name_length);
    131107            if (name_length > IF_NAMESIZE)
    132                 serror("interface name `%s' too long", ch->ifname);
     108                bb_error_msg_and_die("interface name '%s' "
     109                        "too long", ch->ifname);
    133110            line_ptr += name_length;
    134111            line_ptr += strspn(line_ptr, " \t");
     
    145122    }
    146123
    147     if ((ctl_sk = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
    148         serror("socket: %m");
     124    ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0);
    149125
    150126    while (clist) {
     
    173149
    174150        strcpy(ifr.ifr_newname, ch->ifname);
    175         if (ioctl(ctl_sk, SIOCSIFNAME, &ifr) < 0)
    176             serror("cannot change ifname %s to %s: %m",
    177                    ifr.ifr_name, ch->ifname);
     151        ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr,
     152                    "cannot change ifname %s to %s",
     153                    ifr.ifr_name, ch->ifname);
    178154
    179155        /* Remove list entry of renamed interface */
Note: See TracChangeset for help on using the changeset viewer.