diff options
Diffstat (limited to 'networking/nameif.c')
-rw-r--r-- | networking/nameif.c | 42 |
1 files changed, 11 insertions, 31 deletions
diff --git a/networking/nameif.c b/networking/nameif.c index 501e244b1..3fa257263 100644 --- a/networking/nameif.c +++ b/networking/nameif.c | |||
@@ -41,29 +41,6 @@ typedef struct mactable_s { | |||
41 | struct ether_addr *mac; | 41 | struct ether_addr *mac; |
42 | } mactable_t; | 42 | } mactable_t; |
43 | 43 | ||
44 | static unsigned long flags; | ||
45 | |||
46 | static void serror(const char *s, ...) ATTRIBUTE_NORETURN; | ||
47 | |||
48 | static void serror(const char *s, ...) | ||
49 | { | ||
50 | va_list ap; | ||
51 | |||
52 | va_start(ap, s); | ||
53 | |||
54 | if (flags & 1) { | ||
55 | openlog(bb_applet_name, 0, LOG_LOCAL0); | ||
56 | vsyslog(LOG_ERR, s, ap); | ||
57 | closelog(); | ||
58 | } else { | ||
59 | bb_verror_msg(s, ap); | ||
60 | putc('\n', stderr); | ||
61 | } | ||
62 | va_end(ap); | ||
63 | |||
64 | exit(EXIT_FAILURE); | ||
65 | } | ||
66 | |||
67 | /* Check ascii str_macaddr, convert and copy to *mac */ | 44 | /* Check ascii str_macaddr, convert and copy to *mac */ |
68 | static struct ether_addr *cc_macaddr(const char *str_macaddr) | 45 | static struct ether_addr *cc_macaddr(const char *str_macaddr) |
69 | { | 46 | { |
@@ -71,7 +48,7 @@ static struct ether_addr *cc_macaddr(const char *str_macaddr) | |||
71 | 48 | ||
72 | lmac = ether_aton(str_macaddr); | 49 | lmac = ether_aton(str_macaddr); |
73 | if (lmac == NULL) | 50 | if (lmac == NULL) |
74 | serror("cannot parse MAC %s", str_macaddr); | 51 | bb_error_msg_and_die("cannot parse MAC %s", str_macaddr); |
75 | mac = xmalloc(ETH_ALEN); | 52 | mac = xmalloc(ETH_ALEN); |
76 | memcpy(mac, lmac, ETH_ALEN); | 53 | memcpy(mac, lmac, ETH_ALEN); |
77 | 54 | ||
@@ -88,7 +65,10 @@ int nameif_main(int argc, char **argv) | |||
88 | int if_index = 1; | 65 | int if_index = 1; |
89 | mactable_t *ch; | 66 | mactable_t *ch; |
90 | 67 | ||
91 | flags = bb_getopt_ulflags(argc, argv, "sc:", &fname); | 68 | if (1 & bb_getopt_ulflags(argc, argv, "sc:", &fname)) { |
69 | openlog(bb_applet_name, 0, LOG_LOCAL0); | ||
70 | logmode = LOGMODE_SYSLOG; | ||
71 | } | ||
92 | 72 | ||
93 | if ((argc - optind) & 1) | 73 | if ((argc - optind) & 1) |
94 | bb_show_usage(); | 74 | bb_show_usage(); |
@@ -97,9 +77,9 @@ int nameif_main(int argc, char **argv) | |||
97 | char **a = argv + optind; | 77 | char **a = argv + optind; |
98 | 78 | ||
99 | while (*a) { | 79 | while (*a) { |
100 | |||
101 | if (strlen(*a) > IF_NAMESIZE) | 80 | if (strlen(*a) > IF_NAMESIZE) |
102 | serror("interface name `%s' too long", *a); | 81 | bb_error_msg_and_die("interface name `%s' " |
82 | "too long", *a); | ||
103 | ch = xzalloc(sizeof(mactable_t)); | 83 | ch = xzalloc(sizeof(mactable_t)); |
104 | ch->ifname = xstrdup(*a++); | 84 | ch->ifname = xstrdup(*a++); |
105 | ch->mac = cc_macaddr(*a++); | 85 | ch->mac = cc_macaddr(*a++); |
@@ -124,7 +104,8 @@ int nameif_main(int argc, char **argv) | |||
124 | ch = xzalloc(sizeof(mactable_t)); | 104 | ch = xzalloc(sizeof(mactable_t)); |
125 | ch->ifname = xstrndup(line_ptr, name_length); | 105 | ch->ifname = xstrndup(line_ptr, name_length); |
126 | if (name_length > IF_NAMESIZE) | 106 | if (name_length > IF_NAMESIZE) |
127 | serror("interface name `%s' too long", ch->ifname); | 107 | bb_error_msg_and_die("interface name `%s' " |
108 | "too long", ch->ifname); | ||
128 | line_ptr += name_length; | 109 | line_ptr += name_length; |
129 | line_ptr += strspn(line_ptr, " \t"); | 110 | line_ptr += strspn(line_ptr, " \t"); |
130 | name_length = strspn(line_ptr, "0123456789ABCDEFabcdef:"); | 111 | name_length = strspn(line_ptr, "0123456789ABCDEFabcdef:"); |
@@ -139,8 +120,7 @@ int nameif_main(int argc, char **argv) | |||
139 | fclose(ifh); | 120 | fclose(ifh); |
140 | } | 121 | } |
141 | 122 | ||
142 | if ((ctl_sk = socket(PF_INET, SOCK_DGRAM, 0)) == -1) | 123 | ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0); |
143 | serror("socket: %m"); | ||
144 | 124 | ||
145 | while (clist) { | 125 | while (clist) { |
146 | struct ifreq ifr; | 126 | struct ifreq ifr; |
@@ -168,7 +148,7 @@ int nameif_main(int argc, char **argv) | |||
168 | 148 | ||
169 | strcpy(ifr.ifr_newname, ch->ifname); | 149 | strcpy(ifr.ifr_newname, ch->ifname); |
170 | if (ioctl(ctl_sk, SIOCSIFNAME, &ifr) < 0) | 150 | if (ioctl(ctl_sk, SIOCSIFNAME, &ifr) < 0) |
171 | serror("cannot change ifname %s to %s: %m", | 151 | bb_perror_msg_and_die("cannot change ifname %s to %s", |
172 | ifr.ifr_name, ch->ifname); | 152 | ifr.ifr_name, ch->ifname); |
173 | 153 | ||
174 | /* Remove list entry of renamed interface */ | 154 | /* Remove list entry of renamed interface */ |