]>
git.cameronkatri.com Git - apple_cmds.git/blob - network_cmds/netstat.tproj/mptcp.c
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>
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", "TERMINATE"
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 %-8.8x/%-8.8x %50s \n"
77 " [tok(%#"PRIx32
") snd(%#"PRIx64
") rcv(%#"PRIx64
") "
79 mptcp
->mptcpci_mpte_flags
, mptcp
->mptcpci_flags
,
80 mptcpstates
[mptcp
->mptcpci_state
], mptcp
->mptcpci_rtoken
,
81 mptcp
->mptcpci_sndnxt
, mptcp
->mptcpci_rcvnxt
,
82 mptcp
->mptcpci_mpte_addrid
);
84 flow
= (mptcp_flow_t
*)((caddr_t
)mptcp
+ mptcp
->mptcpci_flow_offset
);
86 for (i
= 0; i
< mptcp
->mptcpci_nflows
; i
++) {
87 src
= &flow
->flow_src
;
88 dst
= &flow
->flow_dst
;
90 printf(" tcp%d/%-2.2d ", af
== AF_INET
? 4 : 6,
92 printf("%-8.8x ", flow
->flow_flags
);
93 #define SIN(x) ((struct sockaddr_in *)(x))
94 #define SIN6(x) ((struct sockaddr_in6 *)(x))
97 inetprint(&SIN(src
)->sin_addr
, SIN(src
)->sin_port
,
99 inetprint(&SIN(dst
)->sin_addr
, SIN(dst
)->sin_port
,
104 inet6print(&SIN6(src
)->sin6_addr
, SIN6(src
)->sin6_port
,
106 inet6print(&SIN6(dst
)->sin6_addr
, SIN6(dst
)->sin6_port
,
113 tcpci
= (conninfo_tcp_t
*)((caddr_t
)flow
+
114 flow
->flow_tcpci_offset
);
116 " [relseq(%-4.4d), err(%d)]\n",
117 tcpstates
[tcpci
->tcpci_tcp_info
.tcpi_state
],
121 flow
= (mptcp_flow_t
*)((caddr_t
)flow
+ flow
->flow_len
);
126 mptcppr(uint32_t off
, char *name
, int af
)
128 #pragma unused(off, name, af)
129 const char *mibvar
= "net.inet.mptcp.pcblist";
131 conninfo_mptcp_t
*mptcp
;
135 if (Lflag
|| Aflag
|| mptcp_done
)
139 if (sysctlbyname(mibvar
, 0, &len
, NULL
, 0) < 0) {
141 warn("sysctl: %s", mibvar
);
144 if ((buf
= malloc(len
)) == NULL
) {
148 if (sysctlbyname(mibvar
, buf
, &len
, NULL
, 0) < 0) {
149 warn("sysctl: %s", mibvar
);
154 printf("Active Multipath Internet connections\n");
155 printf("%-8.8s %-9.9s %-22.22s %-22.22s %-11.11s\n",
157 "Local Address", "Foreign Address",
161 while (bufp
< buf
+ len
) {
163 if (buf
+ len
- bufp
< sizeof(conninfo_mptcp_t
))
165 mptcp
= (conninfo_mptcp_t
*)bufp
;
166 printmptcp(id
++, mptcp
);
167 bufp
+= mptcp
->mptcpci_len
;