|
379 | 379 | #include <unistd.h> |
380 | 380 | #endif |
381 | 381 |
|
| 382 | +// Declare earlier than other implementations |
| 383 | +#ifdef HAVE_VMNET_NETWORK |
| 384 | +#include <vmnet/vmnet.h> |
| 385 | +#endif |
| 386 | + |
382 | 387 | #define MAX(a,b) (((a) > (b)) ? (a) : (b)) |
383 | 388 |
|
384 | 389 | /* Internal routine - forward declaration */ |
@@ -1201,11 +1206,36 @@ if (used < max) { |
1201 | 1206 | #endif |
1202 | 1207 | #ifdef HAVE_VMNET_NETWORK |
1203 | 1208 | if (used < max) { |
1204 | | - sprintf(list[used].name, "%s", "vmnet:{optional-parameters}"); |
1205 | | - sprintf(list[used].desc, "%s", "Integrated vmnet.framework support"); |
| 1209 | + sprintf(list[used].name, "%s", "vmnet:shared"); |
| 1210 | + sprintf(list[used].desc, "%s", "Integrated NAT (vmnet.framework) support"); |
| 1211 | + list[used].eth_api = ETH_API_VMN; |
| 1212 | + ++used; |
| 1213 | +} |
| 1214 | +if (used < max) { |
| 1215 | + sprintf(list[used].name, "%s", "vmnet:host"); |
| 1216 | + sprintf(list[used].desc, "%s", "Integrated host-only network (vmnet.framework) support"); |
1206 | 1217 | list[used].eth_api = ETH_API_VMN; |
1207 | 1218 | ++used; |
1208 | 1219 | } |
| 1220 | +// vmnet.framework has an allowed list of devices for bridging |
| 1221 | +// handy for user if we list them since ifconfig is noisy |
| 1222 | +__block int used_block; |
| 1223 | +{ |
| 1224 | + xpc_object_t bridge_list = vmnet_copy_shared_interface_list(); |
| 1225 | + |
| 1226 | + xpc_array_apply(bridge_list, ^bool(size_t index, xpc_object_t value) { |
| 1227 | + if (used_block < max) { |
| 1228 | + sprintf(list[used_block].name, "%s%s", "vmnet:", xpc_string_get_string_ptr(value)); |
| 1229 | + sprintf(list[used_block].desc, "%s", "Integrated bridged network (vmnet.framework) support"); |
| 1230 | + list[used_block].eth_api = ETH_API_VMN; |
| 1231 | + ++used_block; |
| 1232 | + } |
| 1233 | + return true; |
| 1234 | + }); |
| 1235 | + used = used_block; |
| 1236 | + |
| 1237 | + xpc_release(bridge_list); |
| 1238 | +} |
1209 | 1239 | #endif |
1210 | 1240 |
|
1211 | 1241 | if (used < max) { |
@@ -1256,10 +1286,6 @@ extern "C" { |
1256 | 1286 | #include <dlfcn.h> |
1257 | 1287 | #endif |
1258 | 1288 |
|
1259 | | -#ifdef HAVE_VMNET_NETWORK |
1260 | | -#include <vmnet/vmnet.h> |
1261 | | -#endif |
1262 | | - |
1263 | 1289 | #if defined(USE_SHARED) && (defined(_WIN32) || defined(SIM_HAVE_DLOPEN)) |
1264 | 1290 | /* Dynamic DLL loading technique and modified source comes from |
1265 | 1291 | Etherial/WireShark capture_pcap.c */ |
@@ -2301,12 +2327,20 @@ memset(errbuf, 0, PCAP_ERRBUF_SIZE); |
2301 | 2327 | // Because vmnet operates via callbacks, set up a semaphore to block on |
2302 | 2328 | dispatch_semaphore_t cb_finished; |
2303 | 2329 |
|
| 2330 | + const char *devname = savname + sizeof("vmnet:") - 1; |
| 2331 | + |
2304 | 2332 | if_desc = xpc_dictionary_create(NULL, NULL, 0); |
2305 | 2333 | // VMNET_HOST_MODE: Host and other guests |
2306 | 2334 | // VMNET_SHARED_MODE: NAT |
2307 | 2335 | // VMNET_BRIDGED_MODE: Requires macOS 10.15 |
2308 | | - // XXX: Support other modes. |
2309 | | - xpc_dictionary_set_uint64(if_desc, vmnet_operation_mode_key, VMNET_HOST_MODE); |
| 2336 | + if (0 == strcmp(devname, "shared")) { |
| 2337 | + xpc_dictionary_set_uint64(if_desc, vmnet_operation_mode_key, VMNET_SHARED_MODE); |
| 2338 | + } else if (strlen(devname) == 0 || 0 == strcmp(devname, "host")) { |
| 2339 | + xpc_dictionary_set_uint64(if_desc, vmnet_operation_mode_key, VMNET_HOST_MODE); |
| 2340 | + } else if (strlen(devname) > 0) { // Bridged, this is the device name |
| 2341 | + xpc_dictionary_set_uint64(if_desc, vmnet_operation_mode_key, VMNET_BRIDGED_MODE); |
| 2342 | + xpc_dictionary_set_string(if_desc, vmnet_shared_interface_name_key, devname); |
| 2343 | + } |
2310 | 2344 |
|
2311 | 2345 | vmn_queue = dispatch_get_global_queue(QOS_CLASS_UTILITY, 0); |
2312 | 2346 |
|
@@ -2839,6 +2873,11 @@ fprintf (st, " eth2 vde:device{:switch-port-number} (Integrated VDE su |
2839 | 2873 | fprintf (st, " eth3 nat:{optional-nat-parameters} (Integrated NAT (SLiRP) support)\n"); |
2840 | 2874 | #endif |
2841 | 2875 | fprintf (st, " eth4 udp:sourceport:remotehost:remoteport (Integrated UDP bridge support)\n"); |
| 2876 | +#if defined(HAVE_VMNET_NETWORK) |
| 2877 | +fprintf (st, " eth6 vmnet:shared (Integrated NAT (vmnet.framework) support)\n"); |
| 2878 | +fprintf (st, " eth7 vmnet:host (Integrated host-only (vmnet.framework) support)\n"); |
| 2879 | +fprintf (st, " eth8 vmnet:device-name (Integrated bridged (vmnet.framework) support)\n"); |
| 2880 | +#endif |
2842 | 2881 | fprintf (st, " sim> ATTACH %s eth0\n\n", dptr->name); |
2843 | 2882 | fprintf (st, "or equivalently:\n\n"); |
2844 | 2883 | fprintf (st, " sim> ATTACH %s en0\n\n", dptr->name); |
|
0 commit comments