]>
git.saurik.com Git - apple/network_cmds.git/blob - mptcp_client/conn_lib.c
2 * Copyright (c) 2012-2014 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 // Created by Anumita Biswas on 10/30/12.
38 #include <sys/types.h>
39 #include <sys/socket.h>
40 #include <sys/ioctl.h>
47 copyassocids(int s
, sae_associd_t
**aidpp
, uint32_t *cnt
)
49 struct so_aidreq aidr
;
53 if (aidpp
== NULL
|| cnt
== NULL
) {
60 bzero(&aidr
, sizeof (aidr
));
62 err
= ioctl(s
, SIOCGASSOCIDS
, &aidr
);
66 /* none, just return */
67 if (aidr
.sar_cnt
== 0)
70 buf
= calloc(aidr
.sar_cnt
, sizeof (sae_associd_t
));
75 err
= ioctl(s
, SIOCGASSOCIDS
, &aidr
);
88 freeassocids(sae_associd_t
*aidp
)
94 copyconnids(int s
, sae_associd_t aid
, sae_connid_t
**cidp
, uint32_t *cnt
)
96 struct so_cidreq cidr
;
100 if (cidp
== NULL
|| cnt
== NULL
) {
107 bzero(&cidr
, sizeof (cidr
));
110 err
= ioctl(s
, SIOCGCONNIDS
, &cidr
);
114 /* none, just return */
115 if (cidr
.scr_cnt
== 0)
118 buf
= calloc(cidr
.scr_cnt
, sizeof (sae_connid_t
));
123 err
= ioctl(s
, SIOCGCONNIDS
, &cidr
);
136 freeconnids(sae_connid_t
*cidp
)
142 copyconninfo(int s
, sae_connid_t cid
, conninfo_t
**cfop
)
144 struct sockaddr
*src
= NULL
, *dst
= NULL
, *aux
= NULL
;
145 struct so_cinforeq scir
;
146 conninfo_t
*buf
= NULL
;
154 bzero(&scir
, sizeof (scir
));
157 if (ioctl(s
, SIOCGCONNINFO
, &scir
) != 0)
160 if (scir
.scir_src_len
!= 0) {
161 src
= calloc(1, scir
.scir_src_len
);
166 if (scir
.scir_dst_len
!= 0) {
167 dst
= calloc(1, scir
.scir_dst_len
);
172 if (scir
.scir_aux_len
!= 0) {
173 aux
= calloc(1, scir
.scir_aux_len
);
176 scir
.scir_aux_data
= aux
;
179 if (ioctl(s
, SIOCGCONNINFO
, &scir
) != 0)
182 buf
= calloc(1, sizeof (*buf
));
186 // When we query for the length using the first ioctl call above, the kernel
187 // tells us the length of the aux structure so we know how much to allocate
188 // memory. There may not be any aux data, which will be indicated by the aux
189 // data length using the second ioctl call.
190 if (scir
.scir_aux_len
== 0 && aux
!= NULL
) {
193 scir
.scir_aux_data
= NULL
;
196 buf
->ci_flags
= scir
.scir_flags
;
197 buf
->ci_ifindex
= scir
.scir_ifindex
;
200 buf
->ci_error
= scir
.scir_error
;
201 buf
->ci_aux_type
= scir
.scir_aux_type
;
202 buf
->ci_aux_data
= aux
;
203 *cfop
= (conninfo_t
*)buf
;
221 freeconninfo(conninfo_t
*cfo
)
223 if (cfo
->ci_src
!= NULL
)
226 if (cfo
->ci_dst
!= NULL
)
229 if (cfo
->ci_aux_data
!= NULL
)
230 free(cfo
->ci_aux_data
);