]>
git.saurik.com Git - apple/network_cmds.git/blob - ifconfig.tproj/iffake.c
2 * Copyright (c) 2017 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
25 * - manage fake interfaces that pretend to be e.g. ethernet
29 * Modification History:
31 * January 17, 2017 Dieter Siegmund (dieter@apple.com)
35 #include <sys/param.h>
36 #include <sys/ioctl.h>
37 #include <sys/socket.h>
42 #include <net/ethernet.h>
44 #include <net/if_var.h>
45 #include <net/if_fake_var.h>
47 #include <net/route.h>
63 struct if_fake_request iffr
;
65 bzero((char *)&ifd
, sizeof(ifd
));
66 bzero((char *)&iffr
, sizeof(iffr
));
67 strlcpy(ifd
.ifd_name
, ifr
.ifr_name
, sizeof(ifd
.ifd_name
));
68 ifd
.ifd_cmd
= IF_FAKE_G_CMD_GET_PEER
;
69 ifd
.ifd_len
= sizeof(iffr
);
71 if (ioctl(s
, SIOCGDRVSPEC
, &ifd
) < 0) {
74 if (iffr
.iffr_peer_name
[0] == '\0') {
75 printf("\tpeer: <none>\n");
77 printf("\tpeer: %s\n", iffr
.iffr_peer_name
);
83 set_peer(int s
, const char * operation
, const char * val
)
86 struct if_fake_request iffr
;
88 bzero((char *)&ifd
, sizeof(ifd
));
89 bzero((char *)&iffr
, sizeof(iffr
));
90 strlcpy(ifd
.ifd_name
, ifr
.ifr_name
, sizeof(ifd
.ifd_name
));
91 ifd
.ifd_cmd
= IF_FAKE_S_CMD_SET_PEER
;
92 ifd
.ifd_len
= sizeof(iffr
);
95 strlcpy(iffr
.iffr_peer_name
, val
, sizeof(iffr
.iffr_peer_name
));
97 if (ioctl(s
, SIOCSDRVSPEC
, &ifd
) < 0) {
98 err(1, "SIOCDRVSPEC %s peer", operation
);
104 DECL_CMD_FUNC(setpeer
, val
, d
)
106 set_peer(s
, "set", val
);
111 DECL_CMD_FUNC(unsetpeer
, val
, d
)
113 set_peer(s
, "unset", NULL
);
117 static struct cmd fake_cmds
[] = {
118 DEF_CLONE_CMD_ARG("peer", setpeer
),
119 DEF_CMD_OPTARG("-peer", unsetpeer
),
121 static struct afswtch af_fake
= {
122 .af_name
= "af_fake",
124 .af_other_status
= fake_status
,
127 static __constructor
void
130 #define N(a) (sizeof(a) / sizeof(a[0]))
133 for (i
= 0; i
< N(fake_cmds
); i
++)
134 cmd_register(&fake_cmds
[i
]);
135 af_register(&af_fake
);