+ EC_NULL( q = p = strdup(obj->options.interfaces) );
+ EC_NULL( p = strtok_r(p, ", ", &savep) );
+ while (p) {
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL)
+ continue;
+ if (STRCMP(ifa->ifa_name, !=, p))
+ continue;
+
+ family = ifa->ifa_addr->sa_family;
+ if (family == AF_INET || family == AF_INET6) {
+ if (getnameinfo(ifa->ifa_addr,
+ (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6),
+ interfaddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST) != 0) {
+ LOG(log_error, logtype_afpd, "getinterfaddr: getnameinfo() failed %s", gai_strerror(errno));
+ continue;
+ }
+
+ if ((dsi = dsi_init(obj, obj->options.hostname, interfaddr, obj->options.port)) == NULL)
+ continue;
+
+ status_init(obj, dsi);
+ *next = dsi;
+ next = &dsi->next;
+ dsi->AFPobj = obj;
+
+ LOG(log_note, logtype_afpd, "Netatalk AFP/TCP listening on interface %s with address %s:%d",
+ p,
+ getip_string((struct sockaddr *)&dsi->server),
+ getip_port((struct sockaddr *)&dsi->server));
+ } /* if (family == AF_INET || family == AF_INET6) */
+ } /* for (ifa != NULL) */
+ p = strtok_r(NULL, ", ", &savep);
+ }
+ freeifaddrs(ifaddr);
+#endif
+ }
+
+ /*
+ * Check whether we got a valid DSI from options.listen or options.interfaces,
+ * if not add a DSI that accepts all connections and goes though the list of
+ * network interaces for determining an IP we can advertise in DSIStatus
+ */
+ if (dsi == NULL) {
+ if ((dsi = dsi_init(obj, obj->options.hostname, NULL, obj->options.port)) == NULL)
+ EC_FAIL_LOG("no suitable network address found, use \"afp listen\" or \"afp interfaces\"", 0);