+/* get it from the interface list */
+#ifndef IFF_SLAVE
+#define IFF_SLAVE 0
+#endif
+
+static void guess_interface(DSI *dsi, const char *hostname, const char *port)
+{
+ int fd;
+ char **start, **list;
+ struct ifreq ifr;
+ struct sockaddr_in *sa = (struct sockaddr_in *)&dsi->server;
+
+ start = list = getifacelist();
+ if (!start)
+ return;
+
+ fd = socket(PF_INET, SOCK_STREAM, 0);
+
+ while (list && *list) {
+ strlcpy(ifr.ifr_name, *list, sizeof(ifr.ifr_name));
+ list++;
+
+
+ if (ioctl(dsi->serversock, SIOCGIFFLAGS, &ifr) < 0)
+ continue;
+
+ if (ifr.ifr_flags & (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_SLAVE))
+ continue;
+
+ if (!(ifr.ifr_flags & (IFF_UP | IFF_RUNNING)) )
+ continue;
+
+ if (ioctl(fd, SIOCGIFADDR, &ifr) < 0)
+ continue;
+
+ memset(&dsi->server, 0, sizeof(struct sockaddr_storage));
+ sa->sin_family = AF_INET;
+ sa->sin_port = htons(atoi(port));
+ sa->sin_addr = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr;
+
+ LOG(log_info, logtype_dsi, "dsi_tcp: '%s:%s' on interface '%s' will be used instead.",
+ getip_string((struct sockaddr *)&dsi->server), port, ifr.ifr_name);
+ goto iflist_done;
+ }
+ LOG(log_info, logtype_dsi, "dsi_tcp (Chooser will not select afp/tcp) "
+ "Check to make sure %s is in /etc/hosts and the correct domain is in "
+ "/etc/resolv.conf: %s", hostname, strerror(errno));
+
+iflist_done:
+ close(fd);
+ freeifacelist(start);
+}
+
+
+#ifndef AI_NUMERICSERV
+#define AI_NUMERICSERV 0
+#endif
+