2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static const char copyright
[] =
36 "@(#) Copyright (c) 1983, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
42 static char sccsid
[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
44 static const char rcsid
[] =
45 "$Id: ifconfig.c,v 1.8 2004/08/26 23:55:21 lindak Exp $";
48 #include <sys/param.h>
49 #define KERNEL_PRIVATE
50 #include <sys/ioctl.h>
52 #include <sys/socket.h>
53 #include <sys/sysctl.h>
56 #include <net/ethernet.h>
58 #include <net/if_var.h>
59 #include <net/if_dl.h>
60 #include <net/if_types.h>
61 #include <net/route.h>
64 #include <netinet/in.h>
65 #include <netinet/in_var.h>
66 #include <arpa/inet.h>
70 #include <netinet6/nd6.h> /* Define ND6_INFINITE_LIFETIME */
78 #include <netns/ns_if.h>
94 /* wrapper for KAME-special getnameinfo() */
95 #ifndef NI_WITHSCOPEID
96 #define NI_WITHSCOPEID 0
99 struct ifreq ifr
, ridreq
;
100 struct ifaliasreq addreq
;
102 struct in6_ifreq in6_ridreq
;
103 struct in6_aliasreq in6_addreq
=
109 { 0, 0, ND6_INFINITE_LIFETIME
, ND6_INFINITE_LIFETIME
} };
111 struct sockaddr_in netmask
;
125 static int ip6lifetime
;
130 int bond_details
= 0;
135 char addr_buf
[MAXHOSTNAMELEN
*2 + 1]; /*for getnameinfo()*/
138 void Perror
__P((const char *cmd
));
140 int ifconfig
__P((int argc
, char *const *argv
, const struct afswtch
*afp
));
141 void notealias
__P((const char *, int, int, const struct afswtch
*afp
));
142 void printb
__P((const char *s
, unsigned value
, const char *bits
));
143 void rt_xaddrs
__P((caddr_t
, caddr_t
, struct rt_addrinfo
*));
144 void status
__P((const struct afswtch
*afp
, int addrcount
,
145 struct sockaddr_dl
*sdl
, struct if_msghdr
*ifm
,
146 struct ifa_msghdr
*ifam
));
147 void tunnel_status
__P((int s
));
148 void usage
__P((void));
151 void in6_fillscopeid
__P((struct sockaddr_in6
*sin6
));
152 int prefix
__P((void *, int));
153 static char *sec2str
__P((time_t));
154 int explicit_prefix
= 0;
157 typedef void c_func
__P((const char *cmd
, int arg
, int s
, const struct afswtch
*afp
));
158 typedef void c_func2
__P((const char *arg
, const char *arg2
, int s
, const struct afswtch
*afp
));
159 c_func setifaddr
, setifbroadaddr
, setifdstaddr
, setifnetmask
;
163 c_func setifprefixlen
;
167 c_func2 setip6lifetime
;
170 c_func setifflags
, setifmetric
, setifmtu
, setiflladdr
;
171 c_func clone_destroy
;
174 void clone_create(void);
175 #define NEXTARG 0xffffff
176 #define NEXTARG2 0xfffffe
181 int c_parameter
; /* NEXTARG means next argv */
182 void (*c_func
) __P((const char *, int, int, const struct afswtch
*afp
));
183 void (*c_func2
) __P((const char *, const char *, int, const struct afswtch
*afp
));
185 { "up", IFF_UP
, setifflags
} ,
186 { "down", -IFF_UP
, setifflags
},
187 { "arp", -IFF_NOARP
, setifflags
},
188 { "-arp", IFF_NOARP
, setifflags
},
189 { "debug", IFF_DEBUG
, setifflags
},
190 { "-debug", -IFF_DEBUG
, setifflags
},
191 { "add", IFF_UP
, notealias
},
192 { "alias", IFF_UP
, notealias
},
193 { "-alias", -IFF_UP
, notealias
},
194 { "delete", -IFF_UP
, notealias
},
195 { "remove", -IFF_UP
, notealias
},
197 #define EN_SWABIPS 0x1000
198 { "swabips", EN_SWABIPS
, setifflags
},
199 { "-swabips", -EN_SWABIPS
, setifflags
},
201 { "netmask", NEXTARG
, setifnetmask
},
203 { "prefixlen", NEXTARG
, setifprefixlen
},
204 { "anycast", IN6_IFF_ANYCAST
, setip6flags
},
205 { "tentative", IN6_IFF_TENTATIVE
, setip6flags
},
206 { "-tentative", -IN6_IFF_TENTATIVE
, setip6flags
},
207 { "deprecated", IN6_IFF_DEPRECATED
, setip6flags
},
208 { "-deprecated", -IN6_IFF_DEPRECATED
, setip6flags
},
209 { "autoconf", IN6_IFF_AUTOCONF
, setip6flags
},
210 { "-autoconf", -IN6_IFF_AUTOCONF
, setip6flags
},
211 { "pltime", NEXTARG
, setip6pltime
},
212 { "vltime", NEXTARG
, setip6vltime
},
214 { "metric", NEXTARG
, setifmetric
},
215 { "broadcast", NEXTARG
, setifbroadaddr
},
216 { "ipdst", NEXTARG
, setifipdst
},
217 { "tunnel", NEXTARG2
, NULL
, settunnel
},
218 { "deletetunnel", 0, deletetunnel
},
219 { "link0", IFF_LINK0
, setifflags
},
220 { "-link0", -IFF_LINK0
, setifflags
},
221 { "link1", IFF_LINK1
, setifflags
},
222 { "-link1", -IFF_LINK1
, setifflags
},
223 { "link2", IFF_LINK2
, setifflags
},
224 { "-link2", -IFF_LINK2
, setifflags
},
226 { "media", NEXTARG
, setmedia
},
227 { "mediaopt", NEXTARG
, setmediaopt
},
228 { "-mediaopt", NEXTARG
, unsetmediaopt
},
231 { "vlan", NEXTARG
, setvlantag
},
232 { "vlandev", NEXTARG
, setvlandev
},
233 { "-vlandev", NEXTARG
, unsetvlandev
},
236 { "bonddev", NEXTARG
, setbonddev
},
237 { "-bonddev", NEXTARG
, unsetbonddev
},
238 { "bondmode", NEXTARG
, setbondmode
},
241 /* XXX `create' special-cased below */
242 {"create", 0, clone_create
},
243 {"plumb", 0, clone_create
},
245 {"destroy", 0, clone_destroy
},
246 {"unplumb", 0, clone_destroy
},
248 { "ssid", NEXTARG
, set80211ssid
},
249 { "nwid", NEXTARG
, set80211ssid
},
250 { "stationname", NEXTARG
, set80211stationname
},
251 { "station", NEXTARG
, set80211stationname
}, /* BSD/OS */
252 { "channel", NEXTARG
, set80211channel
},
253 { "authmode", NEXTARG
, set80211authmode
},
254 { "powersavemode", NEXTARG
, set80211powersavemode
},
255 { "powersave", 1, set80211powersave
},
256 { "-powersave", 0, set80211powersave
},
257 { "powersavesleep", NEXTARG
, set80211powersavesleep
},
258 { "wepmode", NEXTARG
, set80211wepmode
},
259 { "wep", 1, set80211wep
},
260 { "-wep", 0, set80211wep
},
261 { "weptxkey", NEXTARG
, set80211weptxkey
},
262 { "wepkey", NEXTARG
, set80211wepkey
},
263 { "nwkey", NEXTARG
, set80211nwkey
}, /* NetBSD */
264 { "-nwkey", 0, set80211wep
}, /* NetBSD */
266 { "normal", -IFF_LINK0
, setifflags
},
267 { "compress", IFF_LINK0
, setifflags
},
268 { "noicmp", IFF_LINK1
, setifflags
},
269 { "mtu", NEXTARG
, setifmtu
},
270 { "lladdr", NEXTARG
, setiflladdr
},
272 { 0, 0, setifdstaddr
},
276 * XNS support liberally adapted from code written at the University of
277 * Maryland principally by James O'Toole and Chris Torek.
279 typedef void af_status
__P((int, struct rt_addrinfo
*));
280 typedef void af_getaddr
__P((const char *, int));
281 typedef void af_getprefix
__P((const char *, int));
283 af_status in_status
, at_status
, ether_status
;
284 af_getaddr in_getaddr
, at_getaddr
, ether_getaddr
;
288 af_status in6_status
;
289 af_getaddr in6_getaddr
;
290 af_getprefix in6_getprefix
;
293 af_status xns_status
;
294 af_getaddr xns_getaddr
;
297 /* Known address families */
302 af_status
*af_status
;
303 af_getaddr
*af_getaddr
;
304 af_getprefix
*af_getprefix
;
310 #define C(x) ((caddr_t) &x)
311 { "inet", AF_INET
, in_status
, in_getaddr
, NULL
,
312 SIOCDIFADDR
, SIOCAIFADDR
, C(ridreq
), C(addreq
) },
314 { "inet6", AF_INET6
, in6_status
, in6_getaddr
, in6_getprefix
,
315 SIOCDIFADDR_IN6
, SIOCAIFADDR_IN6
,
316 C(in6_ridreq
), C(in6_addreq
) },
319 { "ns", AF_NS
, xns_status
, xns_getaddr
, NULL
,
320 SIOCDIFADDR
, SIOCAIFADDR
, C(ridreq
), C(addreq
) },
322 { "ether", AF_LINK
, ether_status
, ether_getaddr
, NULL
,
323 0, SIOCSIFLLADDR
, NULL
, C(ridreq
) },
324 #if 0 /* XXX conflicts with the media command */
326 { "media", AF_UNSPEC
, media_status
, NULL
, NULL
, }, /* XXX not real!! */
329 { "vlan", AF_UNSPEC
, vlan_status
, NULL
, NULL
, }, /* XXX not real!! */
332 { "bond", AF_UNSPEC
, bond_status
, NULL
, NULL
, }, /* XXX not real!! */
335 { "ieee80211", AF_UNSPEC
, ieee80211_status
, NULL
, NULL
, }, /* XXX not real!! */
342 * Expand the compacted form of addresses as returned via the
343 * configuration read via sysctl().
347 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
348 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
351 rt_xaddrs(cp
, cplim
, rtinfo
)
353 struct rt_addrinfo
*rtinfo
;
358 memset(rtinfo
->rti_info
, 0, sizeof(rtinfo
->rti_info
));
359 for (i
= 0; (i
< RTAX_MAX
) && (cp
< cplim
); i
++) {
360 if ((rtinfo
->rti_addrs
& (1 << i
)) == 0)
362 rtinfo
->rti_info
[i
] = sa
= (struct sockaddr
*)cp
;
372 fprintf(stderr
, "%s",
373 "usage: ifconfig interface address_family [address [dest_address]]\n"
375 " ifconfig interface create\n"
376 " ifconfig -a [-d] [-m] [-u] [address_family]\n"
377 " ifconfig -l [-d] [-u] [address_family]\n"
378 " ifconfig [-d] [-m] [-u]\n");
380 fprintf(stderr
, "%s",
381 "usage: ifconfig [-L] interface address_family [address [dest_address]]\n"
383 " ifconfig interface create\n"
384 " ifconfig -a [-L] [-d] [-m] [-u] [address_family]\n"
385 " ifconfig -l [-d] [-u] [address_family]\n"
386 " ifconfig [-L] [-d] [-m] [-u]\n");
397 int all
, namesonly
, downonly
, uponly
;
398 int foundit
= 0, need_nl
= 0;
399 const struct afswtch
*afp
= 0;
401 struct if_msghdr
*ifm
, *nextifm
;
402 struct ifa_msghdr
*ifam
;
403 struct sockaddr_dl
*sdl
;
404 char *buf
, *lim
, *next
;
410 /* Parse leading line options */
411 all
= downonly
= uponly
= namesonly
= 0;
412 while ((c
= getopt(argc
, argv
, "abdlmu"
418 case 'a': /* scan all interfaces */
421 case 'b': /* bond detailed output */
424 case 'd': /* restrict scan to "down" interfaces */
427 case 'l': /* scan interface names only */
430 case 'm': /* show media choices in status */
433 case 'u': /* restrict scan to "up" interfaces */
438 ip6lifetime
++; /* print IPv6 address lifetime */
449 /* -l cannot be used with -a or -m or -b */
450 if (namesonly
&& (all
|| supmedia
|| bond_details
))
454 if (uponly
&& downonly
)
457 /* no arguments is equivalent to '-a' */
458 if (!namesonly
&& argc
< 1)
461 /* -a and -l allow an address family arg to limit the output */
462 if (all
|| namesonly
) {
467 for (afp
= afs
; afp
->af_name
; afp
++)
468 if (strcmp(afp
->af_name
, *argv
) == 0) {
472 if (afp
->af_name
== NULL
)
474 /* leave with afp non-zero */
477 /* not listing, need an argument */
481 strncpy(name
, *argv
, sizeof(name
));
485 * NOTE: We must special-case the `create' command right
486 * here as we would otherwise fail when trying to find
489 if (argc
> 0 && (strcmp(argv
[0], "create") == 0 ||
490 strcmp(argv
[0], "plumb") == 0)) {
498 /* Check for address family */
500 for (afp
= afs
; afp
->af_name
; afp
++)
501 if (strcmp(afp
->af_name
, *argv
) == 0) {
505 if (afp
->af_name
== NULL
)
506 afp
= NULL
; /* not a family, NULL */
512 mib
[3] = 0; /* address family */
513 mib
[4] = NET_RT_IFLIST
;
516 /* if particular family specified, only ask about it */
520 if (sysctl(mib
, 6, NULL
, &needed
, NULL
, 0) < 0)
521 errx(1, "iflist-sysctl-estimate");
522 if ((buf
= malloc(needed
)) == NULL
)
524 if (sysctl(mib
, 6, buf
, &needed
, NULL
, 0) < 0)
525 errx(1, "actual retrieval of interface table");
531 ifm
= (struct if_msghdr
*)next
;
533 if (ifm
->ifm_type
== RTM_IFINFO
) {
534 sdl
= (struct sockaddr_dl
*)(ifm
+ 1);
535 flags
= ifm
->ifm_flags
;
537 fprintf(stderr
, "out of sync parsing NET_RT_IFLIST\n");
538 fprintf(stderr
, "expected %d, got %d\n", RTM_IFINFO
,
540 fprintf(stderr
, "msglen = %d\n", ifm
->ifm_msglen
);
541 fprintf(stderr
, "buf:%p, next:%p, lim:%p\n", buf
, next
,
546 next
+= ifm
->ifm_msglen
;
551 nextifm
= (struct if_msghdr
*)next
;
553 if (nextifm
->ifm_type
!= RTM_NEWADDR
)
557 ifam
= (struct ifa_msghdr
*)nextifm
;
560 next
+= nextifm
->ifm_msglen
;
563 if (all
|| namesonly
) {
565 if ((flags
& IFF_UP
) == 0)
566 continue; /* not up */
569 continue; /* not down */
570 strncpy(name
, sdl
->sdl_data
, sdl
->sdl_nlen
);
571 name
[sdl
->sdl_nlen
] = '\0';
574 afp
->af_status
!= ether_status
||
575 sdl
->sdl_type
== IFT_ETHER
) {
584 if (strlen(name
) != sdl
->sdl_nlen
)
585 continue; /* not same len */
586 if (strncmp(name
, sdl
->sdl_data
, sdl
->sdl_nlen
) != 0)
587 continue; /* not same name */
591 ifconfig(argc
, argv
, afp
);
593 status(afp
, addrcount
, sdl
, ifm
, ifam
);
595 if (all
== 0 && namesonly
== 0) {
596 foundit
++; /* flag it as 'done' */
602 if (namesonly
&& need_nl
> 0)
605 if (all
== 0 && namesonly
== 0 && foundit
== 0)
606 errx(1, "interface %s does not exist", name
);
614 ifconfig(argc
, argv
, afp
)
617 const struct afswtch
*afp
;
623 ifr
.ifr_addr
.sa_family
= afp
->af_af
== AF_LINK
? AF_INET
: afp
->af_af
;
624 strncpy(ifr
.ifr_name
, name
, sizeof ifr
.ifr_name
);
626 if ((s
= socket(ifr
.ifr_addr
.sa_family
, SOCK_DGRAM
, 0)) < 0)
630 register const struct cmd
*p
;
632 for (p
= cmds
; p
->c_name
; p
++)
633 if (strcmp(*argv
, p
->c_name
) == 0)
635 if (p
->c_name
== 0 && setaddr
)
636 p
++; /* got src, do dst */
637 if (p
->c_func
|| p
->c_func2
) {
638 if (p
->c_parameter
== NEXTARG
) {
640 errx(1, "'%s' requires argument",
642 (*p
->c_func
)(argv
[1], 0, s
, afp
);
644 } else if (p
->c_parameter
== NEXTARG2
) {
646 errx(1, "'%s' requires 2 arguments",
648 (*p
->c_func2
)(argv
[1], argv
[2], s
, afp
);
649 argc
-= 2, argv
+= 2;
651 (*p
->c_func
)(*argv
, p
->c_parameter
, s
, afp
);
656 if (ifr
.ifr_addr
.sa_family
== AF_INET6
&& explicit_prefix
== 0) {
657 /* Aggregatable address architecture defines all prefixes
658 are 64. So, it is convenient to set prefixlen to 64 if
659 it is not specified. */
660 setifprefixlen("64", 0, s
, afp
);
661 /* in6_getprefix("64", MASK) if MASK is available here... */
665 if (setipdst
&& ifr
.ifr_addr
.sa_family
== AF_NS
) {
667 int size
= sizeof(rq
);
669 rq
.rq_ns
= addreq
.ifra_addr
;
670 rq
.rq_ip
= addreq
.ifra_dstaddr
;
672 if (setsockopt(s
, 0, SO_NSIP_ROUTE
, &rq
, size
) < 0)
673 Perror("Encapsulation Routing");
677 if (afp
->af_ridreq
== NULL
|| afp
->af_difaddr
== 0) {
678 warnx("interface %s cannot change %s addresses!",
685 strncpy(afp
->af_ridreq
, name
, sizeof ifr
.ifr_name
);
686 if ((ret
= ioctl(s
, afp
->af_difaddr
, afp
->af_ridreq
)) < 0) {
687 if (errno
== EADDRNOTAVAIL
&& (doalias
>= 0)) {
688 /* means no previous address for interface */
690 Perror("ioctl (SIOCDIFADDR)");
694 if (afp
->af_addreq
== NULL
|| afp
->af_aifaddr
== 0) {
695 warnx("interface %s cannot change %s addresses!",
700 if (newaddr
&& (setaddr
|| setmask
)) {
701 strncpy(afp
->af_addreq
, name
, sizeof ifr
.ifr_name
);
702 if (ioctl(s
, afp
->af_aifaddr
, afp
->af_addreq
) < 0)
703 Perror("ioctl (SIOCAIFADDR)");
715 setifaddr(addr
, param
, s
, afp
)
719 const struct afswtch
*afp
;
721 if (*afp
->af_getaddr
== NULL
)
724 * Delay the ioctl to set the interface addr until flags are all set.
725 * The address interpretation may depend on the flags,
726 * and the flags may change when the address is set.
729 if (doalias
== 0 && afp
->af_af
!= AF_LINK
)
731 (*afp
->af_getaddr
)(addr
, (doalias
>= 0 ? ADDR
: RIDADDR
));
735 settunnel(src
, dst
, s
, afp
)
736 const char *src
, *dst
;
738 const struct afswtch
*afp
;
740 struct addrinfo hints
, *srcres
, *dstres
;
741 struct ifaliasreq addreq
;
744 struct in6_aliasreq in6_addreq
;
747 memset(&hints
, 0, sizeof(hints
));
748 hints
.ai_family
= afp
->af_af
;
750 if ((ecode
= getaddrinfo(src
, NULL
, NULL
, &srcres
)) != 0)
751 errx(1, "error in parsing address string: %s",
752 gai_strerror(ecode
));
754 if ((ecode
= getaddrinfo(dst
, NULL
, NULL
, &dstres
)) != 0)
755 errx(1, "error in parsing address string: %s",
756 gai_strerror(ecode
));
758 if (srcres
->ai_addr
->sa_family
!= dstres
->ai_addr
->sa_family
)
760 "source and destination address families do not match");
762 switch (srcres
->ai_addr
->sa_family
) {
764 memset(&addreq
, 0, sizeof(addreq
));
765 strncpy(addreq
.ifra_name
, name
, IFNAMSIZ
);
766 memcpy(&addreq
.ifra_addr
, srcres
->ai_addr
,
767 srcres
->ai_addr
->sa_len
);
768 memcpy(&addreq
.ifra_dstaddr
, dstres
->ai_addr
,
769 dstres
->ai_addr
->sa_len
);
771 if (ioctl(s
, SIOCSIFPHYADDR
, &addreq
) < 0)
772 warn("SIOCSIFPHYADDR");
777 memset(&in6_addreq
, 0, sizeof(in6_addreq
));
778 strncpy(in6_addreq
.ifra_name
, name
, IFNAMSIZ
);
779 memcpy(&in6_addreq
.ifra_addr
, srcres
->ai_addr
,
780 srcres
->ai_addr
->sa_len
);
781 memcpy(&in6_addreq
.ifra_dstaddr
, dstres
->ai_addr
,
782 dstres
->ai_addr
->sa_len
);
784 if (ioctl(s
, SIOCSIFPHYADDR_IN6
, &in6_addreq
) < 0)
785 warn("SIOCSIFPHYADDR_IN6");
790 warn("address family not supported");
793 freeaddrinfo(srcres
);
794 freeaddrinfo(dstres
);
799 deletetunnel(vname
, param
, s
, afp
)
803 const struct afswtch
*afp
;
806 if (ioctl(s
, SIOCDIFPHYADDR
, &ifr
) < 0)
807 err(1, "SIOCDIFPHYADDR");
811 setifnetmask(addr
, dummy
, s
, afp
)
815 const struct afswtch
*afp
;
817 if (*afp
->af_getaddr
== NULL
)
820 (*afp
->af_getaddr
)(addr
, NMASK
);
825 setifprefixlen(addr
, dummy
, s
, afp
)
829 const struct afswtch
*afp
;
831 if (*afp
->af_getprefix
)
832 (*afp
->af_getprefix
)(addr
, NMASK
);
837 setip6flags(dummyaddr
, flag
, dummysoc
, afp
)
838 const char *dummyaddr
;
841 const struct afswtch
*afp
;
843 if (afp
->af_af
!= AF_INET6
)
844 err(1, "address flags can be set only for inet6 addresses");
847 in6_addreq
.ifra_flags
&= ~(-flag
);
849 in6_addreq
.ifra_flags
|= flag
;
853 setip6pltime(seconds
, dummy
, s
, afp
)
857 const struct afswtch
*afp
;
859 setip6lifetime("pltime", seconds
, s
, afp
);
863 setip6vltime(seconds
, dummy
, s
, afp
)
867 const struct afswtch
*afp
;
869 setip6lifetime("vltime", seconds
, s
, afp
);
873 setip6lifetime(cmd
, val
, s
, afp
)
877 const struct afswtch
*afp
;
883 newval
= (time_t)strtoul(val
, &ep
, 0);
885 errx(1, "invalid %s", cmd
);
886 if (afp
->af_af
!= AF_INET6
)
887 errx(1, "%s not allowed for the AF", cmd
);
888 if (strcmp(cmd
, "vltime") == 0) {
889 in6_addreq
.ifra_lifetime
.ia6t_expire
= t
+ newval
;
890 in6_addreq
.ifra_lifetime
.ia6t_vltime
= newval
;
891 } else if (strcmp(cmd
, "pltime") == 0) {
892 in6_addreq
.ifra_lifetime
.ia6t_preferred
= t
+ newval
;
893 in6_addreq
.ifra_lifetime
.ia6t_pltime
= newval
;
899 setifbroadaddr(addr
, dummy
, s
, afp
)
903 const struct afswtch
*afp
;
906 (*afp
->af_getaddr
)(addr
, DSTADDR
);
910 setifipdst(addr
, dummy
, s
, afp
)
914 const struct afswtch
*afp
;
916 in_getaddr(addr
, DSTADDR
);
921 #define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr))
924 notealias(addr
, param
, s
, afp
)
928 const struct afswtch
*afp
;
930 if (setaddr
&& doalias
== 0 && param
< 0)
931 bcopy((caddr_t
)rqtosa(af_addreq
),
932 (caddr_t
)rqtosa(af_ridreq
),
933 rqtosa(af_addreq
)->sa_len
);
944 setifdstaddr(addr
, param
, s
, afp
)
948 const struct afswtch
*afp
;
950 if (*afp
->af_getaddr
== NULL
)
952 (*afp
->af_getaddr
)(addr
, DSTADDR
);
956 * Note: doing an SIOCIGIFFLAGS scribbles on the union portion
957 * of the ifreq structure, which may confuse other parts of ifconfig.
958 * Make a private copy so we can avoid that.
961 setifflags(vname
, value
, s
, afp
)
965 const struct afswtch
*afp
;
969 bcopy((char *)&ifr
, (char *)&my_ifr
, sizeof(struct ifreq
));
971 if (ioctl(s
, SIOCGIFFLAGS
, (caddr_t
)&my_ifr
) < 0) {
972 Perror("ioctl (SIOCGIFFLAGS)");
975 strncpy(my_ifr
.ifr_name
, name
, sizeof (my_ifr
.ifr_name
));
976 flags
= my_ifr
.ifr_flags
;
983 my_ifr
.ifr_flags
= flags
;
984 if (ioctl(s
, SIOCSIFFLAGS
, (caddr_t
)&my_ifr
) < 0)
989 setifmetric(val
, dummy
, s
, afp
)
993 const struct afswtch
*afp
;
995 strncpy(ifr
.ifr_name
, name
, sizeof (ifr
.ifr_name
));
996 ifr
.ifr_metric
= atoi(val
);
997 if (ioctl(s
, SIOCSIFMETRIC
, (caddr_t
)&ifr
) < 0)
998 warn("ioctl (set metric)");
1002 setifmtu(val
, dummy
, s
, afp
)
1006 const struct afswtch
*afp
;
1008 strncpy(ifr
.ifr_name
, name
, sizeof (ifr
.ifr_name
));
1009 ifr
.ifr_mtu
= atoi(val
);
1010 if (ioctl(s
, SIOCSIFMTU
, (caddr_t
)&ifr
) < 0)
1011 warn("ioctl (set mtu)");
1015 setiflladdr(val
, dummy
, s
, afp
)
1019 const struct afswtch
*afp
;
1021 struct ether_addr
*ea
;
1023 ea
= ether_aton(val
);
1025 warn("malformed link-level address");
1028 strncpy(ifr
.ifr_name
, name
, sizeof (ifr
.ifr_name
));
1029 ifr
.ifr_addr
.sa_len
= ETHER_ADDR_LEN
;
1030 ifr
.ifr_addr
.sa_family
= AF_LINK
;
1031 bcopy(ea
, ifr
.ifr_addr
.sa_data
, ETHER_ADDR_LEN
);
1032 if (ioctl(s
, SIOCSIFLLADDR
, (caddr_t
)&ifr
) < 0)
1033 warn("ioctl (set lladdr)");
1039 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \
1040 "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
1044 * Print the status of the interface. If an address family was
1045 * specified, show it and it only; otherwise, show them all.
1048 status(afp
, addrcount
, sdl
, ifm
, ifam
)
1049 const struct afswtch
*afp
;
1051 struct sockaddr_dl
*sdl
;
1052 struct if_msghdr
*ifm
;
1053 struct ifa_msghdr
*ifam
;
1055 const struct afswtch
*p
= NULL
;
1056 struct rt_addrinfo info
;
1066 ifr
.ifr_addr
.sa_family
= afp
->af_af
== AF_LINK
? AF_INET
: afp
->af_af
;
1067 strncpy(ifr
.ifr_name
, name
, sizeof ifr
.ifr_name
);
1069 if ((s
= socket(ifr
.ifr_addr
.sa_family
, SOCK_DGRAM
, 0)) < 0)
1073 * XXX is it we are doing a SIOCGIFMETRIC etc for one family.
1074 * is it possible that the metric and mtu can be different for
1075 * each family? If so, we have a format problem, because the
1076 * metric and mtu is printed on the global the flags line.
1078 if (ioctl(s
, SIOCGIFMETRIC
, (caddr_t
)&ifr
) < 0)
1079 warn("ioctl (SIOCGIFMETRIC)");
1081 metric
= ifr
.ifr_metric
;
1083 if (ioctl(s
, SIOCGIFMTU
, (caddr_t
)&ifr
) < 0)
1084 warn("ioctl (SIOCGIFMTU)");
1088 printf("%s: ", name
);
1089 printb("flags", flags
, IFFBITS
);
1091 printf(" metric %d", metric
);
1093 printf(" mtu %d", mtu
);
1098 while (addrcount
> 0) {
1100 info
.rti_addrs
= ifam
->ifam_addrs
;
1102 /* Expand the compacted addresses */
1103 rt_xaddrs((char *)(ifam
+ 1), ifam
->ifam_msglen
+ (char *)ifam
,
1107 if (afp
->af_af
== info
.rti_info
[RTAX_IFA
]->sa_family
) {
1109 (*p
->af_status
)(s
, &info
);
1111 } else for (p
= afs
; p
->af_name
; p
++) {
1112 if (p
->af_af
== info
.rti_info
[RTAX_IFA
]->sa_family
)
1113 (*p
->af_status
)(s
, &info
);
1116 ifam
= (struct ifa_msghdr
*)((char *)ifam
+ ifam
->ifam_msglen
);
1118 if (allfamilies
|| afp
->af_status
== ether_status
)
1119 ether_status(s
, (struct rt_addrinfo
*)sdl
);
1121 if (allfamilies
|| afp
->af_status
== media_status
)
1122 media_status(s
, NULL
);
1125 if (allfamilies
|| afp
->af_status
== vlan_status
)
1126 vlan_status(s
, NULL
);
1129 if (allfamilies
|| afp
->af_status
== bond_status
)
1130 bond_status(s
, NULL
);
1132 #ifdef USE_IEEE80211
1133 if (allfamilies
|| afp
->af_status
== ieee80211_status
)
1134 ieee80211_status(s
, NULL
);
1136 strncpy(ifs
.ifs_name
, name
, sizeof ifs
.ifs_name
);
1137 if (ioctl(s
, SIOCGIFSTATUS
, &ifs
) == 0)
1138 printf("%s", ifs
.ascii
);
1140 if (!allfamilies
&& !p
&& afp
->af_status
!= media_status
&&
1141 afp
->af_status
!= ether_status
1143 && afp
->af_status
!= vlan_status
1146 warnx("%s has no %s interface address!", name
, afp
->af_name
);
1156 char psrcaddr
[NI_MAXHOST
];
1157 char pdstaddr
[NI_MAXHOST
];
1158 u_long srccmd
, dstcmd
;
1160 const char *ver
= "";
1161 #ifdef NI_WITHSCOPEID
1162 const int niflag
= NI_NUMERICHOST
| NI_WITHSCOPEID
;
1164 const int niflag
= NI_NUMERICHOST
;
1167 struct in6_ifreq in6_ifr
;
1171 psrcaddr
[0] = pdstaddr
[0] = '\0';
1174 memset(&in6_ifr
, 0, sizeof(in6_ifr
));
1175 strncpy(in6_ifr
.ifr_name
, name
, IFNAMSIZ
);
1176 s6
= socket(AF_INET6
, SOCK_DGRAM
, 0);
1178 srccmd
= SIOCGIFPSRCADDR
;
1179 dstcmd
= SIOCGIFPDSTADDR
;
1183 srccmd
= SIOCGIFPSRCADDR_IN6
;
1184 dstcmd
= SIOCGIFPDSTADDR_IN6
;
1185 ifrp
= (struct ifreq
*)&in6_ifr
;
1188 srccmd
= SIOCGIFPSRCADDR
;
1189 dstcmd
= SIOCGIFPDSTADDR
;
1193 if (ioctl(s
, srccmd
, (caddr_t
)ifrp
) < 0)
1196 if (ifrp
->ifr_addr
.sa_family
== AF_INET6
)
1197 in6_fillscopeid((struct sockaddr_in6
*)&ifrp
->ifr_addr
);
1199 getnameinfo(&ifrp
->ifr_addr
, ifrp
->ifr_addr
.sa_len
,
1200 psrcaddr
, sizeof(psrcaddr
), 0, 0, niflag
);
1202 if (ifrp
->ifr_addr
.sa_family
== AF_INET6
)
1206 if (ioctl(s
, dstcmd
, (caddr_t
)ifrp
) < 0)
1209 if (ifrp
->ifr_addr
.sa_family
== AF_INET6
)
1210 in6_fillscopeid((struct sockaddr_in6
*)&ifrp
->ifr_addr
);
1212 getnameinfo(&ifrp
->ifr_addr
, ifrp
->ifr_addr
.sa_len
,
1213 pdstaddr
, sizeof(pdstaddr
), 0, 0, niflag
);
1215 printf("\ttunnel inet%s %s --> %s\n", ver
,
1216 psrcaddr
, pdstaddr
);
1222 struct rt_addrinfo
* info
;
1224 struct sockaddr_in
*sin
, null_sin
;
1226 memset(&null_sin
, 0, sizeof(null_sin
));
1228 sin
= (struct sockaddr_in
*)info
->rti_info
[RTAX_IFA
];
1229 printf("\tinet %s ", inet_ntoa(sin
->sin_addr
));
1231 if (flags
& IFF_POINTOPOINT
) {
1232 /* note RTAX_BRD overlap with IFF_BROADCAST */
1233 sin
= (struct sockaddr_in
*)info
->rti_info
[RTAX_BRD
];
1236 printf("--> %s ", inet_ntoa(sin
->sin_addr
));
1239 sin
= (struct sockaddr_in
*)info
->rti_info
[RTAX_NETMASK
];
1242 printf("netmask 0x%lx ", (unsigned long)ntohl(sin
->sin_addr
.s_addr
));
1244 if (flags
& IFF_BROADCAST
) {
1245 /* note RTAX_BRD overlap with IFF_POINTOPOINT */
1246 sin
= (struct sockaddr_in
*)info
->rti_info
[RTAX_BRD
];
1247 if (sin
&& sin
->sin_addr
.s_addr
!= 0)
1248 printf("broadcast %s", inet_ntoa(sin
->sin_addr
));
1255 in6_fillscopeid(sin6
)
1256 struct sockaddr_in6
*sin6
;
1258 #if defined(__KAME__) && defined(KAME_SCOPEID)
1259 if (IN6_IS_ADDR_LINKLOCAL(&sin6
->sin6_addr
)) {
1260 sin6
->sin6_scope_id
=
1261 ntohs(*(u_int16_t
*)&sin6
->sin6_addr
.s6_addr
[2]);
1262 sin6
->sin6_addr
.s6_addr
[2] = sin6
->sin6_addr
.s6_addr
[3] = 0;
1270 struct rt_addrinfo
* info
;
1272 struct sockaddr_in6
*sin
, null_sin
;
1273 struct in6_ifreq ifr6
;
1276 struct in6_addrlifetime lifetime
;
1277 time_t t
= time(NULL
);
1281 memset(&null_sin
, 0, sizeof(null_sin
));
1283 sin
= (struct sockaddr_in6
*)info
->rti_info
[RTAX_IFA
];
1284 strncpy(ifr6
.ifr_name
, ifr
.ifr_name
, sizeof(ifr
.ifr_name
));
1285 if ((s6
= socket(AF_INET6
, SOCK_DGRAM
, 0)) < 0) {
1286 perror("ifconfig: socket");
1289 ifr6
.ifr_addr
= *sin
;
1290 if (ioctl(s6
, SIOCGIFAFLAG_IN6
, &ifr6
) < 0) {
1291 perror("ifconfig: ioctl(SIOCGIFAFLAG_IN6)");
1295 flags6
= ifr6
.ifr_ifru
.ifru_flags6
;
1296 memset(&lifetime
, 0, sizeof(lifetime
));
1297 ifr6
.ifr_addr
= *sin
;
1298 if (ioctl(s6
, SIOCGIFALIFETIME_IN6
, &ifr6
) < 0) {
1299 perror("ifconfig: ioctl(SIOCGIFALIFETIME_IN6)");
1303 lifetime
= ifr6
.ifr_ifru
.ifru_lifetime
;
1306 /* XXX: embedded link local addr check */
1307 if (IN6_IS_ADDR_LINKLOCAL(&sin
->sin6_addr
) &&
1308 *(u_short
*)&sin
->sin6_addr
.s6_addr
[2] != 0) {
1311 index
= *(u_short
*)&sin
->sin6_addr
.s6_addr
[2];
1312 *(u_short
*)&sin
->sin6_addr
.s6_addr
[2] = 0;
1313 if (sin
->sin6_scope_id
== 0)
1314 sin
->sin6_scope_id
= ntohs(index
);
1316 scopeid
= sin
->sin6_scope_id
;
1318 error
= getnameinfo((struct sockaddr
*)sin
, sin
->sin6_len
, addr_buf
,
1319 sizeof(addr_buf
), NULL
, 0,
1320 NI_NUMERICHOST
|NI_WITHSCOPEID
);
1322 inet_ntop(AF_INET6
, &sin
->sin6_addr
, addr_buf
,
1324 printf("\tinet6 %s ", addr_buf
);
1326 if (flags
& IFF_POINTOPOINT
) {
1327 /* note RTAX_BRD overlap with IFF_BROADCAST */
1328 sin
= (struct sockaddr_in6
*)info
->rti_info
[RTAX_BRD
];
1330 * some of the interfaces do not have valid destination
1333 if (sin
&& sin
->sin6_family
== AF_INET6
) {
1336 /* XXX: embedded link local addr check */
1337 if (IN6_IS_ADDR_LINKLOCAL(&sin
->sin6_addr
) &&
1338 *(u_short
*)&sin
->sin6_addr
.s6_addr
[2] != 0) {
1341 index
= *(u_short
*)&sin
->sin6_addr
.s6_addr
[2];
1342 *(u_short
*)&sin
->sin6_addr
.s6_addr
[2] = 0;
1343 if (sin
->sin6_scope_id
== 0)
1344 sin
->sin6_scope_id
= ntohs(index
);
1347 error
= getnameinfo((struct sockaddr
*)sin
,
1348 sin
->sin6_len
, addr_buf
,
1349 sizeof(addr_buf
), NULL
, 0,
1350 NI_NUMERICHOST
|NI_WITHSCOPEID
);
1352 inet_ntop(AF_INET6
, &sin
->sin6_addr
, addr_buf
,
1354 printf("--> %s ", addr_buf
);
1358 sin
= (struct sockaddr_in6
*)info
->rti_info
[RTAX_NETMASK
];
1361 printf("prefixlen %d ", prefix(&sin
->sin6_addr
,
1362 sizeof(struct in6_addr
)));
1364 if ((flags6
& IN6_IFF_ANYCAST
) != 0)
1366 if ((flags6
& IN6_IFF_TENTATIVE
) != 0)
1367 printf("tentative ");
1368 if ((flags6
& IN6_IFF_DUPLICATED
) != 0)
1369 printf("duplicated ");
1370 if ((flags6
& IN6_IFF_DETACHED
) != 0)
1371 printf("detached ");
1372 if ((flags6
& IN6_IFF_DEPRECATED
) != 0)
1373 printf("deprecated ");
1374 if ((flags6
& IN6_IFF_AUTOCONF
) != 0)
1375 printf("autoconf ");
1376 if ((flags6
& IN6_IFF_TEMPORARY
) != 0)
1377 printf("temporary ");
1380 printf("scopeid 0x%x ", scopeid
);
1382 if (ip6lifetime
&& (lifetime
.ia6t_preferred
|| lifetime
.ia6t_expire
)) {
1384 if (lifetime
.ia6t_preferred
) {
1385 printf("%s ", lifetime
.ia6t_preferred
< t
1386 ? "0" : sec2str(lifetime
.ia6t_preferred
- t
));
1391 if (lifetime
.ia6t_expire
) {
1392 printf("%s ", lifetime
.ia6t_expire
< t
1393 ? "0" : sec2str(lifetime
.ia6t_expire
- t
));
1406 struct rt_addrinfo
* info
;
1408 struct sockaddr_ns
*sns
, null_sns
;
1410 memset(&null_sns
, 0, sizeof(null_sns
));
1412 sns
= (struct sockaddr_ns
*)info
->rti_info
[RTAX_IFA
];
1413 printf("\tns %s ", ns_ntoa(sns
->sns_addr
));
1415 if (flags
& IFF_POINTOPOINT
) {
1416 sns
= (struct sockaddr_ns
*)info
->rti_info
[RTAX_BRD
];
1419 printf("--> %s ", ns_ntoa(sns
->sns_addr
));
1429 ether_status(s
, info
)
1431 struct rt_addrinfo
*info
;
1435 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)info
;
1437 cp
= (char *)LLADDR(sdl
);
1438 if ((n
= sdl
->sdl_alen
) > 0) {
1439 if (sdl
->sdl_type
== IFT_ETHER
)
1440 printf ("\tether ");
1442 printf ("\tlladdr ");
1444 printf("%02x%c",*cp
++ & 0xff, n
>0? ':' : ' ');
1456 errx(1, "%s: no such interface", cmd
);
1460 errx(1, "%s: permission denied", cmd
);
1468 #define SIN(x) ((struct sockaddr_in *) &(x))
1469 struct sockaddr_in
*sintab
[] = {
1470 SIN(ridreq
.ifr_addr
), SIN(addreq
.ifra_addr
),
1471 SIN(addreq
.ifra_mask
), SIN(addreq
.ifra_broadaddr
)};
1474 in_getaddr(s
, which
)
1478 register struct sockaddr_in
*sin
= sintab
[which
];
1482 sin
->sin_len
= sizeof(*sin
);
1484 sin
->sin_family
= AF_INET
;
1486 if (which
== ADDR
) {
1489 if((p
= strrchr(s
, '/')) != NULL
) {
1490 /* address is `name/masklen' */
1493 struct sockaddr_in
*min
= sintab
[NMASK
];
1495 ret
= sscanf(p
+1, "%u", &masklen
);
1496 if(ret
!= 1 || (masklen
< 0 || masklen
> 32)) {
1498 errx(1, "%s: bad value", s
);
1500 min
->sin_len
= sizeof(*min
);
1501 min
->sin_addr
.s_addr
= htonl(~((1LL << (32 - masklen
)) - 1) &
1506 if (inet_aton(s
, &sin
->sin_addr
))
1508 if ((hp
= gethostbyname(s
)) != 0)
1509 bcopy(hp
->h_addr
, (char *)&sin
->sin_addr
,
1510 MIN(hp
->h_length
, sizeof(sin
->sin_addr
)));
1511 else if ((np
= getnetbyname(s
)) != 0)
1512 sin
->sin_addr
= inet_makeaddr(np
->n_net
, INADDR_ANY
);
1514 errx(1, "%s: bad value", s
);
1518 #define SIN6(x) ((struct sockaddr_in6 *) &(x))
1519 struct sockaddr_in6
*sin6tab
[] = {
1520 SIN6(in6_ridreq
.ifr_addr
), SIN6(in6_addreq
.ifra_addr
),
1521 SIN6(in6_addreq
.ifra_prefixmask
), SIN6(in6_addreq
.ifra_dstaddr
)};
1524 in6_getaddr(s
, which
)
1528 register struct sockaddr_in6
*sin
= sin6tab
[which
];
1529 struct addrinfo hints
, *res
;
1534 sin
->sin6_len
= sizeof(*sin
);
1536 sin
->sin6_family
= AF_INET6
;
1538 if (which
== ADDR
) {
1540 if((p
= strrchr(s
, '/')) != NULL
) {
1542 in6_getprefix(p
+ 1, NMASK
);
1543 explicit_prefix
= 1;
1547 if (sin
->sin6_family
== AF_INET6
) {
1548 bzero(&hints
, sizeof(struct addrinfo
));
1549 hints
.ai_family
= AF_INET6
;
1550 error
= getaddrinfo(s
, NULL
, &hints
, &res
);
1553 if (inet_pton(AF_INET6
, s
, &sin
->sin6_addr
) != 1)
1554 errx(1, "%s: bad value", s
);
1556 bcopy(res
->ai_addr
, sin
, res
->ai_addrlen
);
1560 in6_getprefix(plen
, which
)
1564 register struct sockaddr_in6
*sin
= sin6tab
[which
];
1565 register u_char
*cp
;
1566 int len
= atoi(plen
);
1568 if ((len
< 0) || (len
> 128))
1569 errx(1, "%s: bad value", plen
);
1570 sin
->sin6_len
= sizeof(*sin
);
1572 sin
->sin6_family
= AF_INET6
;
1573 if ((len
== 0) || (len
== 128)) {
1574 memset(&sin
->sin6_addr
, 0xff, sizeof(struct in6_addr
));
1577 memset((void *)&sin
->sin6_addr
, 0x00, sizeof(sin
->sin6_addr
));
1578 for (cp
= (u_char
*)&sin
->sin6_addr
; len
> 7; len
-= 8)
1580 *cp
= 0xff << (8 - len
);
1585 * Print a value a la the %b format of the kernel's printf
1590 register unsigned v
;
1591 register const char *bits
;
1593 register int i
, any
= 0;
1596 if (bits
&& *bits
== 8)
1597 printf("%s=%o", s
, v
);
1599 printf("%s=%x", s
, v
);
1603 while ((i
= *bits
++) != '\0') {
1604 if (v
& (1 << (i
-1))) {
1608 for (; (c
= *bits
) > 32; bits
++)
1611 for (; *bits
> 32; bits
++)
1619 ether_getaddr(addr
, which
)
1623 struct ether_addr
*ea
;
1624 struct sockaddr
*sea
= &ridreq
.ifr_addr
;
1626 ea
= ether_aton(addr
);
1628 errx(1, "malformed ether address");
1630 errx(1, "Ethernet does not use netmasks");
1631 sea
->sa_family
= AF_LINK
;
1632 sea
->sa_len
= ETHER_ADDR_LEN
;
1633 bcopy(ea
, sea
->sa_data
, ETHER_ADDR_LEN
);
1642 register u_char
*name
= (u_char
*)val
;
1643 register int byte
, bit
, plen
= 0;
1645 for (byte
= 0; byte
< size
; byte
++, plen
+= 8)
1646 if (name
[byte
] != 0xff)
1650 for (bit
= 7; bit
!= 0; bit
--, plen
++)
1651 if (!(name
[byte
] & (1 << bit
)))
1653 for (; bit
!= 0; bit
--)
1654 if (name
[byte
] & (1 << bit
))
1657 for (; byte
< size
; byte
++)
1667 static char result
[256];
1668 int days
, hours
, mins
, secs
;
1673 days
= total
/ 3600 / 24;
1674 hours
= (total
/ 3600) % 24;
1675 mins
= (total
/ 60) % 60;
1680 p
+= sprintf(p
, "%dd", days
);
1682 if (!first
|| hours
) {
1684 p
+= sprintf(p
, "%dh", hours
);
1686 if (!first
|| mins
) {
1688 p
+= sprintf(p
, "%dm", mins
);
1690 sprintf(p
, "%ds", secs
);
1692 sprintf(result
, "%lu", (unsigned long)total
);
1703 s
= socket(AF_INET
, SOCK_DGRAM
, 0);
1707 memset(&ifr
, 0, sizeof(ifr
));
1708 (void) strlcpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
1709 if (ioctl(s
, SIOCIFCREATE
, &ifr
) < 0)
1710 err(1, "SIOCIFCREATE");
1712 if (strcmp(name
, ifr
.ifr_name
) != 0) {
1713 printf("%s\n", ifr
.ifr_name
);
1714 strlcpy(name
, ifr
.ifr_name
, sizeof(name
));
1721 clone_destroy(const char *val
, int d
, int s
, const struct afswtch
*rafp
)
1724 (void) strncpy(ifr
.ifr_name
, name
, sizeof(ifr
.ifr_name
));
1725 if (ioctl(s
, SIOCIFDESTROY
, &ifr
) < 0)
1726 err(1, "SIOCIFDESTROY");