3
0

ifconfig.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. /* vi: set sw=4 ts=4: */
  2. /* ifconfig
  3. *
  4. * Similar to the standard Unix ifconfig, but with only the necessary
  5. * parts for AF_INET, and without any printing of if info (for now).
  6. *
  7. * Bjorn Wesen, Axis Communications AB
  8. *
  9. *
  10. * Authors of the original ifconfig was:
  11. * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  12. *
  13. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  14. */
  15. /*
  16. * Heavily modified by Manuel Novoa III Mar 6, 2001
  17. *
  18. * From initial port to busybox, removed most of the redundancy by
  19. * converting to a table-driven approach. Added several (optional)
  20. * args missing from initial port.
  21. *
  22. * Still missing: media, tunnel.
  23. *
  24. * 2002-04-20
  25. * IPV6 support added by Bart Visscher <magick@linux-fan.com>
  26. */
  27. //usage:#define ifconfig_trivial_usage
  28. //usage: IF_FEATURE_IFCONFIG_STATUS("[-a]") " interface [address]"
  29. //usage:#define ifconfig_full_usage "\n\n"
  30. //usage: "Configure a network interface\n"
  31. //usage: "\n"
  32. //usage: IF_FEATURE_IPV6(
  33. //usage: " [add ADDRESS[/PREFIXLEN]]\n")
  34. //usage: IF_FEATURE_IPV6(
  35. //usage: " [del ADDRESS[/PREFIXLEN]]\n")
  36. //usage: " [[-]broadcast [ADDRESS]] [[-]pointopoint [ADDRESS]]\n"
  37. //usage: " [netmask ADDRESS] [dstaddr ADDRESS]\n"
  38. //usage: IF_FEATURE_IFCONFIG_SLIP(
  39. //usage: " [outfill NN] [keepalive NN]\n")
  40. //usage: " " IF_FEATURE_IFCONFIG_HW("[hw ether" IF_FEATURE_HWIB("|infiniband")" ADDRESS] ") "[metric NN] [mtu NN]\n"
  41. //usage: " [[-]trailers] [[-]arp] [[-]allmulti]\n"
  42. //usage: " [multicast] [[-]promisc] [txqueuelen NN] [[-]dynamic]\n"
  43. //usage: IF_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ(
  44. //usage: " [mem_start NN] [io_addr NN] [irq NN]\n")
  45. //usage: " [up|down] ..."
  46. #include "libbb.h"
  47. #include "inet_common.h"
  48. #include <net/if.h>
  49. #include <net/if_arp.h>
  50. #include <netinet/in.h>
  51. #ifdef HAVE_NET_ETHERNET_H
  52. # include <net/ethernet.h>
  53. #endif
  54. #if ENABLE_FEATURE_IFCONFIG_SLIP
  55. # include <linux/if_slip.h>
  56. #endif
  57. /* I don't know if this is needed for busybox or not. Anyone? */
  58. #define QUESTIONABLE_ALIAS_CASE
  59. /* Defines for glibc2.0 users. */
  60. #ifndef SIOCSIFTXQLEN
  61. # define SIOCSIFTXQLEN 0x8943
  62. # define SIOCGIFTXQLEN 0x8942
  63. #endif
  64. /* ifr_qlen is ifru_ivalue, but it isn't present in 2.0 kernel headers */
  65. #ifndef ifr_qlen
  66. # define ifr_qlen ifr_ifru.ifru_mtu
  67. #endif
  68. #ifndef IFF_DYNAMIC
  69. # define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */
  70. #endif
  71. #if ENABLE_FEATURE_IPV6
  72. struct in6_ifreq {
  73. struct in6_addr ifr6_addr;
  74. uint32_t ifr6_prefixlen;
  75. int ifr6_ifindex;
  76. };
  77. #endif
  78. /*
  79. * Here are the bit masks for the "flags" member of struct options below.
  80. * N_ signifies no arg prefix; M_ signifies arg prefixed by '-'.
  81. * CLR clears the flag; SET sets the flag; ARG signifies (optional) arg.
  82. */
  83. #define N_CLR 0x01
  84. #define M_CLR 0x02
  85. #define N_SET 0x04
  86. #define M_SET 0x08
  87. #define N_ARG 0x10
  88. #define M_ARG 0x20
  89. #define M_MASK (M_CLR | M_SET | M_ARG)
  90. #define N_MASK (N_CLR | N_SET | N_ARG)
  91. #define SET_MASK (N_SET | M_SET)
  92. #define CLR_MASK (N_CLR | M_CLR)
  93. #define SET_CLR_MASK (SET_MASK | CLR_MASK)
  94. #define ARG_MASK (M_ARG | N_ARG)
  95. /*
  96. * Here are the bit masks for the "arg_flags" member of struct options below.
  97. */
  98. /*
  99. * cast type:
  100. * 00 int
  101. * 01 char *
  102. * 02 HOST_COPY in_ether
  103. * 03 HOST_COPY INET_resolve
  104. */
  105. #define A_CAST_TYPE 0x03
  106. /*
  107. * map type:
  108. * 00 not a map type (mem_start, io_addr, irq)
  109. * 04 memstart (unsigned long)
  110. * 08 io_addr (unsigned short)
  111. * 0C irq (unsigned char)
  112. */
  113. #define A_MAP_TYPE 0x0C
  114. #define A_ARG_REQ 0x10 /* Set if an arg is required. */
  115. #define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */
  116. #define A_SET_AFTER 0x40 /* Set a flag at the end. */
  117. #define A_COLON_CHK 0x80 /* Is this needed? See below. */
  118. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  119. #define A_HOSTNAME 0x100 /* Set if it is ip addr. */
  120. #define A_BROADCAST 0x200 /* Set if it is broadcast addr. */
  121. #else
  122. #define A_HOSTNAME 0
  123. #define A_BROADCAST 0
  124. #endif
  125. /*
  126. * These defines are for dealing with the A_CAST_TYPE field.
  127. */
  128. #define A_CAST_CHAR_PTR 0x01
  129. #define A_CAST_RESOLVE 0x01
  130. #define A_CAST_HOST_COPY 0x02
  131. #define A_CAST_HOST_COPY_IN_ETHER A_CAST_HOST_COPY
  132. #define A_CAST_HOST_COPY_RESOLVE (A_CAST_HOST_COPY | A_CAST_RESOLVE)
  133. /*
  134. * These defines are for dealing with the A_MAP_TYPE field.
  135. */
  136. #define A_MAP_ULONG 0x04 /* memstart */
  137. #define A_MAP_USHORT 0x08 /* io_addr */
  138. #define A_MAP_UCHAR 0x0C /* irq */
  139. /*
  140. * Define the bit masks signifying which operations to perform for each arg.
  141. */
  142. #define ARG_METRIC (A_ARG_REQ /*| A_CAST_INT*/)
  143. #define ARG_MTU (A_ARG_REQ /*| A_CAST_INT*/)
  144. #define ARG_TXQUEUELEN (A_ARG_REQ /*| A_CAST_INT*/)
  145. #define ARG_MEM_START (A_ARG_REQ | A_MAP_ULONG)
  146. #define ARG_IO_ADDR (A_ARG_REQ | A_MAP_ULONG)
  147. #define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR)
  148. #define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
  149. #define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
  150. #define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_BROADCAST)
  151. #define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
  152. #define ARG_POINTOPOINT (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
  153. #define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR)
  154. #define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR)
  155. #define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK | A_HOSTNAME)
  156. #define ARG_ADD_DEL (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
  157. struct arg1opt {
  158. const char *name;
  159. unsigned short selector;
  160. unsigned short ifr_offset;
  161. };
  162. struct options {
  163. const char *name;
  164. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  165. const unsigned int flags:6;
  166. const unsigned int arg_flags:10;
  167. #else
  168. const unsigned char flags;
  169. const unsigned char arg_flags;
  170. #endif
  171. const unsigned short selector;
  172. };
  173. #define ifreq_offsetof(x) offsetof(struct ifreq, x)
  174. /*
  175. * Set up the tables. Warning! They must have corresponding order!
  176. */
  177. static const struct arg1opt Arg1Opt[] = {
  178. { "SIFMETRIC", SIOCSIFMETRIC, ifreq_offsetof(ifr_metric) },
  179. { "SIFMTU", SIOCSIFMTU, ifreq_offsetof(ifr_mtu) },
  180. { "SIFTXQLEN", SIOCSIFTXQLEN, ifreq_offsetof(ifr_qlen) },
  181. { "SIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr) },
  182. { "SIFNETMASK", SIOCSIFNETMASK, ifreq_offsetof(ifr_netmask) },
  183. { "SIFBRDADDR", SIOCSIFBRDADDR, ifreq_offsetof(ifr_broadaddr) },
  184. #if ENABLE_FEATURE_IFCONFIG_HW
  185. { "SIFHWADDR", SIOCSIFHWADDR, ifreq_offsetof(ifr_hwaddr) },
  186. #endif
  187. { "SIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr) },
  188. #ifdef SIOCSKEEPALIVE
  189. { "SKEEPALIVE", SIOCSKEEPALIVE, ifreq_offsetof(ifr_data) },
  190. #endif
  191. #ifdef SIOCSOUTFILL
  192. { "SOUTFILL", SIOCSOUTFILL, ifreq_offsetof(ifr_data) },
  193. #endif
  194. #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
  195. { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.mem_start) },
  196. { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.base_addr) },
  197. { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.irq) },
  198. #endif
  199. #if ENABLE_FEATURE_IPV6
  200. { "SIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */
  201. { "DIFADDR", SIOCDIFADDR, ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */
  202. #endif
  203. /* Last entry is for unmatched (assumed to be hostname/address) arg. */
  204. { "SIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr) },
  205. };
  206. static const struct options OptArray[] = {
  207. { "metric", N_ARG, ARG_METRIC, 0 },
  208. { "mtu", N_ARG, ARG_MTU, 0 },
  209. { "txqueuelen", N_ARG, ARG_TXQUEUELEN, 0 },
  210. { "dstaddr", N_ARG, ARG_DSTADDR, 0 },
  211. { "netmask", N_ARG, ARG_NETMASK, 0 },
  212. { "broadcast", N_ARG | M_CLR, ARG_BROADCAST, IFF_BROADCAST },
  213. #if ENABLE_FEATURE_IFCONFIG_HW
  214. { "hw", N_ARG, ARG_HW, 0 },
  215. #endif
  216. { "pointopoint", N_ARG | M_CLR, ARG_POINTOPOINT, IFF_POINTOPOINT },
  217. #ifdef SIOCSKEEPALIVE
  218. { "keepalive", N_ARG, ARG_KEEPALIVE, 0 },
  219. #endif
  220. #ifdef SIOCSOUTFILL
  221. { "outfill", N_ARG, ARG_OUTFILL, 0 },
  222. #endif
  223. #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
  224. { "mem_start", N_ARG, ARG_MEM_START, 0 },
  225. { "io_addr", N_ARG, ARG_IO_ADDR, 0 },
  226. { "irq", N_ARG, ARG_IRQ, 0 },
  227. #endif
  228. #if ENABLE_FEATURE_IPV6
  229. { "add", N_ARG, ARG_ADD_DEL, 0 },
  230. { "del", N_ARG, ARG_ADD_DEL, 0 },
  231. #endif
  232. { "arp", N_CLR | M_SET, 0, IFF_NOARP },
  233. { "trailers", N_CLR | M_SET, 0, IFF_NOTRAILERS },
  234. { "promisc", N_SET | M_CLR, 0, IFF_PROMISC },
  235. { "multicast", N_SET | M_CLR, 0, IFF_MULTICAST },
  236. { "allmulti", N_SET | M_CLR, 0, IFF_ALLMULTI },
  237. { "dynamic", N_SET | M_CLR, 0, IFF_DYNAMIC },
  238. { "up", N_SET, 0, (IFF_UP | IFF_RUNNING) },
  239. { "down", N_CLR, 0, IFF_UP },
  240. { NULL, 0, ARG_HOSTNAME, (IFF_UP | IFF_RUNNING) }
  241. };
  242. int ifconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  243. int ifconfig_main(int argc UNUSED_PARAM, char **argv)
  244. {
  245. struct ifreq ifr;
  246. struct sockaddr_in sai;
  247. #if ENABLE_FEATURE_IFCONFIG_HW
  248. struct sockaddr sa;
  249. #endif
  250. const struct arg1opt *a1op;
  251. const struct options *op;
  252. int sockfd; /* socket fd we use to manipulate stuff with */
  253. int selector;
  254. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  255. unsigned int mask;
  256. unsigned int did_flags;
  257. unsigned int sai_hostname, sai_netmask;
  258. #else
  259. unsigned char mask;
  260. unsigned char did_flags;
  261. #endif
  262. char *p;
  263. /*char host[128];*/
  264. const char *host = NULL; /* make gcc happy */
  265. did_flags = 0;
  266. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  267. sai_hostname = 0;
  268. sai_netmask = 0;
  269. #endif
  270. /* skip argv[0] */
  271. ++argv;
  272. #if ENABLE_FEATURE_IFCONFIG_STATUS
  273. if (argv[0] && (argv[0][0] == '-' && argv[0][1] == 'a' && !argv[0][2])) {
  274. interface_opt_a = 1;
  275. ++argv;
  276. }
  277. #endif
  278. if (!argv[0] || !argv[1]) { /* one or no args */
  279. #if ENABLE_FEATURE_IFCONFIG_STATUS
  280. return display_interfaces(argv[0] /* can be NULL */);
  281. #else
  282. bb_error_msg_and_die("no support for status display");
  283. #endif
  284. }
  285. /* Create a channel to the NET kernel. */
  286. sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
  287. /* get interface name */
  288. strncpy_IFNAMSIZ(ifr.ifr_name, *argv);
  289. /* Process the remaining arguments. */
  290. while (*++argv != NULL) {
  291. p = *argv;
  292. mask = N_MASK;
  293. if (*p == '-') { /* If the arg starts with '-'... */
  294. ++p; /* advance past it and */
  295. mask = M_MASK; /* set the appropriate mask. */
  296. }
  297. for (op = OptArray; op->name; op++) { /* Find table entry. */
  298. if (strcmp(p, op->name) == 0) { /* If name matches... */
  299. mask &= op->flags;
  300. if (mask) /* set the mask and go. */
  301. goto FOUND_ARG;
  302. /* If we get here, there was a valid arg with an */
  303. /* invalid '-' prefix. */
  304. bb_error_msg_and_die("bad: '%s'", p-1);
  305. }
  306. }
  307. /* We fell through, so treat as possible hostname. */
  308. a1op = Arg1Opt + ARRAY_SIZE(Arg1Opt) - 1;
  309. mask = op->arg_flags;
  310. goto HOSTNAME;
  311. FOUND_ARG:
  312. if (mask & ARG_MASK) {
  313. mask = op->arg_flags;
  314. if (mask & A_NETMASK & did_flags)
  315. bb_show_usage();
  316. a1op = Arg1Opt + (op - OptArray);
  317. if (*++argv == NULL) {
  318. if (mask & A_ARG_REQ)
  319. bb_show_usage();
  320. --argv;
  321. mask &= A_SET_AFTER; /* just for broadcast */
  322. } else { /* got an arg so process it */
  323. HOSTNAME:
  324. did_flags |= (mask & (A_NETMASK|A_HOSTNAME));
  325. if (mask & A_CAST_HOST_COPY) {
  326. #if ENABLE_FEATURE_IFCONFIG_HW
  327. if (mask & A_CAST_RESOLVE) {
  328. #endif
  329. host = *argv;
  330. if (strcmp(host, "inet") == 0)
  331. continue; /* compat stuff */
  332. sai.sin_family = AF_INET;
  333. sai.sin_port = 0;
  334. if (strcmp(host, "default") == 0) {
  335. /* Default is special, meaning 0.0.0.0. */
  336. sai.sin_addr.s_addr = INADDR_ANY;
  337. }
  338. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  339. else if ((host[0] == '+' && !host[1])
  340. && (mask & A_BROADCAST)
  341. && (did_flags & (A_NETMASK|A_HOSTNAME)) == (A_NETMASK|A_HOSTNAME)
  342. ) {
  343. /* + is special, meaning broadcast is derived. */
  344. sai.sin_addr.s_addr = (~sai_netmask) | (sai_hostname & sai_netmask);
  345. }
  346. #endif
  347. else {
  348. len_and_sockaddr *lsa;
  349. #if ENABLE_FEATURE_IPV6
  350. char *prefix;
  351. int prefix_len = 0;
  352. prefix = strchr(host, '/');
  353. if (prefix) {
  354. prefix_len = xatou_range(prefix + 1, 0, 128);
  355. *prefix = '\0';
  356. }
  357. resolve:
  358. #endif
  359. lsa = xhost2sockaddr(host, 0);
  360. #if ENABLE_FEATURE_IPV6
  361. if (lsa->u.sa.sa_family != AF_INET6 && prefix) {
  362. /* TODO: we do not support "ifconfig eth0 up 1.2.3.4/17".
  363. * For now, just make it fail instead of silently ignoring "/17" part:
  364. */
  365. *prefix = '/';
  366. goto resolve;
  367. }
  368. if (lsa->u.sa.sa_family == AF_INET6) {
  369. int sockfd6;
  370. struct in6_ifreq ifr6;
  371. sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0);
  372. xioctl(sockfd6, SIOCGIFINDEX, &ifr);
  373. ifr6.ifr6_ifindex = ifr.ifr_ifindex;
  374. ifr6.ifr6_prefixlen = prefix_len;
  375. memcpy(&ifr6.ifr6_addr,
  376. &lsa->u.sin6.sin6_addr,
  377. sizeof(struct in6_addr));
  378. ioctl_or_perror_and_die(sockfd6, a1op->selector, &ifr6, "SIOC%s", a1op->name);
  379. if (ENABLE_FEATURE_CLEAN_UP)
  380. free(lsa);
  381. continue;
  382. }
  383. #endif
  384. sai.sin_addr = lsa->u.sin.sin_addr;
  385. if (ENABLE_FEATURE_CLEAN_UP)
  386. free(lsa);
  387. }
  388. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  389. if (mask & A_HOSTNAME)
  390. sai_hostname = sai.sin_addr.s_addr;
  391. if (mask & A_NETMASK)
  392. sai_netmask = sai.sin_addr.s_addr;
  393. #endif
  394. p = (char *) &sai;
  395. #if ENABLE_FEATURE_IFCONFIG_HW
  396. } else { /* A_CAST_HOST_COPY_IN_ETHER */
  397. /* This is the "hw" arg case. */
  398. smalluint hw_class = index_in_substrings("ether\0"
  399. IF_FEATURE_HWIB("infiniband\0"), *argv) + 1;
  400. if (!hw_class || !*++argv)
  401. bb_show_usage();
  402. host = *argv;
  403. if (hw_class == 1 ? in_ether(host, &sa) : in_ib(host, &sa))
  404. bb_error_msg_and_die("invalid hw-addr %s", host);
  405. p = (char *) &sa;
  406. }
  407. #endif
  408. memcpy( ((char *)&ifr) + a1op->ifr_offset,
  409. p, sizeof(struct sockaddr));
  410. } else {
  411. /* FIXME: error check?? */
  412. unsigned long i = strtoul(*argv, NULL, 0);
  413. p = ((char *)&ifr) + a1op->ifr_offset;
  414. #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
  415. if (mask & A_MAP_TYPE) {
  416. xioctl(sockfd, SIOCGIFMAP, &ifr);
  417. if ((mask & A_MAP_UCHAR) == A_MAP_UCHAR)
  418. *(unsigned char *) p = i;
  419. else if (mask & A_MAP_USHORT)
  420. *(unsigned short *) p = i;
  421. else
  422. *(unsigned long *) p = i;
  423. } else
  424. #endif
  425. if (mask & A_CAST_CHAR_PTR)
  426. *(caddr_t *) p = (caddr_t) i;
  427. else /* A_CAST_INT */
  428. *(int *) p = i;
  429. }
  430. ioctl_or_perror_and_die(sockfd, a1op->selector, &ifr, "SIOC%s", a1op->name);
  431. #ifdef QUESTIONABLE_ALIAS_CASE
  432. if (mask & A_COLON_CHK) {
  433. /*
  434. * Don't do the set_flag() if the address is an alias with
  435. * a '-' at the end, since it's deleted already! - Roman
  436. *
  437. * Should really use regex.h here, not sure though how well
  438. * it'll go with the cross-platform support etc.
  439. */
  440. char *ptr;
  441. short int found_colon = 0;
  442. for (ptr = ifr.ifr_name; *ptr; ptr++)
  443. if (*ptr == ':')
  444. found_colon++;
  445. if (found_colon && ptr[-1] == '-')
  446. continue;
  447. }
  448. #endif
  449. }
  450. if (!(mask & A_SET_AFTER))
  451. continue;
  452. mask = N_SET;
  453. } /* if (mask & ARG_MASK) */
  454. xioctl(sockfd, SIOCGIFFLAGS, &ifr);
  455. selector = op->selector;
  456. if (mask & SET_MASK)
  457. ifr.ifr_flags |= selector;
  458. else
  459. ifr.ifr_flags &= ~selector;
  460. xioctl(sockfd, SIOCSIFFLAGS, &ifr);
  461. } /* while () */
  462. if (ENABLE_FEATURE_CLEAN_UP)
  463. close(sockfd);
  464. return 0;
  465. }