From 5902acfc600aa7d331608b1286d6af0b21f6a7ba Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 10 Dec 2010 23:48:06 +0000 Subject: [PATCH 1/1] network_cmds-329.2.2.tar.gz --- netstat.tproj/if.c | 168 +++++++++++++++++++++---- netstat.tproj/main.c | 6 +- network_cmds.xcodeproj/project.pbxproj | 33 +++-- ping.tproj/ping.c | 43 ++++++- 4 files changed, 203 insertions(+), 47 deletions(-) diff --git a/netstat.tproj/if.c b/netstat.tproj/if.c index 18986be..881e8ae 100644 --- a/netstat.tproj/if.c +++ b/netstat.tproj/if.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Apple Inc. All rights reserved. + * Copyright (c) 2008-2010 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -459,8 +459,10 @@ struct iftot { u_int64_t ift_dr; /* drops */ u_int64_t ift_ib; /* input bytes */ u_int64_t ift_ob; /* output bytes */ - u_int64_t ift_obgp; /* output bg packets */ - u_int64_t ift_obgb; /* output bg bytes */ + u_int64_t ift_itcp; /* input tc packets */ + u_int64_t ift_itcb; /* input tc bytes */ + u_int64_t ift_otcp; /* output tc packets */ + u_int64_t ift_otcb; /* output tc bytes */ }; u_char signalled; /* set if alarm goes off "early" */ @@ -486,7 +488,6 @@ sidewaysintpr() sigset_t sigset, oldsigset; struct itimerval timer_interval; - /* Common OID prefix */ name[0] = CTL_NET; name[1] = PF_LINK; @@ -536,21 +537,30 @@ sidewaysintpr() (void)setitimer(ITIMER_REAL, &timer_interval, NULL); first = 1; banner: - printf("%17s %14s %16s", "input", - interesting ? interesting->ift_name : "(Total)", "output"); + if (prioflag) + printf("%37s %14s %16s", "input", + interesting ? interesting->ift_name : "(Total)", "output"); + else + printf("%17s %14s %16s", "input", + interesting ? interesting->ift_name : "(Total)", "output"); putchar('\n'); - printf("%10s %5s %10s %10s %5s %10s %5s", - "packets", "errs", "bytes", "packets", "errs", "bytes", "colls"); + printf("%10s %5s %10s ", + "packets", "errs", "bytes"); + if (prioflag) + printf(" %10s %10s", "tcpkts", "tcbytes"); + printf("%10s %5s %10s %5s", + "packets", "errs", "bytes", "colls"); if (dflag) printf(" %5.5s", "drops"); if (prioflag) - printf(" %10s %10s", "obgpkts", "obgbytes"); + printf(" %10s %10s", "tcpkts", "tcbytes"); putchar('\n'); fflush(stdout); line = 0; loop: if (interesting != NULL) { struct ifmibdata ifmd; + struct ifmibdata_supplemental ifmsupp; len = sizeof(struct ifmibdata); name[3] = IFMIB_IFDATA; @@ -559,21 +569,64 @@ loop: if (sysctl(name, 6, &ifmd, &len, (void *)0, 0) == -1) err(1, "sysctl IFDATA_GENERAL %d", interesting_row); + if (prioflag) { + len = sizeof(struct ifmibdata_supplemental); + name[3] = IFMIB_IFDATA; + name[4] = interesting_row; + name[5] = IFDATA_SUPPLEMENTAL; + if (sysctl(name, 6, &ifmsupp, &len, (void *)0, 0) == -1) + err(1, "sysctl IFDATA_SUPPLEMENTAL %d", interesting_row); + } if (!first) { - printf("%10llu %5llu %10llu %10llu %5llu %10llu %5llu", + printf("%10llu %5llu %10llu ", ifmd.ifmd_data.ifi_ipackets - interesting->ift_ip, ifmd.ifmd_data.ifi_ierrors - interesting->ift_ie, - ifmd.ifmd_data.ifi_ibytes - interesting->ift_ib, + ifmd.ifmd_data.ifi_ibytes - interesting->ift_ib); + switch (prioflag) { + case SO_TC_BK: + printf("%10llu %10llu ", + ifmsupp.ifmd_traffic_class.ifi_ibkpackets - interesting->ift_itcp, + ifmsupp.ifmd_traffic_class.ifi_ibkbytes - interesting->ift_itcb); + break; + case SO_TC_VI: + printf("%10llu %10llu ", + ifmsupp.ifmd_traffic_class.ifi_ivipackets - interesting->ift_itcp, + ifmsupp.ifmd_traffic_class.ifi_ivibytes - interesting->ift_itcb); + break; + case SO_TC_VO: + printf("%10llu %10llu ", + ifmsupp.ifmd_traffic_class.ifi_ivopackets - interesting->ift_itcp, + ifmsupp.ifmd_traffic_class.ifi_ivobytes - interesting->ift_itcb); + break; + default: + break; + } + printf("%10llu %5llu %10llu %5llu", ifmd.ifmd_data.ifi_opackets - interesting->ift_op, ifmd.ifmd_data.ifi_oerrors - interesting->ift_oe, ifmd.ifmd_data.ifi_obytes - interesting->ift_ob, ifmd.ifmd_data.ifi_collisions - interesting->ift_co); if (dflag) printf(" %5llu", ifmd.ifmd_snd_drops - interesting->ift_dr); - if (prioflag) - printf(" %10llu %10llu", - ifmd.ifmd_filler[0] - interesting->ift_obgp, - ifmd.ifmd_filler[1] - interesting->ift_obgb); + switch (prioflag) { + case SO_TC_BK: + printf(" %10llu %10llu", + ifmsupp.ifmd_traffic_class.ifi_obkpackets - interesting->ift_otcp, + ifmsupp.ifmd_traffic_class.ifi_obkbytes - interesting->ift_otcb); + break; + case SO_TC_VI: + printf(" %10llu %10llu", + ifmsupp.ifmd_traffic_class.ifi_ovipackets - interesting->ift_otcp, + ifmsupp.ifmd_traffic_class.ifi_ovibytes - interesting->ift_otcb); + break; + case SO_TC_VO: + printf(" %10llu %10llu", + ifmsupp.ifmd_traffic_class.ifi_ovopackets - interesting->ift_otcp, + ifmsupp.ifmd_traffic_class.ifi_ovobytes - interesting->ift_otcb); + break; + default: + break; + } } interesting->ift_ip = ifmd.ifmd_data.ifi_ipackets; interesting->ift_ie = ifmd.ifmd_data.ifi_ierrors; @@ -584,10 +637,31 @@ loop: interesting->ift_co = ifmd.ifmd_data.ifi_collisions; interesting->ift_dr = ifmd.ifmd_snd_drops; /* private counters */ - interesting->ift_obgp = ifmd.ifmd_filler[0]; - interesting->ift_obgb = ifmd.ifmd_filler[1]; + switch (prioflag) { + case SO_TC_BK: + interesting->ift_itcp = ifmsupp.ifmd_traffic_class.ifi_ibkpackets; + interesting->ift_itcb = ifmsupp.ifmd_traffic_class.ifi_ibkbytes; + interesting->ift_otcp = ifmsupp.ifmd_traffic_class.ifi_obkpackets; + interesting->ift_otcb = ifmsupp.ifmd_traffic_class.ifi_obkbytes; + break; + case SO_TC_VI: + interesting->ift_itcp = ifmsupp.ifmd_traffic_class.ifi_ivipackets; + interesting->ift_itcb = ifmsupp.ifmd_traffic_class.ifi_ivibytes; + interesting->ift_otcp = ifmsupp.ifmd_traffic_class.ifi_ovipackets; + interesting->ift_otcb = ifmsupp.ifmd_traffic_class.ifi_ovibytes; + break; + case SO_TC_VO: + interesting->ift_itcp = ifmsupp.ifmd_traffic_class.ifi_ivopackets; + interesting->ift_itcb = ifmsupp.ifmd_traffic_class.ifi_ivobytes; + interesting->ift_otcp = ifmsupp.ifmd_traffic_class.ifi_ovopackets; + interesting->ift_otcb = ifmsupp.ifmd_traffic_class.ifi_ovobytes; + break; + default: + break; + } } else { unsigned int latest_ifcount; + struct ifmibdata_supplemental *ifmsuppall = NULL; len = sizeof(int); name[3] = IFMIB_SYSTEM; @@ -600,7 +674,7 @@ loop: free(ifmdall); ifmdall = malloc(len); if (ifmdall == 0) - err(1, "malloc failed"); + err(1, "malloc ifmdall failed"); } else if (latest_ifcount > ifcount) { ifcount = latest_ifcount; len = ifcount * sizeof(struct ifmibdata); @@ -611,7 +685,17 @@ loop: name[5] = IFDATA_GENERAL; if (sysctl(name, 6, ifmdall, &len, (void *)0, 0) == -1) err(1, "sysctl IFMIB_IFALLDATA"); - + if (prioflag) { + len = ifcount * sizeof(struct ifmibdata_supplemental); + ifmsuppall = malloc(len); + if (ifmsuppall == NULL) + err(1, "malloc ifmsuppall failed"); + name[3] = IFMIB_IFALLDATA; + name[4] = 0; + name[5] = IFDATA_SUPPLEMENTAL; + if (sysctl(name, 6, ifmsuppall, &len, (void *)0, 0) == -1) + err(1, "sysctl IFMIB_IFALLDATA SUPPLEMENTAL"); + } sum->ift_ip = 0; sum->ift_ie = 0; sum->ift_ib = 0; @@ -620,8 +704,10 @@ loop: sum->ift_ob = 0; sum->ift_co = 0; sum->ift_dr = 0; - sum->ift_obgp = 0; - sum->ift_obgb = 0; + sum->ift_itcp = 0; + sum->ift_itcb = 0; + sum->ift_otcp = 0; + sum->ift_otcb = 0; for (i = 0; i < ifcount; i++) { struct ifmibdata *ifmd = ifmdall + i; @@ -634,14 +720,42 @@ loop: sum->ift_co += ifmd->ifmd_data.ifi_collisions; sum->ift_dr += ifmd->ifmd_snd_drops; /* private counters */ - sum->ift_obgp += ifmd->ifmd_filler[0]; - sum->ift_obgb += ifmd->ifmd_filler[1]; + if (prioflag) { + struct ifmibdata_supplemental *ifmsupp = ifmsuppall + i; + switch (prioflag) { + case SO_TC_BK: + sum->ift_itcp += ifmsupp->ifmd_traffic_class.ifi_ibkpackets; + sum->ift_itcb += ifmsupp->ifmd_traffic_class.ifi_ibkbytes; + sum->ift_otcp += ifmsupp->ifmd_traffic_class.ifi_obkpackets; + sum->ift_otcb += ifmsupp->ifmd_traffic_class.ifi_obkbytes; + break; + case SO_TC_VI: + sum->ift_itcp += ifmsupp->ifmd_traffic_class.ifi_ivipackets; + sum->ift_itcb += ifmsupp->ifmd_traffic_class.ifi_ivibytes; + sum->ift_otcp += ifmsupp->ifmd_traffic_class.ifi_ovipackets; + sum->ift_otcb += ifmsupp->ifmd_traffic_class.ifi_ovibytes; + break; + case SO_TC_VO: + sum->ift_itcp += ifmsupp->ifmd_traffic_class.ifi_ivopackets; + sum->ift_itcb += ifmsupp->ifmd_traffic_class.ifi_ivobytes; + sum->ift_otcp += ifmsupp->ifmd_traffic_class.ifi_ovopackets; + sum->ift_otcb += ifmsupp->ifmd_traffic_class.ifi_ovobytes; + break; + default: + break; + } + } } if (!first) { - printf("%10llu %5llu %10llu %10llu %5llu %10llu %5llu", + printf("%10llu %5llu %10llu ", sum->ift_ip - total->ift_ip, sum->ift_ie - total->ift_ie, - sum->ift_ib - total->ift_ib, + sum->ift_ib - total->ift_ib); + if (prioflag) + printf(" %10llu %10llu", + sum->ift_itcp - total->ift_itcp, + sum->ift_itcb - total->ift_itcb); + printf("%10llu %5llu %10llu %5llu", sum->ift_op - total->ift_op, sum->ift_oe - total->ift_oe, sum->ift_ob - total->ift_ob, @@ -650,8 +764,8 @@ loop: printf(" %5llu", sum->ift_dr - total->ift_dr); if (prioflag) printf(" %10llu %10llu", - sum->ift_obgp - total->ift_obgp, - sum->ift_obgb - total->ift_obgb); + sum->ift_otcp - total->ift_otcp, + sum->ift_otcb - total->ift_otcb); } *total = *sum; } diff --git a/netstat.tproj/main.c b/netstat.tproj/main.c index 102c933..c30de82 100644 --- a/netstat.tproj/main.c +++ b/netstat.tproj/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Apple Inc. All rights reserved. + * Copyright (c) 2008-2010 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -307,7 +307,7 @@ main(argc, argv) af = AF_UNSPEC; - while ((ch = getopt(argc, argv, "Aabdf:gI:iLlmnPp:rRstuWw:")) != -1) + while ((ch = getopt(argc, argv, "Aabdf:gI:iLlmnP:p:rRstuWw:")) != -1) switch(ch) { case 'A': Aflag = 1; @@ -370,7 +370,7 @@ main(argc, argv) nflag = 1; break; case 'P': - prioflag = 1; + prioflag = atoi(optarg); break; case 'p': if ((tp = name2protox(optarg)) == NULL) { diff --git a/network_cmds.xcodeproj/project.pbxproj b/network_cmds.xcodeproj/project.pbxproj index 8bd8b93..ccf6127 100644 --- a/network_cmds.xcodeproj/project.pbxproj +++ b/network_cmds.xcodeproj/project.pbxproj @@ -402,91 +402,91 @@ isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 726121530EE8881700AFED1B /* ifconfig */; + remoteGlobalIDString = 726121530EE8881700AFED1B; remoteInfo = ifconfig; }; 72ABD0891083D753008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 726121820EE8897C00AFED1B /* ip6conf */; + remoteGlobalIDString = 726121820EE8897C00AFED1B; remoteInfo = ip6conf; }; 72ABD08B1083D75D008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 724DAC0C0EE8940D008900D0 /* ndp */; + remoteGlobalIDString = 724DAC0C0EE8940D008900D0; remoteInfo = ndp; }; 72ABD08D1083D75F008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7216D2450EE896C000AE70E4 /* netstat */; + remoteGlobalIDString = 7216D2450EE896C000AE70E4; remoteInfo = netstat; }; 72ABD08F1083D762008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7216D27B0EE8980A00AE70E4 /* ping */; + remoteGlobalIDString = 7216D27B0EE8980A00AE70E4; remoteInfo = ping; }; 72ABD0911083D764008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7216D2990EE898BD00AE70E4 /* ping6 */; + remoteGlobalIDString = 7216D2990EE898BD00AE70E4; remoteInfo = ping6; }; 72ABD0931083D767008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7216D2CC0EE89B7900AE70E4 /* rarpd */; + remoteGlobalIDString = 7216D2CC0EE89B7900AE70E4; remoteInfo = rarpd; }; 72ABD0951083D76A008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7216D2EC0EE89CBC00AE70E4 /* route */; + remoteGlobalIDString = 7216D2EC0EE89CBC00AE70E4; remoteInfo = route; }; 72ABD0971083D76D008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7216D3130EE89E9E00AE70E4 /* rtadvd */; + remoteGlobalIDString = 7216D3130EE89E9E00AE70E4; remoteInfo = rtadvd; }; 72ABD0991083D76F008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7216D3580EE8A02200AE70E4 /* rtsol */; + remoteGlobalIDString = 7216D3580EE8A02200AE70E4; remoteInfo = rtsol; }; 72ABD09B1083D772008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7294F0F80EE8BB460052EC88 /* traceroute */; + remoteGlobalIDString = 7294F0F80EE8BB460052EC88; remoteInfo = traceroute; }; 72ABD09D1083D774008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7294F1290EE8BD280052EC88 /* traceroute6 */; + remoteGlobalIDString = 7294F1290EE8BD280052EC88; remoteInfo = traceroute6; }; 72ABD0A31083D818008C721C /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 724862310EE86EB7001D0DE9 /* Project object */; proxyType = 1; - remoteGlobalIDString = 7261212C0EE8710B00AFED1B /* arp */; + remoteGlobalIDString = 7261212C0EE8710B00AFED1B; remoteInfo = arp; }; 72CD1D9B0EE8C47C005F825D /* PBXContainerItemProxy */ = { @@ -1708,7 +1708,14 @@ isa = PBXProject; buildConfigurationList = 724862340EE86EB7001D0DE9 /* Build configuration list for PBXProject "network_cmds" */; compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; hasScannedForEncodings = 0; + knownRegions = ( + English, + Japanese, + French, + German, + ); mainGroup = 7248622F0EE86EB7001D0DE9; productRefGroup = 7261210D0EE8707500AFED1B /* Products */; projectDirPath = ""; diff --git a/ping.tproj/ping.c b/ping.tproj/ping.c index 0b50aad..b0a8f0d 100644 --- a/ping.tproj/ping.c +++ b/ping.tproj/ping.c @@ -205,6 +205,8 @@ unsigned int ifscope; #if defined(IP_FORCE_OUT_IFP) && TARGET_OS_EMBEDDED char boundifname[IFNAMSIZ]; #endif /* IP_FORCE_OUT_IFP */ +int how_traffic_class = 0; +int traffic_class = -1; /* counters */ long nmissedmax; /* max value of ntransmitted - nreceived - 1 */ @@ -302,7 +304,7 @@ main(argc, argv) outpack = outpackhdr + sizeof(struct ip); while ((ch = getopt(argc, argv, - "Aab:c:DdfG:g:h:I:i:Ll:M:m:nop:QqRrS:s:T:t:vW:z:" + "Aab:c:DdfG:g:h:I:i:k:Ll:M:m:nop:QqRrS:s:T:t:vW:z:" #ifdef IPSEC #ifdef IPSEC_POLICY_IPSEC "P:" @@ -419,6 +421,10 @@ main(argc, argv) err(EX_NOPERM, "-i interval too short"); } break; + case 'k': + how_traffic_class++; + traffic_class = atoi(optarg); + break; case 'L': options |= F_NOLOOP; loop = 0; @@ -678,6 +684,10 @@ main(argc, argv) if (options & F_SO_DONTROUTE) (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&hold, sizeof(hold)); + if (how_traffic_class == 1) { + (void)setsockopt(s, SOL_SOCKET, SO_TRAFFIC_CLASS, (void *)&traffic_class, + sizeof(traffic_class)); + } #ifdef IPSEC #ifdef IPSEC_POLICY_IPSEC if (options & F_POLICY) { @@ -1058,9 +1068,34 @@ pinger(void) ip->ip_sum = in_cksum((u_short *)outpackhdr, cc); packet = outpackhdr; } - i = sendto(s, (char *)packet, cc, 0, (struct sockaddr *)&whereto, - sizeof(whereto)); - + if (how_traffic_class == 2) { + struct msghdr msg; + struct iovec iov; + char *cmbuf[CMSG_SPACE(sizeof(int))]; + struct cmsghdr *cm = (struct cmsghdr *)cmbuf; + + msg.msg_name = &whereto; + msg.msg_namelen = sizeof(whereto); + + iov.iov_base = packet; + iov.iov_len = cc; + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + + cm->cmsg_len = CMSG_LEN(sizeof(int)); + cm->cmsg_level = SOL_SOCKET; + cm->cmsg_type = SO_TRAFFIC_CLASS; + *(int *)CMSG_DATA(cm) = traffic_class; + msg.msg_control = cm; + msg.msg_controllen = CMSG_SPACE(sizeof(int)); + + msg.msg_flags = 0; + + i = sendmsg(s, &msg, 0); + } else { + i = sendto(s, (char *)packet, cc, 0, (struct sockaddr *)&whereto, + sizeof(whereto)); + } if (i < 0 || i != cc) { if (i < 0) { if (options & F_FLOOD && errno == ENOBUFS) { -- 2.45.2