Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/networking/ifconfig.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/networking/ifconfig.c
r1765 r2725 11 11 * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> 12 12 * 13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.13 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 14 14 */ 15 15 … … 37 37 #include <netinet/if_ether.h> 38 38 #endif 39 #include "libbb.h" 39 40 #include "inet_common.h" 40 #include "libbb.h"41 41 42 42 #if ENABLE_FEATURE_IFCONFIG_SLIP … … 165 165 struct arg1opt { 166 166 const char *name; 167 int selector;167 unsigned short selector; 168 168 unsigned short ifr_offset; 169 169 }; … … 184 184 185 185 static const struct arg1opt Arg1Opt[] = { 186 { "SIOCSIFMETRIC", SIOCSIFMETRIC, ifreq_offsetof(ifr_metric)},187 { "SIOCSIFMTU", SIOCSIFMTU, ifreq_offsetof(ifr_mtu)},188 { "SIOCSIFTXQLEN", SIOCSIFTXQLEN, ifreq_offsetof(ifr_qlen)},189 { "SIOCSIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr)},190 { "SIOCSIFNETMASK", SIOCSIFNETMASK, ifreq_offsetof(ifr_netmask)},191 { "SIOCSIFBRDADDR", SIOCSIFBRDADDR, ifreq_offsetof(ifr_broadaddr)},192 #if ENABLE_FEATURE_IFCONFIG_HW 193 { "SIOCSIFHWADDR", SIOCSIFHWADDR, ifreq_offsetof(ifr_hwaddr)},194 #endif 195 { "SIOCSIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr)},186 { "SIFMETRIC", SIOCSIFMETRIC, ifreq_offsetof(ifr_metric) }, 187 { "SIFMTU", SIOCSIFMTU, ifreq_offsetof(ifr_mtu) }, 188 { "SIFTXQLEN", SIOCSIFTXQLEN, ifreq_offsetof(ifr_qlen) }, 189 { "SIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr) }, 190 { "SIFNETMASK", SIOCSIFNETMASK, ifreq_offsetof(ifr_netmask) }, 191 { "SIFBRDADDR", SIOCSIFBRDADDR, ifreq_offsetof(ifr_broadaddr) }, 192 #if ENABLE_FEATURE_IFCONFIG_HW 193 { "SIFHWADDR", SIOCSIFHWADDR, ifreq_offsetof(ifr_hwaddr) }, 194 #endif 195 { "SIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr) }, 196 196 #ifdef SIOCSKEEPALIVE 197 { "SIOCSKEEPALIVE", SIOCSKEEPALIVE, ifreq_offsetof(ifr_data)},197 { "SKEEPALIVE", SIOCSKEEPALIVE, ifreq_offsetof(ifr_data) }, 198 198 #endif 199 199 #ifdef SIOCSOUTFILL 200 { "SIOCSOUTFILL", SIOCSOUTFILL, ifreq_offsetof(ifr_data)},200 { "SOUTFILL", SIOCSOUTFILL, ifreq_offsetof(ifr_data) }, 201 201 #endif 202 202 #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ 203 { "SIOCSIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.mem_start)},204 { "SIOCSIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.base_addr)},205 { "SIOCSIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.irq)},203 { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.mem_start) }, 204 { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.base_addr) }, 205 { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.irq) }, 206 206 #endif 207 207 /* Last entry if for unmatched (possibly hostname) arg. */ 208 208 #if ENABLE_FEATURE_IPV6 209 { "SIOCSIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr)}, /* IPv6 version ignores the offset */210 { "SIOCDIFADDR", SIOCDIFADDR, ifreq_offsetof(ifr_addr)}, /* IPv6 version ignores the offset */211 #endif 212 { "SIOCSIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr)},209 { "SIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */ 210 { "DIFADDR", SIOCDIFADDR, ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */ 211 #endif 212 { "SIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr) }, 213 213 }; 214 214 215 215 static const struct options OptArray[] = { 216 { "metric", N_ARG, ARG_METRIC, 0},217 { "mtu", N_ARG, ARG_MTU, 0},218 { "txqueuelen", N_ARG, ARG_TXQUEUELEN, 0},219 { "dstaddr", N_ARG, ARG_DSTADDR, 0},220 { "netmask", N_ARG, ARG_NETMASK, 0},221 { "broadcast", N_ARG | M_CLR, ARG_BROADCAST, IFF_BROADCAST},222 #if ENABLE_FEATURE_IFCONFIG_HW 223 { "hw", N_ARG, ARG_HW, 0},224 #endif 225 { "pointopoint", N_ARG | M_CLR, ARG_POINTOPOINT, IFF_POINTOPOINT},216 { "metric", N_ARG, ARG_METRIC, 0 }, 217 { "mtu", N_ARG, ARG_MTU, 0 }, 218 { "txqueuelen", N_ARG, ARG_TXQUEUELEN, 0 }, 219 { "dstaddr", N_ARG, ARG_DSTADDR, 0 }, 220 { "netmask", N_ARG, ARG_NETMASK, 0 }, 221 { "broadcast", N_ARG | M_CLR, ARG_BROADCAST, IFF_BROADCAST }, 222 #if ENABLE_FEATURE_IFCONFIG_HW 223 { "hw", N_ARG, ARG_HW, 0 }, 224 #endif 225 { "pointopoint", N_ARG | M_CLR, ARG_POINTOPOINT, IFF_POINTOPOINT }, 226 226 #ifdef SIOCSKEEPALIVE 227 { "keepalive", N_ARG, ARG_KEEPALIVE, 0},227 { "keepalive", N_ARG, ARG_KEEPALIVE, 0 }, 228 228 #endif 229 229 #ifdef SIOCSOUTFILL 230 { "outfill", N_ARG, ARG_OUTFILL, 0},230 { "outfill", N_ARG, ARG_OUTFILL, 0 }, 231 231 #endif 232 232 #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ 233 { "mem_start", N_ARG, ARG_MEM_START, 0},234 { "io_addr", N_ARG, ARG_IO_ADDR, 0},235 { "irq", N_ARG, ARG_IRQ, 0},233 { "mem_start", N_ARG, ARG_MEM_START, 0 }, 234 { "io_addr", N_ARG, ARG_IO_ADDR, 0 }, 235 { "irq", N_ARG, ARG_IRQ, 0 }, 236 236 #endif 237 237 #if ENABLE_FEATURE_IPV6 238 { "add", N_ARG, ARG_ADD_DEL, 0},239 { "del", N_ARG, ARG_ADD_DEL, 0},240 #endif 241 { "arp", N_CLR | M_SET, 0, IFF_NOARP},242 { "trailers", N_CLR | M_SET, 0, IFF_NOTRAILERS},243 { "promisc", N_SET | M_CLR, 0, IFF_PROMISC},244 { "multicast", N_SET | M_CLR, 0, IFF_MULTICAST},245 { "allmulti", N_SET | M_CLR, 0, IFF_ALLMULTI},246 { "dynamic", N_SET | M_CLR, 0, IFF_DYNAMIC},247 { "up", N_SET, 0, (IFF_UP | IFF_RUNNING)},248 { "down", N_CLR, 0, IFF_UP},249 { NULL, 0, ARG_HOSTNAME, (IFF_UP | IFF_RUNNING)}238 { "add", N_ARG, ARG_ADD_DEL, 0 }, 239 { "del", N_ARG, ARG_ADD_DEL, 0 }, 240 #endif 241 { "arp", N_CLR | M_SET, 0, IFF_NOARP }, 242 { "trailers", N_CLR | M_SET, 0, IFF_NOTRAILERS }, 243 { "promisc", N_SET | M_CLR, 0, IFF_PROMISC }, 244 { "multicast", N_SET | M_CLR, 0, IFF_MULTICAST }, 245 { "allmulti", N_SET | M_CLR, 0, IFF_ALLMULTI }, 246 { "dynamic", N_SET | M_CLR, 0, IFF_DYNAMIC }, 247 { "up", N_SET, 0, (IFF_UP | IFF_RUNNING) }, 248 { "down", N_CLR, 0, IFF_UP }, 249 { NULL, 0, ARG_HOSTNAME, (IFF_UP | IFF_RUNNING) } 250 250 }; 251 251 … … 253 253 * A couple of prototypes. 254 254 */ 255 256 255 #if ENABLE_FEATURE_IFCONFIG_HW 257 256 static int in_ether(const char *bufp, struct sockaddr *sap); … … 261 260 * Our main function. 262 261 */ 263 264 int ifconfig_main(int argc, char **argv); 265 int ifconfig_main(int argc, char **argv) 262 int ifconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 263 int ifconfig_main(int argc UNUSED_PARAM, char **argv) 266 264 { 267 265 struct ifreq ifr; … … 294 292 /* skip argv[0] */ 295 293 ++argv; 296 --argc;297 294 298 295 #if ENABLE_FEATURE_IFCONFIG_STATUS 299 if (arg c > 0&& (argv[0][0] == '-' && argv[0][1] == 'a' && !argv[0][2])) {296 if (argv[0] && (argv[0][0] == '-' && argv[0][1] == 'a' && !argv[0][2])) { 300 297 interface_opt_a = 1; 301 --argc;302 298 ++argv; 303 299 } 304 300 #endif 305 301 306 if ( argc <= 1) {302 if (!argv[0] || !argv[1]) { /* one or no args */ 307 303 #if ENABLE_FEATURE_IFCONFIG_STATUS 308 return display_interfaces(arg c ? *argv : NULL);304 return display_interfaces(argv[0] /* can be NULL */); 309 305 #else 310 306 bb_error_msg_and_die("no support for status display"); … … 316 312 317 313 /* get interface name */ 318 s afe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ);314 strncpy_IFNAMSIZ(ifr.ifr_name, *argv); 319 315 320 316 /* Process the remaining arguments. */ … … 375 371 sai.sin_family = AF_INET; 376 372 sai.sin_port = 0; 377 if ( !strcmp(host, bb_str_default)) {373 if (strcmp(host, "default") == 0) { 378 374 /* Default is special, meaning 0.0.0.0. */ 379 375 sai.sin_addr.s_addr = INADDR_ANY; … … 393 389 lsa = xhost2sockaddr(host, 0); 394 390 #if ENABLE_FEATURE_IPV6 395 if (lsa-> sa.sa_family == AF_INET6) {391 if (lsa->u.sa.sa_family == AF_INET6) { 396 392 int sockfd6; 397 393 struct in6_ifreq ifr6; 398 394 399 395 memcpy((char *) &ifr6.ifr6_addr, 400 (char *) &(lsa-> sin6.sin6_addr),396 (char *) &(lsa->u.sin6.sin6_addr), 401 397 sizeof(struct in6_addr)); 402 398 … … 406 402 ifr6.ifr6_ifindex = ifr.ifr_ifindex; 407 403 ifr6.ifr6_prefixlen = prefix_len; 408 ioctl_or_perror_and_die(sockfd6, a1op->selector, &ifr6, " %s", a1op->name);404 ioctl_or_perror_and_die(sockfd6, a1op->selector, &ifr6, "SIOC%s", a1op->name); 409 405 if (ENABLE_FEATURE_CLEAN_UP) 410 406 free(lsa); … … 412 408 } 413 409 #endif 414 sai.sin_addr = lsa-> sin.sin_addr;410 sai.sin_addr = lsa->u.sin.sin_addr; 415 411 if (ENABLE_FEATURE_CLEAN_UP) 416 412 free(lsa); … … 426 422 } else { /* A_CAST_HOST_COPY_IN_ETHER */ 427 423 /* This is the "hw" arg case. */ 428 if (strcmp("ether", *argv) || !*++argv) 424 smalluint hw_class= index_in_substrings("ether\0" 425 IF_FEATURE_HWIB("infiniband\0"), *argv) + 1; 426 if (!hw_class || !*++argv) 429 427 bb_show_usage(); 430 428 /*safe_strncpy(host, *argv, sizeof(host));*/ 431 429 host = *argv; 432 if ( in_ether(host, &sa))430 if (hw_class == 1 ? in_ether(host, &sa) : in_ib(host, &sa)) 433 431 bb_error_msg_and_die("invalid hw-addr %s", host); 434 432 p = (char *) &sa; … … 458 456 } 459 457 460 ioctl_or_perror_and_die(sockfd, a1op->selector, &ifr, " %s", a1op->name);458 ioctl_or_perror_and_die(sockfd, a1op->selector, &ifr, "SIOC%s", a1op->name); 461 459 #ifdef QUESTIONABLE_ALIAS_CASE 462 460 if (mask & A_COLON_CHK) { … … 507 505 508 506 sap->sa_family = ARPHRD_ETHER; 509 ptr = sap->sa_data;507 ptr = (char *) sap->sa_data; 510 508 511 509 i = 0;
Note:
See TracChangeset
for help on using the changeset viewer.