2 * Copyright (c) 2008-2010 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1983, 1988, 1993
30 * The Regents of the University of California. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 static char sccsid[] = "@(#)if.c 8.3 (Berkeley) 4/28/95";
65 static const char rcsid
[] =
66 "$Id: if.c,v 1.7 2006/01/16 04:53:59 lindak Exp $";
69 #include <sys/types.h>
70 #include <sys/socket.h>
71 #include <sys/sysctl.h>
75 #include <net/if_var.h>
76 #include <net/if_dl.h>
77 #include <net/if_types.h>
78 #include <net/if_mib.h>
79 #include <net/ethernet.h>
80 #include <net/route.h>
82 #include <netinet/in.h>
83 #include <netinet/in_var.h>
85 #include <arpa/inet.h>
99 #define ROUNDUP(a, size) (((a) & ((size) - 1)) ? (1 + ((a)|(size - 1))) : (a))
101 #define NEXT_SA(p) (struct sockaddr *) \
102 ((caddr_t)p + (p->sa_len ? ROUNDUP(p->sa_len, sizeof(uint32_t)) : \
105 static void sidewaysintpr ();
106 static void catchalarm (int);
109 char *netname6 (struct sockaddr_in6
*, struct sockaddr
*);
110 static char ntop_buf
[INET6_ADDRSTRLEN
]; /* for inet_ntop() */
114 * Display a formatted value, or a '-' in the same space.
117 show_stat(const char *fmt
, int width
, u_int64_t value
, short showvalue
)
121 /* Construct the format string */
123 sprintf(newfmt
, "%%%d%s", width
, fmt
);
124 printf(newfmt
, value
);
126 sprintf(newfmt
, "%%%ds", width
);
132 get_rti_info(int addrs
, struct sockaddr
*sa
, struct sockaddr
**rti_info
)
137 for (i
= 0; i
< RTAX_MAX
; i
++) {
138 if (addrs
& (1 << i
)) {
140 if (sa
->sa_len
< sizeof(struct sockaddr
))
141 len
+= sizeof(struct sockaddr
);
153 multipr(int family
, char *buf
, char *lim
)
157 for (next
= buf
; next
< lim
; ) {
158 struct ifma_msghdr2
*ifmam
= (struct ifma_msghdr2
*)next
;
159 struct sockaddr
*rti_info
[RTAX_MAX
];
163 next
+= ifmam
->ifmam_msglen
;
164 if (ifmam
->ifmam_type
== RTM_IFINFO2
)
166 else if (ifmam
->ifmam_type
!= RTM_NEWMADDR2
)
168 get_rti_info(ifmam
->ifmam_addrs
, (struct sockaddr
*)(ifmam
+ 1), rti_info
);
169 sa
= rti_info
[RTAX_IFA
];
171 if (sa
->sa_family
!= family
)
173 switch (sa
->sa_family
) {
175 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sa
;
177 fmt
= routename(sin
->sin_addr
.s_addr
);
182 struct sockaddr_in6 sin6
;
184 memcpy(&sin6
, sa
, sizeof(struct sockaddr_in6
));
186 if (IN6_IS_ADDR_LINKLOCAL(&sin6
.sin6_addr
) ||
187 IN6_IS_ADDR_MC_LINKLOCAL(&sin6
.sin6_addr
)) {
188 sin6
.sin6_scope_id
= ntohs(*(u_int16_t
*)&sin6
.sin6_addr
.s6_addr
[2]);
189 sin6
.sin6_addr
.s6_addr
[2] = 0;
190 sin6
.sin6_addr
.s6_addr
[3] = 0;
193 printf("%23s %-19.19s(refs: %d)\n", "",
194 inet_ntop(AF_INET6
, &sin6
.sin6_addr
,
195 ntop_buf
, sizeof(ntop_buf
)),
196 ifmam
->ifmam_refcount
);
201 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)sa
;
203 switch (sdl
->sdl_type
) {
206 fmt
= ether_ntoa((struct ether_addr
*)
214 printf("%23s %s\n", "", fmt
);
219 * Print a description of the network interfaces.
222 intpr(void (*pfunc
)(char *))
224 u_int64_t opackets
= 0;
225 u_int64_t ipackets
= 0;
226 u_int64_t obytes
= 0;
227 u_int64_t ibytes
= 0;
228 u_int64_t oerrors
= 0;
229 u_int64_t ierrors
= 0;
230 u_int64_t collisions
= 0;
234 struct sockaddr
*sa
= NULL
;
239 char *buf
= NULL
, *lim
, *next
;
241 struct if_msghdr
*ifm
;
242 struct sockaddr
*rti_info
[RTAX_MAX
];
243 unsigned int ifindex
= 0;
251 ifindex
= if_nametoindex(interface
);
253 mib
[0] = CTL_NET
; // networking subsystem
254 mib
[1] = PF_ROUTE
; // type of information
255 mib
[2] = 0; // protocol (IPPROTO_xxx)
256 mib
[3] = 0; // address family
257 mib
[4] = NET_RT_IFLIST2
; // operation
259 if (sysctl(mib
, 6, NULL
, &len
, NULL
, 0) < 0)
261 if ((buf
= malloc(len
)) == NULL
) {
262 printf("malloc failed\n");
265 if (sysctl(mib
, 6, buf
, &len
, NULL
, 0) < 0) {
271 printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s",
272 "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs");
274 printf(" %10.10s","Ibytes");
275 printf(" %8.8s %5.5s", "Opkts", "Oerrs");
277 printf(" %10.10s","Obytes");
278 printf(" %5s", "Coll");
280 printf(" %s", "Time");
282 printf(" %s", "Drop");
286 for (next
= buf
; next
< lim
; ) {
292 ifm
= (struct if_msghdr
*)next
;
293 next
+= ifm
->ifm_msglen
;
295 if (ifm
->ifm_type
== RTM_IFINFO2
) {
296 struct if_msghdr2
*if2m
= (struct if_msghdr2
*)ifm
;
297 struct sockaddr_dl
*sdl
= (struct sockaddr_dl
*)(if2m
+ 1);
299 strncpy(name
, sdl
->sdl_data
, sdl
->sdl_nlen
);
300 name
[sdl
->sdl_nlen
] = 0;
301 if (interface
!= 0 && if2m
->ifm_index
!= ifindex
)
303 cp
= index(name
, '\0');
310 if ((if2m
->ifm_flags
& IFF_UP
) == 0)
315 * Get the interface stats. These may get
316 * overriden below on a per-interface basis.
318 opackets
= if2m
->ifm_data
.ifi_opackets
;
319 ipackets
= if2m
->ifm_data
.ifi_ipackets
;
320 obytes
= if2m
->ifm_data
.ifi_obytes
;
321 ibytes
= if2m
->ifm_data
.ifi_ibytes
;
322 oerrors
=if2m
->ifm_data
.ifi_oerrors
;
323 ierrors
= if2m
->ifm_data
.ifi_ierrors
;
324 collisions
= if2m
->ifm_data
.ifi_collisions
;
325 timer
= if2m
->ifm_timer
;
326 drops
= if2m
->ifm_snd_drops
;
327 mtu
= if2m
->ifm_data
.ifi_mtu
;
329 get_rti_info(if2m
->ifm_addrs
, (struct sockaddr
*)(if2m
+ 1), rti_info
);
330 sa
= rti_info
[RTAX_IFP
];
331 } else if (ifm
->ifm_type
== RTM_NEWADDR
) {
332 struct ifa_msghdr
*ifam
= (struct ifa_msghdr
*)ifm
;
334 if (interface
!= 0 && ifam
->ifam_index
!= ifindex
)
336 get_rti_info(ifam
->ifam_addrs
, (struct sockaddr
*)(ifam
+ 1), rti_info
);
337 sa
= rti_info
[RTAX_IFA
];
341 printf("%-5.5s %-5u ", name
, mtu
);
344 printf("%-13.13s ", "none");
345 printf("%-15.15s ", "none");
347 switch (sa
->sa_family
) {
349 printf("%-13.13s ", "none");
350 printf("%-15.15s ", "none");
354 struct sockaddr_in
*sin
= (struct sockaddr_in
*)sa
;
355 struct sockaddr_in mask
;
357 mask
.sin_addr
.s_addr
= 0;
359 rti_info
[RTAX_NETMASK
],
360 ((struct sockaddr_in
*)rti_info
[RTAX_NETMASK
])->sin_len
);
363 netname(sin
->sin_addr
.s_addr
& mask
.sin_addr
.s_addr
,
364 ntohl(mask
.sin_addr
.s_addr
)));
367 routename(sin
->sin_addr
.s_addr
));
374 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)sa
;
375 struct sockaddr
*mask
= (struct sockaddr
*)rti_info
[RTAX_NETMASK
];
381 (char *)inet_ntop(AF_INET6
,
383 ntop_buf
, sizeof(ntop_buf
)));
390 struct sockaddr_dl
*sdl
=
391 (struct sockaddr_dl
*)sa
;
393 cp
= (char *)LLADDR(sdl
);
395 sprintf(linknum
, "<Link#%d>", sdl
->sdl_index
);
396 m
= printf("%-11.11s ", linknum
);
401 m
= printf("(%d)", sa
->sa_family
);
402 for (cp
= sa
->sa_len
+ (char *)sa
;
403 --cp
> sa
->sa_data
&& (*cp
== 0);) {}
404 n
= cp
- sa
->sa_data
+ 1;
408 m
+= printf("%02x%c", *cp
++ & 0xff,
419 show_stat("llu", 8, ipackets
, link_layer
|network_layer
);
421 show_stat("llu", 5, ierrors
, link_layer
);
424 show_stat("llu", 10, ibytes
, link_layer
|network_layer
);
427 show_stat("llu", 8, opackets
, link_layer
|network_layer
);
429 show_stat("llu", 5, oerrors
, link_layer
);
432 show_stat("llu", 10, obytes
, link_layer
|network_layer
);
435 show_stat("llu", 5, collisions
, link_layer
);
438 show_stat("ll", 3, timer
, link_layer
);
442 show_stat("ll", 3, drops
, link_layer
);
447 multipr(sa
->sa_family
, next
, lim
);
452 SLIST_ENTRY(iftot
) chain
;
453 char ift_name
[16]; /* interface name */
454 u_int64_t ift_ip
; /* input packets */
455 u_int64_t ift_ie
; /* input errors */
456 u_int64_t ift_op
; /* output packets */
457 u_int64_t ift_oe
; /* output errors */
458 u_int64_t ift_co
; /* collisions */
459 u_int64_t ift_dr
; /* drops */
460 u_int64_t ift_ib
; /* input bytes */
461 u_int64_t ift_ob
; /* output bytes */
462 u_int64_t ift_itcp
; /* input tc packets */
463 u_int64_t ift_itcb
; /* input tc bytes */
464 u_int64_t ift_otcp
; /* output tc packets */
465 u_int64_t ift_otcb
; /* output tc bytes */
468 u_char signalled
; /* set if alarm goes off "early" */
471 * Print a running summary of interface statistics.
472 * Repeat display every interval seconds, showing statistics
473 * collected over that interval. Assumes that interval is non-zero.
474 * First line printed at top of screen is always cumulative.
475 * XXX - should be rewritten to use ifmib(4).
480 struct iftot
*total
, *sum
, *interesting
;
485 unsigned int ifcount
, i
;
486 struct ifmibdata
*ifmdall
= 0;
488 sigset_t sigset
, oldsigset
;
489 struct itimerval timer_interval
;
491 /* Common OID prefix */
494 name
[2] = NETLINK_GENERIC
;
497 name
[3] = IFMIB_SYSTEM
;
498 name
[4] = IFMIB_IFCOUNT
;
499 if (sysctl(name
, 5, &ifcount
, &len
, 0, 0) == 1)
500 err(1, "sysctl IFMIB_IFCOUNT");
502 len
= ifcount
* sizeof(struct ifmibdata
);
503 ifmdall
= malloc(len
);
505 err(1, "malloc failed");
506 name
[3] = IFMIB_IFALLDATA
;
508 name
[5] = IFDATA_GENERAL
;
509 if (sysctl(name
, 6, ifmdall
, &len
, (void *)0, 0) == -1)
510 err(1, "sysctl IFMIB_IFALLDATA");
514 for (i
= 0; i
< ifcount
; i
++) {
515 struct ifmibdata
*ifmd
= ifmdall
+ i
;
517 if (interface
&& strcmp(ifmd
->ifmd_name
, interface
) == 0) {
518 if ((interesting
= calloc(ifcount
, sizeof(struct iftot
))) == NULL
)
519 err(1, "malloc failed");
520 interesting_row
= i
+ 1;
521 snprintf(interesting
->ift_name
, 16, "(%s)", ifmd
->ifmd_name
);;
524 if ((total
= calloc(1, sizeof(struct iftot
))) == NULL
)
525 err(1, "malloc failed");
527 if ((sum
= calloc(1, sizeof(struct iftot
))) == NULL
)
528 err(1, "malloc failed");
530 /* create a timer that fires repeatedly every interval seconds */
531 timer_interval
.it_value
.tv_sec
= interval
;
532 timer_interval
.it_value
.tv_usec
= 0;
533 timer_interval
.it_interval
.tv_sec
= interval
;
534 timer_interval
.it_interval
.tv_usec
= 0;
535 (void)signal(SIGALRM
, catchalarm
);
537 (void)setitimer(ITIMER_REAL
, &timer_interval
, NULL
);
541 printf("%37s %14s %16s", "input",
542 interesting
? interesting
->ift_name
: "(Total)", "output");
544 printf("%17s %14s %16s", "input",
545 interesting
? interesting
->ift_name
: "(Total)", "output");
547 printf("%10s %5s %10s ",
548 "packets", "errs", "bytes");
550 printf(" %10s %10s", "tcpkts", "tcbytes");
551 printf("%10s %5s %10s %5s",
552 "packets", "errs", "bytes", "colls");
554 printf(" %5.5s", "drops");
556 printf(" %10s %10s", "tcpkts", "tcbytes");
561 if (interesting
!= NULL
) {
562 struct ifmibdata ifmd
;
563 struct ifmibdata_supplemental ifmsupp
;
565 len
= sizeof(struct ifmibdata
);
566 name
[3] = IFMIB_IFDATA
;
567 name
[4] = interesting_row
;
568 name
[5] = IFDATA_GENERAL
;
569 if (sysctl(name
, 6, &ifmd
, &len
, (void *)0, 0) == -1)
570 err(1, "sysctl IFDATA_GENERAL %d", interesting_row
);
573 len
= sizeof(struct ifmibdata_supplemental
);
574 name
[3] = IFMIB_IFDATA
;
575 name
[4] = interesting_row
;
576 name
[5] = IFDATA_SUPPLEMENTAL
;
577 if (sysctl(name
, 6, &ifmsupp
, &len
, (void *)0, 0) == -1)
578 err(1, "sysctl IFDATA_SUPPLEMENTAL %d", interesting_row
);
581 printf("%10llu %5llu %10llu ",
582 ifmd
.ifmd_data
.ifi_ipackets
- interesting
->ift_ip
,
583 ifmd
.ifmd_data
.ifi_ierrors
- interesting
->ift_ie
,
584 ifmd
.ifmd_data
.ifi_ibytes
- interesting
->ift_ib
);
587 printf("%10llu %10llu ",
588 ifmsupp
.ifmd_traffic_class
.ifi_ibkpackets
- interesting
->ift_itcp
,
589 ifmsupp
.ifmd_traffic_class
.ifi_ibkbytes
- interesting
->ift_itcb
);
592 printf("%10llu %10llu ",
593 ifmsupp
.ifmd_traffic_class
.ifi_ivipackets
- interesting
->ift_itcp
,
594 ifmsupp
.ifmd_traffic_class
.ifi_ivibytes
- interesting
->ift_itcb
);
597 printf("%10llu %10llu ",
598 ifmsupp
.ifmd_traffic_class
.ifi_ivopackets
- interesting
->ift_itcp
,
599 ifmsupp
.ifmd_traffic_class
.ifi_ivobytes
- interesting
->ift_itcb
);
604 printf("%10llu %5llu %10llu %5llu",
605 ifmd
.ifmd_data
.ifi_opackets
- interesting
->ift_op
,
606 ifmd
.ifmd_data
.ifi_oerrors
- interesting
->ift_oe
,
607 ifmd
.ifmd_data
.ifi_obytes
- interesting
->ift_ob
,
608 ifmd
.ifmd_data
.ifi_collisions
- interesting
->ift_co
);
610 printf(" %5llu", ifmd
.ifmd_snd_drops
- interesting
->ift_dr
);
613 printf(" %10llu %10llu",
614 ifmsupp
.ifmd_traffic_class
.ifi_obkpackets
- interesting
->ift_otcp
,
615 ifmsupp
.ifmd_traffic_class
.ifi_obkbytes
- interesting
->ift_otcb
);
618 printf(" %10llu %10llu",
619 ifmsupp
.ifmd_traffic_class
.ifi_ovipackets
- interesting
->ift_otcp
,
620 ifmsupp
.ifmd_traffic_class
.ifi_ovibytes
- interesting
->ift_otcb
);
623 printf(" %10llu %10llu",
624 ifmsupp
.ifmd_traffic_class
.ifi_ovopackets
- interesting
->ift_otcp
,
625 ifmsupp
.ifmd_traffic_class
.ifi_ovobytes
- interesting
->ift_otcb
);
631 interesting
->ift_ip
= ifmd
.ifmd_data
.ifi_ipackets
;
632 interesting
->ift_ie
= ifmd
.ifmd_data
.ifi_ierrors
;
633 interesting
->ift_ib
= ifmd
.ifmd_data
.ifi_ibytes
;
634 interesting
->ift_op
= ifmd
.ifmd_data
.ifi_opackets
;
635 interesting
->ift_oe
= ifmd
.ifmd_data
.ifi_oerrors
;
636 interesting
->ift_ob
= ifmd
.ifmd_data
.ifi_obytes
;
637 interesting
->ift_co
= ifmd
.ifmd_data
.ifi_collisions
;
638 interesting
->ift_dr
= ifmd
.ifmd_snd_drops
;
639 /* private counters */
642 interesting
->ift_itcp
= ifmsupp
.ifmd_traffic_class
.ifi_ibkpackets
;
643 interesting
->ift_itcb
= ifmsupp
.ifmd_traffic_class
.ifi_ibkbytes
;
644 interesting
->ift_otcp
= ifmsupp
.ifmd_traffic_class
.ifi_obkpackets
;
645 interesting
->ift_otcb
= ifmsupp
.ifmd_traffic_class
.ifi_obkbytes
;
648 interesting
->ift_itcp
= ifmsupp
.ifmd_traffic_class
.ifi_ivipackets
;
649 interesting
->ift_itcb
= ifmsupp
.ifmd_traffic_class
.ifi_ivibytes
;
650 interesting
->ift_otcp
= ifmsupp
.ifmd_traffic_class
.ifi_ovipackets
;
651 interesting
->ift_otcb
= ifmsupp
.ifmd_traffic_class
.ifi_ovibytes
;
654 interesting
->ift_itcp
= ifmsupp
.ifmd_traffic_class
.ifi_ivopackets
;
655 interesting
->ift_itcb
= ifmsupp
.ifmd_traffic_class
.ifi_ivobytes
;
656 interesting
->ift_otcp
= ifmsupp
.ifmd_traffic_class
.ifi_ovopackets
;
657 interesting
->ift_otcb
= ifmsupp
.ifmd_traffic_class
.ifi_ovobytes
;
663 unsigned int latest_ifcount
;
664 struct ifmibdata_supplemental
*ifmsuppall
= NULL
;
667 name
[3] = IFMIB_SYSTEM
;
668 name
[4] = IFMIB_IFCOUNT
;
669 if (sysctl(name
, 5, &latest_ifcount
, &len
, 0, 0) == 1)
670 err(1, "sysctl IFMIB_IFCOUNT");
671 if (latest_ifcount
> ifcount
) {
672 ifcount
= latest_ifcount
;
673 len
= ifcount
* sizeof(struct ifmibdata
);
675 ifmdall
= malloc(len
);
677 err(1, "malloc ifmdall failed");
678 } else if (latest_ifcount
> ifcount
) {
679 ifcount
= latest_ifcount
;
680 len
= ifcount
* sizeof(struct ifmibdata
);
682 len
= ifcount
* sizeof(struct ifmibdata
);
683 name
[3] = IFMIB_IFALLDATA
;
685 name
[5] = IFDATA_GENERAL
;
686 if (sysctl(name
, 6, ifmdall
, &len
, (void *)0, 0) == -1)
687 err(1, "sysctl IFMIB_IFALLDATA");
689 len
= ifcount
* sizeof(struct ifmibdata_supplemental
);
690 ifmsuppall
= malloc(len
);
691 if (ifmsuppall
== NULL
)
692 err(1, "malloc ifmsuppall failed");
693 name
[3] = IFMIB_IFALLDATA
;
695 name
[5] = IFDATA_SUPPLEMENTAL
;
696 if (sysctl(name
, 6, ifmsuppall
, &len
, (void *)0, 0) == -1)
697 err(1, "sysctl IFMIB_IFALLDATA SUPPLEMENTAL");
711 for (i
= 0; i
< ifcount
; i
++) {
712 struct ifmibdata
*ifmd
= ifmdall
+ i
;
714 sum
->ift_ip
+= ifmd
->ifmd_data
.ifi_ipackets
;
715 sum
->ift_ie
+= ifmd
->ifmd_data
.ifi_ierrors
;
716 sum
->ift_ib
+= ifmd
->ifmd_data
.ifi_ibytes
;
717 sum
->ift_op
+= ifmd
->ifmd_data
.ifi_opackets
;
718 sum
->ift_oe
+= ifmd
->ifmd_data
.ifi_oerrors
;
719 sum
->ift_ob
+= ifmd
->ifmd_data
.ifi_obytes
;
720 sum
->ift_co
+= ifmd
->ifmd_data
.ifi_collisions
;
721 sum
->ift_dr
+= ifmd
->ifmd_snd_drops
;
722 /* private counters */
724 struct ifmibdata_supplemental
*ifmsupp
= ifmsuppall
+ i
;
727 sum
->ift_itcp
+= ifmsupp
->ifmd_traffic_class
.ifi_ibkpackets
;
728 sum
->ift_itcb
+= ifmsupp
->ifmd_traffic_class
.ifi_ibkbytes
;
729 sum
->ift_otcp
+= ifmsupp
->ifmd_traffic_class
.ifi_obkpackets
;
730 sum
->ift_otcb
+= ifmsupp
->ifmd_traffic_class
.ifi_obkbytes
;
733 sum
->ift_itcp
+= ifmsupp
->ifmd_traffic_class
.ifi_ivipackets
;
734 sum
->ift_itcb
+= ifmsupp
->ifmd_traffic_class
.ifi_ivibytes
;
735 sum
->ift_otcp
+= ifmsupp
->ifmd_traffic_class
.ifi_ovipackets
;
736 sum
->ift_otcb
+= ifmsupp
->ifmd_traffic_class
.ifi_ovibytes
;
739 sum
->ift_itcp
+= ifmsupp
->ifmd_traffic_class
.ifi_ivopackets
;
740 sum
->ift_itcb
+= ifmsupp
->ifmd_traffic_class
.ifi_ivobytes
;
741 sum
->ift_otcp
+= ifmsupp
->ifmd_traffic_class
.ifi_ovopackets
;
742 sum
->ift_otcb
+= ifmsupp
->ifmd_traffic_class
.ifi_ovobytes
;
750 printf("%10llu %5llu %10llu ",
751 sum
->ift_ip
- total
->ift_ip
,
752 sum
->ift_ie
- total
->ift_ie
,
753 sum
->ift_ib
- total
->ift_ib
);
755 printf(" %10llu %10llu",
756 sum
->ift_itcp
- total
->ift_itcp
,
757 sum
->ift_itcb
- total
->ift_itcb
);
758 printf("%10llu %5llu %10llu %5llu",
759 sum
->ift_op
- total
->ift_op
,
760 sum
->ift_oe
- total
->ift_oe
,
761 sum
->ift_ob
- total
->ift_ob
,
762 sum
->ift_co
- total
->ift_co
);
764 printf(" %5llu", sum
->ift_dr
- total
->ift_dr
);
766 printf(" %10llu %10llu",
767 sum
->ift_otcp
- total
->ift_otcp
,
768 sum
->ift_otcb
- total
->ift_otcb
);
775 sigemptyset(&sigset
);
776 sigaddset(&sigset
, SIGALRM
);
777 (void)sigprocmask(SIG_BLOCK
, &sigset
, &oldsigset
);
779 sigemptyset(&sigset
);
782 (void)sigprocmask(SIG_SETMASK
, &oldsigset
, NULL
);
795 intervalpr(void (*pr
)(uint32_t, char *, int), uint32_t off
, char *name
, int af
)
797 struct itimerval timer_interval
;
798 sigset_t sigset
, oldsigset
;
800 /* create a timer that fires repeatedly every interval seconds */
801 timer_interval
.it_value
.tv_sec
= interval
;
802 timer_interval
.it_value
.tv_usec
= 0;
803 timer_interval
.it_interval
.tv_sec
= interval
;
804 timer_interval
.it_interval
.tv_usec
= 0;
805 (void) signal(SIGALRM
, catchalarm
);
807 (void) setitimer(ITIMER_REAL
, &timer_interval
, NULL
);
813 sigemptyset(&sigset
);
814 sigaddset(&sigset
, SIGALRM
);
815 (void) sigprocmask(SIG_BLOCK
, &sigset
, &oldsigset
);
817 sigemptyset(&sigset
);
820 (void) sigprocmask(SIG_SETMASK
, &oldsigset
, NULL
);
826 * Called if an interval expires before sidewaysintpr has completed a loop.
827 * Sets a flag to not wait for the alarm.
830 catchalarm(int signo
)