$NetBSD: patch-af,v 1.4 2013/11/21 09:18:17 obache Exp $ * Treat NetBSD same as FreeBSD. * Move sys/param.h and config.h header files before using conditions. * libupnp>=1.6.7 support. --- src/ushare.c.orig 2007-12-09 13:03:36.000000000 +0000 +++ src/ushare.c @@ -28,7 +28,11 @@ #include #include -#if (defined(BSD) || defined(__FreeBSD__) || defined(__APPLE__)) +#if (defined(__unix__) || defined(unix)) && !defined(USG) || defined(__NetBSD__) +#include +#endif + +#if (defined(BSD) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__)) #include #include #include @@ -49,18 +53,19 @@ #include #endif -#if (defined(__unix__) || defined(unix)) && !defined(USG) -#include -#endif - #include #include +#if UPNP_VERSION >= 10607 +#include +#endif + +#include "config.h" + #if (defined(HAVE_SETLOCALE) && defined(CONFIG_NLS)) # include #endif -#include "config.h" #include "ushare.h" #include "services.h" #include "http.h" @@ -177,7 +182,12 @@ handle_action_request (struct Upnp_Actio struct service_t *service; struct service_action_t *action; char val[256]; +#if UPNP_VERSION < 10607 uint32_t ip; +#else + int error; + int slen; +#endif if (!request || !ut) return; @@ -188,10 +198,30 @@ handle_action_request (struct Upnp_Actio if (strcmp (request->DevUDN + 5, ut->udn)) return; +#if UPNP_VERSION < 10607 ip = request->CtrlPtIPAddr.s_addr; ip = ntohl (ip); sprintf (val, "%d.%d.%d.%d", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF); +#else +#ifdef __sun + switch (request->CtrlPtIPAddr.ss_family) { + case AF_INET: + slen = sizeof (struct sockaddr_in); + break; + case AF_INET6: + slen = sizeof (struct sockaddr_in6); + break; + default: + slen = sizeof (request->CtrlPtIPAddr); + break; + } +#else + slen = request->CtrlPtIPAddr.ss_len; +#endif + error = getnameinfo((struct sockaddr *)&(request->CtrlPtIPAddr), slen, + val, sizeof(val), NULL, 0, NI_NUMERICHOST); +#endif if (ut->verbose) { @@ -505,7 +535,7 @@ create_udn (char *interface) char *buf; unsigned char *ptr; -#if (defined(BSD) || defined(__FreeBSD__) || defined(__APPLE__)) +#if (defined(BSD) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__)) int mib[6]; size_t len; struct if_msghdr *ifm; @@ -517,7 +547,7 @@ create_udn (char *interface) if (!interface) return NULL; -#if (defined(BSD) || defined(__FreeBSD__) || defined(__APPLE__)) +#if (defined(BSD) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__NetBSD__)) mib[0] = CTL_NET; mib[1] = AF_ROUTE; mib[2] = 0; @@ -568,7 +598,7 @@ create_udn (char *interface) buf = (char *) malloc (64 * sizeof (char)); memset (buf, 0, 64); ptr = (unsigned char *) ifr.ifr_hwaddr.sa_data; -#endif /* (defined(BSD) || defined(__FreeBSD__)) */ +#endif /* (defined(BSD) || defined(__FreeBSD__) || defined(__NetBSD__)) */ snprintf (buf, 64, "%s-%02x%02x%02x%02x%02x%02x", DEFAULT_UUID, (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), @@ -718,7 +748,7 @@ reload_config (int s __attribute__ ((unu } } -inline void +void display_headers (void) { printf (_("%s (version %s), a lightweight UPnP A/V and DLNA Media Server.\n"), @@ -734,11 +764,8 @@ setup_i18n(void) #ifdef HAVE_SETLOCALE setlocale (LC_ALL, ""); #endif -#if (!defined(BSD) && !defined(__FreeBSD__)) bindtextdomain (PACKAGE, LOCALEDIR); #endif - textdomain (PACKAGE); -#endif } #define SHUTDOWN_MSG _("Server is shutting down: other clients will be notified soon, Bye bye ...\n") @@ -845,6 +872,9 @@ main (int argc, char **argv) signal (SIGINT, UPnPBreak); signal (SIGHUP, reload_config); +#ifndef MSG_NOSIGNAL + signal (SIGPIPE, SIG_IGN); +#endif if (ut->use_telnet) {