]> git.cameronkatri.com Git - apple_cmds.git/blob - network_cmds/ifconfig.tproj/nexus.c
system_cmds: Fix compilation for lower targets, downgrade lsmp
[apple_cmds.git] / network_cmds / ifconfig.tproj / nexus.c
1 /*
2 * Copyright (c) 2017 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * nexus.c
25 * - report information about attached nexus
26 */
27
28 /*
29 * Modification History:
30 *
31 * April 10, 2017 Dieter Siegmund (dieter@apple.com)
32 * - created
33 */
34
35 #include <sys/param.h>
36 #include <sys/ioctl.h>
37 #include <sys/socket.h>
38
39 #include <stdlib.h>
40 #include <unistd.h>
41
42 #include <net/ethernet.h>
43 #include <net/if.h>
44 #include <net/if_var.h>
45 #include <net/if_fake_var.h>
46
47 #include <net/route.h>
48
49 #include <ctype.h>
50 #include <stdio.h>
51 #include <string.h>
52 #include <stdlib.h>
53 #include <unistd.h>
54 #include <err.h>
55 #include <errno.h>
56
57 #include "ifconfig.h"
58
59 #if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 135000
60 #define flowswitch multistack
61 #define ifnr_flowswitch ifnr_multistack
62 #endif
63
64 static void
65 nexus_status(int s)
66 {
67 struct if_nexusreq ifnr;
68 uuid_string_t flowswitch;
69 uuid_string_t netif;
70
71 if (!verbose) {
72 return;
73 }
74 bzero((char *)&ifnr, sizeof(ifnr));
75 strlcpy(ifnr.ifnr_name, ifr.ifr_name, sizeof(ifnr.ifnr_name));
76 if (ioctl(s, SIOCGIFNEXUS, &ifnr) < 0) {
77 return;
78 }
79 if (uuid_is_null(ifnr.ifnr_netif)) {
80 /* technically, this shouldn't happen */
81 return;
82 }
83 uuid_unparse_upper(ifnr.ifnr_netif, netif);
84 printf("\tnetif: %s\n", netif);
85 if (uuid_is_null(ifnr.ifnr_flowswitch) == 0) {
86 uuid_unparse_upper(ifnr.ifnr_flowswitch, flowswitch);
87 printf("\tflowswitch: %s\n", flowswitch);
88 }
89 return;
90 }
91
92 static struct afswtch af_fake = {
93 .af_name = "af_fake",
94 .af_af = AF_UNSPEC,
95 .af_other_status = nexus_status,
96 };
97
98 static __constructor void
99 fake_ctor(void)
100 {
101 af_register(&af_fake);
102 }
103