Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/networking/nameif.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/networking/nameif.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * nameif.c - Naming Interfaces based on MAC address for busybox. … … 9 10 */ 10 11 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> 19 14 #include <net/if.h> 20 15 #include <netinet/ether.h> … … 47 42 } mactable_t; 48 43 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 72 44 /* Check ascii str_macaddr, convert and copy to *mac */ 73 45 static struct ether_addr *cc_macaddr(const char *str_macaddr) … … 77 49 lmac = ether_aton(str_macaddr); 78 50 if (lmac == NULL) 79 serror("cannot parse MAC %s", str_macaddr);51 bb_error_msg_and_die("cannot parse MAC %s", str_macaddr); 80 52 mac = xmalloc(ETH_ALEN); 81 53 memcpy(mac, lmac, ETH_ALEN); … … 84 56 } 85 57 58 int nameif_main(int argc, char **argv); 86 59 int nameif_main(int argc, char **argv) 87 60 { … … 94 67 mactable_t *ch; 95 68 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 } 97 73 98 74 if ((argc - optind) & 1) … … 103 79 104 80 while (*a) { 105 106 81 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); 108 84 ch = xzalloc(sizeof(mactable_t)); 109 ch->ifname = bb_xstrdup(*a++);85 ch->ifname = xstrdup(*a++); 110 86 ch->mac = cc_macaddr(*a++); 111 87 if (clist) … … 115 91 } 116 92 } else { 117 ifh = bb_xfopen(fname, "r");93 ifh = xfopen(fname, "r"); 118 94 119 while ((line = bb_get_line_from_file(ifh)) != NULL) {95 while ((line = xmalloc_fgets(ifh)) != NULL) { 120 96 char *line_ptr; 121 97 size_t name_length; … … 128 104 name_length = strcspn(line_ptr, " \t"); 129 105 ch = xzalloc(sizeof(mactable_t)); 130 ch->ifname = bb_xstrndup(line_ptr, name_length);106 ch->ifname = xstrndup(line_ptr, name_length); 131 107 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); 133 110 line_ptr += name_length; 134 111 line_ptr += strspn(line_ptr, " \t"); … … 145 122 } 146 123 147 if ((ctl_sk = socket(PF_INET, SOCK_DGRAM, 0)) == -1) 148 serror("socket: %m"); 124 ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0); 149 125 150 126 while (clist) { … … 173 149 174 150 strcpy(ifr.ifr_newname, ch->ifname); 175 i f (ioctl(ctl_sk, SIOCSIFNAME, &ifr) < 0)176 serror("cannot change ifname %s to %s: %m",177 151 ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr, 152 "cannot change ifname %s to %s", 153 ifr.ifr_name, ch->ifname); 178 154 179 155 /* Remove list entry of renamed interface */
Note:
See TracChangeset
for help on using the changeset viewer.