wget: don't notify on download begin and end if quiet
[oweals/busybox.git] / networking / ifconfig.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * ifconfig
4  *
5  * Similar to the standard Unix ifconfig, but with only the necessary
6  * parts for AF_INET, and without any printing of if info (for now).
7  *
8  * Bjorn Wesen, Axis Communications AB
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 //config:config IFCONFIG
28 //config:       bool "ifconfig (12 kb)"
29 //config:       default y
30 //config:       select PLATFORM_LINUX
31 //config:       help
32 //config:       Ifconfig is used to configure the kernel-resident network interfaces.
33 //config:
34 //config:config FEATURE_IFCONFIG_STATUS
35 //config:       bool "Enable status reporting output (+7k)"
36 //config:       default y
37 //config:       depends on IFCONFIG
38 //config:       help
39 //config:       If ifconfig is called with no arguments it will display the status
40 //config:       of the currently active interfaces.
41 //config:
42 //config:config FEATURE_IFCONFIG_SLIP
43 //config:       bool "Enable slip-specific options \"keepalive\" and \"outfill\""
44 //config:       default y
45 //config:       depends on IFCONFIG
46 //config:       help
47 //config:       Allow "keepalive" and "outfill" support for SLIP. If you're not
48 //config:       planning on using serial lines, leave this unchecked.
49 //config:
50 //config:config FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
51 //config:       bool "Enable options \"mem_start\", \"io_addr\", and \"irq\""
52 //config:       default y
53 //config:       depends on IFCONFIG
54 //config:       help
55 //config:       Allow the start address for shared memory, start address for I/O,
56 //config:       and/or the interrupt line used by the specified device.
57 //config:
58 //config:config FEATURE_IFCONFIG_HW
59 //config:       bool "Enable option \"hw\" (ether only)"
60 //config:       default y
61 //config:       depends on IFCONFIG
62 //config:       help
63 //config:       Set the hardware address of this interface, if the device driver
64 //config:       supports  this  operation. Currently, we only support the 'ether'
65 //config:       class.
66 //config:
67 //config:config FEATURE_IFCONFIG_BROADCAST_PLUS
68 //config:       bool "Set the broadcast automatically"
69 //config:       default y
70 //config:       depends on IFCONFIG
71 //config:       help
72 //config:       Setting this will make ifconfig attempt to find the broadcast
73 //config:       automatically if the value '+' is used.
74
75 //applet:IF_IFCONFIG(APPLET(ifconfig, BB_DIR_SBIN, BB_SUID_DROP))
76
77 //kbuild:lib-$(CONFIG_IFCONFIG) += ifconfig.o interface.o
78
79 //usage:#define ifconfig_trivial_usage
80 //usage:        IF_FEATURE_IFCONFIG_STATUS("[-a]") " interface [address]"
81 //usage:#define ifconfig_full_usage "\n\n"
82 //usage:       "Configure a network interface\n"
83 //usage:     "\n"
84 //usage:        IF_FEATURE_IPV6(
85 //usage:       "        [add ADDRESS[/PREFIXLEN]]\n")
86 //usage:        IF_FEATURE_IPV6(
87 //usage:       "        [del ADDRESS[/PREFIXLEN]]\n")
88 //usage:       "        [[-]broadcast [ADDRESS]] [[-]pointopoint [ADDRESS]]\n"
89 //usage:       "        [netmask ADDRESS] [dstaddr ADDRESS]\n"
90 //usage:        IF_FEATURE_IFCONFIG_SLIP(
91 //usage:       "        [outfill NN] [keepalive NN]\n")
92 //usage:       "        " IF_FEATURE_IFCONFIG_HW("[hw ether" IF_FEATURE_HWIB("|infiniband")" ADDRESS] ") "[metric NN] [mtu NN]\n"
93 //usage:       "        [[-]trailers] [[-]arp] [[-]allmulti]\n"
94 //usage:       "        [multicast] [[-]promisc] [txqueuelen NN] [[-]dynamic]\n"
95 //usage:        IF_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ(
96 //usage:       "        [mem_start NN] [io_addr NN] [irq NN]\n")
97 //usage:       "        [up|down] ..."
98
99 #include "libbb.h"
100 #include "inet_common.h"
101 #include <net/if.h>
102 #include <net/if_arp.h>
103 #include <netinet/in.h>
104 #ifdef HAVE_NET_ETHERNET_H
105 # include <net/ethernet.h>
106 #endif
107
108 #if ENABLE_FEATURE_IFCONFIG_SLIP
109 # include <linux/if_slip.h>
110 #endif
111
112 /* I don't know if this is needed for busybox or not.  Anyone? */
113 #define QUESTIONABLE_ALIAS_CASE
114
115
116 /* Defines for glibc2.0 users. */
117 #ifndef SIOCSIFTXQLEN
118 # define SIOCSIFTXQLEN      0x8943
119 # define SIOCGIFTXQLEN      0x8942
120 #endif
121
122 /* ifr_qlen is ifru_ivalue, but it isn't present in 2.0 kernel headers */
123 #ifndef ifr_qlen
124 # define ifr_qlen        ifr_ifru.ifru_mtu
125 #endif
126
127 #ifndef IFF_DYNAMIC
128 # define IFF_DYNAMIC     0x8000 /* dialup device with changing addresses */
129 #endif
130
131 #if ENABLE_FEATURE_IPV6
132 struct in6_ifreq {
133         struct in6_addr ifr6_addr;
134         uint32_t ifr6_prefixlen;
135         int ifr6_ifindex;
136 };
137 #endif
138
139 /*
140  * Here are the bit masks for the "flags" member of struct options below.
141  * N_ signifies no arg prefix; M_ signifies arg prefixed by '-'.
142  * CLR clears the flag; SET sets the flag; ARG signifies (optional) arg.
143  */
144 #define N_CLR            0x01
145 #define M_CLR            0x02
146 #define N_SET            0x04
147 #define M_SET            0x08
148 #define N_ARG            0x10
149 #define M_ARG            0x20
150
151 #define M_MASK           (M_CLR | M_SET | M_ARG)
152 #define N_MASK           (N_CLR | N_SET | N_ARG)
153 #define SET_MASK         (N_SET | M_SET)
154 #define CLR_MASK         (N_CLR | M_CLR)
155 #define SET_CLR_MASK     (SET_MASK | CLR_MASK)
156 #define ARG_MASK         (M_ARG | N_ARG)
157
158 /*
159  * Here are the bit masks for the "arg_flags" member of struct options below.
160  */
161
162 /*
163  * cast type:
164  *   00 int
165  *   01 char *
166  *   02 HOST_COPY in_ether
167  *   03 HOST_COPY INET_resolve
168  */
169 #define A_CAST_TYPE      0x03
170 /*
171  * map type:
172  *   00 not a map type (mem_start, io_addr, irq)
173  *   04 memstart (unsigned long)
174  *   08 io_addr  (unsigned short)
175  *   0C irq      (unsigned char)
176  */
177 #define A_MAP_TYPE       0x0C
178 #define A_ARG_REQ        0x10   /* Set if an arg is required. */
179 #define A_NETMASK        0x20   /* Set if netmask (check for multiple sets). */
180 #define A_SET_AFTER      0x40   /* Set a flag at the end. */
181 #define A_COLON_CHK      0x80   /* Is this needed?  See below. */
182 #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
183 #define A_HOSTNAME      0x100   /* Set if it is ip addr. */
184 #define A_BROADCAST     0x200   /* Set if it is broadcast addr. */
185 #else
186 #define A_HOSTNAME          0
187 #define A_BROADCAST         0
188 #endif
189
190 /*
191  * These defines are for dealing with the A_CAST_TYPE field.
192  */
193 #define A_CAST_CHAR_PTR  0x01
194 #define A_CAST_RESOLVE   0x01
195 #define A_CAST_HOST_COPY 0x02
196 #define A_CAST_HOST_COPY_IN_ETHER    A_CAST_HOST_COPY
197 #define A_CAST_HOST_COPY_RESOLVE     (A_CAST_HOST_COPY | A_CAST_RESOLVE)
198
199 /*
200  * These defines are for dealing with the A_MAP_TYPE field.
201  */
202 #define A_MAP_ULONG      0x04   /* memstart */
203 #define A_MAP_USHORT     0x08   /* io_addr */
204 #define A_MAP_UCHAR      0x0C   /* irq */
205
206 /*
207  * Define the bit masks signifying which operations to perform for each arg.
208  */
209
210 #define ARG_METRIC       (A_ARG_REQ /*| A_CAST_INT*/)
211 #define ARG_MTU          (A_ARG_REQ /*| A_CAST_INT*/)
212 #define ARG_TXQUEUELEN   (A_ARG_REQ /*| A_CAST_INT*/)
213 #define ARG_MEM_START    (A_ARG_REQ | A_MAP_ULONG)
214 #define ARG_IO_ADDR      (A_ARG_REQ | A_MAP_ULONG)
215 #define ARG_IRQ          (A_ARG_REQ | A_MAP_UCHAR)
216 #define ARG_DSTADDR      (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
217 #define ARG_NETMASK      (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
218 #define ARG_BROADCAST    (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_BROADCAST)
219 #define ARG_HW           (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
220 #define ARG_POINTOPOINT  (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
221 #define ARG_KEEPALIVE    (A_ARG_REQ | A_CAST_CHAR_PTR)
222 #define ARG_OUTFILL      (A_ARG_REQ | A_CAST_CHAR_PTR)
223 #define ARG_HOSTNAME     (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK | A_HOSTNAME)
224 #define ARG_ADD_DEL      (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
225
226
227 struct arg1opt {
228         const char *name;
229         unsigned short selector;
230         unsigned short ifr_offset;
231 };
232
233 struct options {
234         const char *name;
235 #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
236         const unsigned int flags:6;
237         const unsigned int arg_flags:10;
238 #else
239         const unsigned char flags;
240         const unsigned char arg_flags;
241 #endif
242         const unsigned short selector;
243 };
244
245 #define ifreq_offsetof(x)  offsetof(struct ifreq, x)
246
247 /*
248  * Set up the tables.  Warning!  They must have corresponding order!
249  */
250
251 static const struct arg1opt Arg1Opt[] = {
252         { "SIFMETRIC",  SIOCSIFMETRIC,  ifreq_offsetof(ifr_metric) },
253         { "SIFMTU",     SIOCSIFMTU,     ifreq_offsetof(ifr_mtu) },
254         { "SIFTXQLEN",  SIOCSIFTXQLEN,  ifreq_offsetof(ifr_qlen) },
255         { "SIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr) },
256         { "SIFNETMASK", SIOCSIFNETMASK, ifreq_offsetof(ifr_netmask) },
257         { "SIFBRDADDR", SIOCSIFBRDADDR, ifreq_offsetof(ifr_broadaddr) },
258 #if ENABLE_FEATURE_IFCONFIG_HW
259         { "SIFHWADDR",  SIOCSIFHWADDR,  ifreq_offsetof(ifr_hwaddr) },
260 #endif
261         { "SIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr) },
262 #ifdef SIOCSKEEPALIVE
263         { "SKEEPALIVE", SIOCSKEEPALIVE, ifreq_offsetof(ifr_data) },
264 #endif
265 #ifdef SIOCSOUTFILL
266         { "SOUTFILL",   SIOCSOUTFILL,   ifreq_offsetof(ifr_data) },
267 #endif
268 #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
269         { "SIFMAP",     SIOCSIFMAP,     ifreq_offsetof(ifr_map.mem_start) },
270         { "SIFMAP",     SIOCSIFMAP,     ifreq_offsetof(ifr_map.base_addr) },
271         { "SIFMAP",     SIOCSIFMAP,     ifreq_offsetof(ifr_map.irq) },
272 #endif
273 #if ENABLE_FEATURE_IPV6
274         { "SIFADDR",    SIOCSIFADDR,    ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */
275         { "DIFADDR",    SIOCDIFADDR,    ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */
276 #endif
277         /* Last entry is for unmatched (assumed to be hostname/address) arg. */
278         { "SIFADDR",    SIOCSIFADDR,    ifreq_offsetof(ifr_addr) },
279 };
280
281 static const struct options OptArray[] = {
282         { "metric",      N_ARG,         ARG_METRIC,      0 },
283         { "mtu",         N_ARG,         ARG_MTU,         0 },
284         { "txqueuelen",  N_ARG,         ARG_TXQUEUELEN,  0 },
285         { "dstaddr",     N_ARG,         ARG_DSTADDR,     0 },
286         { "netmask",     N_ARG,         ARG_NETMASK,     0 },
287         { "broadcast",   N_ARG | M_CLR, ARG_BROADCAST,   IFF_BROADCAST },
288 #if ENABLE_FEATURE_IFCONFIG_HW
289         { "hw",          N_ARG,         ARG_HW,          0 },
290 #endif
291         { "pointopoint", N_ARG | M_CLR, ARG_POINTOPOINT, IFF_POINTOPOINT },
292 #ifdef SIOCSKEEPALIVE
293         { "keepalive",   N_ARG,         ARG_KEEPALIVE,   0 },
294 #endif
295 #ifdef SIOCSOUTFILL
296         { "outfill",     N_ARG,         ARG_OUTFILL,     0 },
297 #endif
298 #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
299         { "mem_start",   N_ARG,         ARG_MEM_START,   0 },
300         { "io_addr",     N_ARG,         ARG_IO_ADDR,     0 },
301         { "irq",         N_ARG,         ARG_IRQ,         0 },
302 #endif
303 #if ENABLE_FEATURE_IPV6
304         { "add",         N_ARG,         ARG_ADD_DEL,     0 },
305         { "del",         N_ARG,         ARG_ADD_DEL,     0 },
306 #endif
307         { "arp",         N_CLR | M_SET, 0,               IFF_NOARP },
308         { "trailers",    N_CLR | M_SET, 0,               IFF_NOTRAILERS },
309         { "promisc",     N_SET | M_CLR, 0,               IFF_PROMISC },
310         { "multicast",   N_SET | M_CLR, 0,               IFF_MULTICAST },
311         { "allmulti",    N_SET | M_CLR, 0,               IFF_ALLMULTI },
312         { "dynamic",     N_SET | M_CLR, 0,               IFF_DYNAMIC },
313         { "up",          N_SET,         0,               (IFF_UP | IFF_RUNNING) },
314         { "down",        N_CLR,         0,               IFF_UP },
315         { NULL,          0,             ARG_HOSTNAME,    (IFF_UP | IFF_RUNNING) }
316 };
317
318 int ifconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
319 int ifconfig_main(int argc UNUSED_PARAM, char **argv)
320 {
321         struct ifreq ifr;
322         struct sockaddr_in sai;
323 #if ENABLE_FEATURE_IFCONFIG_HW
324         struct sockaddr sa;
325 #endif
326         const struct arg1opt *a1op;
327         const struct options *op;
328         int sockfd;                     /* socket fd we use to manipulate stuff with */
329         int selector;
330 #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
331         unsigned int mask;
332         unsigned int did_flags;
333         unsigned int sai_hostname, sai_netmask;
334 #else
335         unsigned char mask;
336         unsigned char did_flags;
337 #endif
338         char *p;
339         /*char host[128];*/
340         const char *host = NULL; /* make gcc happy */
341         IF_FEATURE_IFCONFIG_STATUS(char *show_all_param;)
342
343         did_flags = 0;
344 #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
345         sai_hostname = 0;
346         sai_netmask = 0;
347 #endif
348
349         /* skip argv[0] */
350         ++argv;
351
352 #if ENABLE_FEATURE_IFCONFIG_STATUS
353         show_all_param = NULL;
354         if (argv[0] && argv[0][0] == '-' && argv[0][1] == 'a' && !argv[0][2]) {
355                 ++argv;
356                 show_all_param = IFNAME_SHOW_DOWNED_TOO;
357         }
358 #endif
359
360         if (!argv[0] || !argv[1]) { /* one or no args */
361 #if ENABLE_FEATURE_IFCONFIG_STATUS
362                 return display_interfaces(argv[0] ? argv[0] : show_all_param);
363 #else
364                 bb_error_msg_and_die("no support for status display");
365 #endif
366         }
367
368         /* Create a channel to the NET kernel. */
369         sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
370
371         /* get interface name */
372         strncpy_IFNAMSIZ(ifr.ifr_name, *argv);
373
374         /* Process the remaining arguments. */
375         while (*++argv != NULL) {
376                 p = *argv;
377                 mask = N_MASK;
378                 if (*p == '-') {        /* If the arg starts with '-'... */
379                         ++p;            /*    advance past it and */
380                         mask = M_MASK;  /*    set the appropriate mask. */
381                 }
382                 for (op = OptArray; op->name; op++) {   /* Find table entry. */
383                         if (strcmp(p, op->name) == 0) { /* If name matches... */
384                                 mask &= op->flags;
385                                 if (mask)       /* set the mask and go. */
386                                         goto FOUND_ARG;
387                                 /* If we get here, there was a valid arg with an */
388                                 /* invalid '-' prefix. */
389                                 bb_error_msg_and_die("bad: '%s'", p-1);
390                         }
391                 }
392
393                 /* We fell through, so treat as possible hostname. */
394                 a1op = Arg1Opt + ARRAY_SIZE(Arg1Opt) - 1;
395                 mask = op->arg_flags;
396                 goto HOSTNAME;
397
398  FOUND_ARG:
399                 if (mask & ARG_MASK) {
400                         mask = op->arg_flags;
401                         if (mask & A_NETMASK & did_flags)
402                                 bb_show_usage();
403                         a1op = Arg1Opt + (op - OptArray);
404                         if (*++argv == NULL) {
405                                 if (mask & A_ARG_REQ)
406                                         bb_show_usage();
407                                 --argv;
408                                 mask &= A_SET_AFTER;    /* just for broadcast */
409                         } else {        /* got an arg so process it */
410  HOSTNAME:
411                                 did_flags |= (mask & (A_NETMASK|A_HOSTNAME));
412                                 if (mask & A_CAST_HOST_COPY) {
413 #if ENABLE_FEATURE_IFCONFIG_HW
414                                         if (mask & A_CAST_RESOLVE) {
415 #endif
416                                                 host = *argv;
417                                                 if (strcmp(host, "inet") == 0)
418                                                         continue; /* compat stuff */
419                                                 sai.sin_family = AF_INET;
420                                                 sai.sin_port = 0;
421                                                 if (strcmp(host, "default") == 0) {
422                                                         /* Default is special, meaning 0.0.0.0. */
423                                                         sai.sin_addr.s_addr = INADDR_ANY;
424                                                 }
425 #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
426                                                 else if ((host[0] == '+' && !host[1])
427                                                  && (mask & A_BROADCAST)
428                                                  && (did_flags & (A_NETMASK|A_HOSTNAME)) == (A_NETMASK|A_HOSTNAME)
429                                                 ) {
430                                                         /* + is special, meaning broadcast is derived. */
431                                                         sai.sin_addr.s_addr = (~sai_netmask) | (sai_hostname & sai_netmask);
432                                                 }
433 #endif
434                                                 else {
435                                                         len_and_sockaddr *lsa;
436 #if ENABLE_FEATURE_IPV6
437                                                         char *prefix;
438                                                         int prefix_len = 0;
439                                                         prefix = strchr(host, '/');
440                                                         if (prefix) {
441                                                                 prefix_len = xatou_range(prefix + 1, 0, 128);
442                                                                 *prefix = '\0';
443                                                         }
444  resolve:
445 #endif
446                                                         lsa = xhost2sockaddr(host, 0);
447 #if ENABLE_FEATURE_IPV6
448                                                         if (lsa->u.sa.sa_family != AF_INET6 && prefix) {
449 /* TODO: we do not support "ifconfig eth0 up 1.2.3.4/17".
450  * For now, just make it fail instead of silently ignoring "/17" part:
451  */
452                                                                 *prefix = '/';
453                                                                 goto resolve;
454                                                         }
455                                                         if (lsa->u.sa.sa_family == AF_INET6) {
456                                                                 int sockfd6;
457                                                                 struct in6_ifreq ifr6;
458
459                                                                 sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0);
460                                                                 xioctl(sockfd6, SIOCGIFINDEX, &ifr);
461                                                                 ifr6.ifr6_ifindex = ifr.ifr_ifindex;
462                                                                 ifr6.ifr6_prefixlen = prefix_len;
463                                                                 memcpy(&ifr6.ifr6_addr,
464                                                                                 &lsa->u.sin6.sin6_addr,
465                                                                                 sizeof(struct in6_addr));
466                                                                 ioctl_or_perror_and_die(sockfd6, a1op->selector, &ifr6, "SIOC%s", a1op->name);
467                                                                 if (ENABLE_FEATURE_CLEAN_UP)
468                                                                         free(lsa);
469                                                                 continue;
470                                                         }
471 #endif
472                                                         sai.sin_addr = lsa->u.sin.sin_addr;
473                                                         if (ENABLE_FEATURE_CLEAN_UP)
474                                                                 free(lsa);
475                                                 }
476 #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
477                                                 if (mask & A_HOSTNAME)
478                                                         sai_hostname = sai.sin_addr.s_addr;
479                                                 if (mask & A_NETMASK)
480                                                         sai_netmask = sai.sin_addr.s_addr;
481 #endif
482                                                 p = (char *) &sai;
483 #if ENABLE_FEATURE_IFCONFIG_HW
484                                         } else {        /* A_CAST_HOST_COPY_IN_ETHER */
485                                                 /* This is the "hw" arg case. */
486                                                 smalluint hw_class = index_in_substrings("ether\0"
487                                                                 IF_FEATURE_HWIB("infiniband\0"), *argv) + 1;
488                                                 if (!hw_class || !*++argv)
489                                                         bb_show_usage();
490                                                 host = *argv;
491                                                 if (hw_class == 1 ? in_ether(host, &sa) : in_ib(host, &sa))
492                                                         bb_error_msg_and_die("invalid hw-addr %s", host);
493                                                 p = (char *) &sa;
494                                         }
495 #endif
496                                         memcpy( ((char *)&ifr) + a1op->ifr_offset,
497                                                 p, sizeof(struct sockaddr));
498                                 } else {
499                                         /* FIXME: error check?? */
500                                         unsigned long i = strtoul(*argv, NULL, 0);
501                                         p = ((char *)&ifr) + a1op->ifr_offset;
502 #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
503                                         if (mask & A_MAP_TYPE) {
504                                                 xioctl(sockfd, SIOCGIFMAP, &ifr);
505                                                 if ((mask & A_MAP_UCHAR) == A_MAP_UCHAR)
506                                                         *(unsigned char *) p = i;
507                                                 else if (mask & A_MAP_USHORT)
508                                                         *(unsigned short *) p = i;
509                                                 else
510                                                         *(unsigned long *) p = i;
511                                         } else
512 #endif
513                                         if (mask & A_CAST_CHAR_PTR)
514                                                 *(caddr_t *) p = (caddr_t) i;
515                                         else    /* A_CAST_INT */
516                                                 *(int *) p = i;
517                                 }
518
519                                 ioctl_or_perror_and_die(sockfd, a1op->selector, &ifr, "SIOC%s", a1op->name);
520 #ifdef QUESTIONABLE_ALIAS_CASE
521                                 if (mask & A_COLON_CHK) {
522                                         /*
523                                          * Don't do the set_flag() if the address is an alias with
524                                          * a '-' at the end, since it's deleted already! - Roman
525                                          *
526                                          * Should really use regex.h here, not sure though how well
527                                          * it'll go with the cross-platform support etc.
528                                          */
529                                         char *ptr;
530                                         short int found_colon = 0;
531                                         for (ptr = ifr.ifr_name; *ptr; ptr++)
532                                                 if (*ptr == ':')
533                                                         found_colon++;
534                                         if (found_colon && ptr[-1] == '-')
535                                                 continue;
536                                 }
537 #endif
538                         }
539                         if (!(mask & A_SET_AFTER))
540                                 continue;
541                         mask = N_SET;
542                 } /* if (mask & ARG_MASK) */
543
544                 xioctl(sockfd, SIOCGIFFLAGS, &ifr);
545                 selector = op->selector;
546                 if (mask & SET_MASK)
547                         ifr.ifr_flags |= selector;
548                 else
549                         ifr.ifr_flags &= ~selector;
550                 xioctl(sockfd, SIOCSIFFLAGS, &ifr);
551         } /* while () */
552
553         if (ENABLE_FEATURE_CLEAN_UP)
554                 close(sockfd);
555         return 0;
556 }