]>
git.saurik.com Git - apple/network_cmds.git/blob - netstat.tproj/mptcp.c
5aca9b6ebcc2b7b8196a10a91bd03110e18bf8b2
2 * Copyright (c) 2013 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@
30 #include <TargetConditionals.h>
33 #if TARGET_OS_EMBEDDED
39 #include <sys/errno.h>
40 #include <sys/types.h>
41 #include <sys/sysctl.h>
43 #include <netinet/in.h>
44 #include <netinet/tcp.h>
45 #include <netinet/mptcp_var.h>
47 #include <arpa/inet.h>
51 /* XXX we can't include tcp_fsm.h because inet.c already includes it. */
52 static const char *tcpstates
[] = {
53 "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD",
54 "ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1", "CLOSING",
55 "LAST_ACK", "FIN_WAIT_2", "TIME_WAIT"
58 static const char *mptcpstates
[] = {
59 "CLOSED", "LISTEN", "ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1",
60 "CLOSING", "LAST_ACK", "FIN_WAIT_2", "TIME_WAIT", "FASTCLOSE_WAIT"
64 extern void inetprint (struct in_addr
*, int, char *, int);
65 extern void inet6print (struct in6_addr
*, int, char *, int);
68 printmptcp(int id
, conninfo_mptcp_t
*mptcp
)
71 conninfo_tcp_t
*tcpci
;
72 struct sockaddr_storage
*src
, *dst
;
76 printf("mptcp/%-2.2d %69s\n", id
,
77 mptcpstates
[mptcp
->mptcpci_state
]);
78 for (i
= 0; i
< mptcp
->mptcpci_nflows
; i
++) {
79 flow
= &mptcp
->mptcpci_flows
[i
];
80 src
= &flow
->flow_src
;
81 dst
= &flow
->flow_dst
;
83 printf(" tcp%d/%-2.2d ", af
== AF_INET
? 4 : 6,
85 printf("%-8.8x ", flow
->flow_flags
);
86 #define SIN(x) ((struct sockaddr_in *)(x))
87 #define SIN6(x) ((struct sockaddr_in6 *)(x))
90 inetprint(&SIN(src
)->sin_addr
, SIN(src
)->sin_port
,
92 inetprint(&SIN(dst
)->sin_addr
, SIN(dst
)->sin_port
,
97 inet6print(&SIN6(src
)->sin6_addr
, SIN6(src
)->sin6_port
,
99 inet6print(&SIN6(dst
)->sin6_addr
, SIN6(dst
)->sin6_port
,
106 tcpci
= &flow
->flow_ci
;
107 printf("%s\n", tcpstates
[tcpci
->tcpci_tcp_info
.tcpi_state
]);
112 mptcppr(uint32_t off
, char *name
, int af
)
114 #pragma unused(off, name, af)
115 const char *mibvar
= "net.inet.mptcp.pcblist";
117 conninfo_mptcp_t
*mptcp
;
121 if (Lflag
|| Aflag
|| mptcp_done
)
125 if (sysctlbyname(mibvar
, 0, &len
, NULL
, 0) < 0) {
127 warn("sysctl: %s", mibvar
);
130 if ((buf
= malloc(len
)) == NULL
) {
134 if (sysctlbyname(mibvar
, buf
, &len
, NULL
, 0) < 0) {
135 warn("sysctl: %s", mibvar
);
140 printf("Active Multipath Internet connections\n");
141 printf("%-8.8s %-9.9s %-22.22s %-22.22s %-11.11s\n",
143 "Local Address", "Foreign Address",
147 while (bufp
< buf
+ len
) {
149 if (buf
+ len
- bufp
< sizeof(conninfo_mptcp_t
))
151 mptcp
= (conninfo_mptcp_t
*)bufp
;
152 printmptcp(id
++, mptcp
);
153 bufp
+= mptcp
->mptcpci_len
;
157 #endif /* TARGET_OS_EMBEDDED */