- if(!get_config_string(lookup_config(config_tree, "Interface"), &iface))
- iface = xstrdup(rindex(device, '/') ? rindex(device, '/') + 1 : device);
+ if(connect(device_fd, (struct sockaddr *)&sc, sizeof(sc)) == -1) {
+ logger(LOG_ERR, "Could not connect utun socket: %s\n", strerror(errno));
+ return false;
+ }
+
+ char name[64] = "";
+ socklen_t len = sizeof name;
+ if(getsockopt(device_fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, name, &len)) {
+ iface = xstrdup(device);
+ } else {
+ iface = xstrdup(name);
+ }
+
+ device_info = "OS X utun device";
+
+ logger(LOG_INFO, "%s is a %s", device, device_info);
+
+ return true;
+}
+#endif
+
+static bool setup_device(void) {
+ // Find out which device file to open
+
+ if(!get_config_string(lookup_config(config_tree, "Device"), &device)) {
+ if(routing_mode == RMODE_ROUTER)
+ device = xstrdup(DEFAULT_TUN_DEVICE);
+ else
+ device = xstrdup(DEFAULT_TAP_DEVICE);
+ }
+
+ // Find out if it's supposed to be a tun or a tap device
+
+ char *type;