lib/util/charset Add back setlocale(), but only when called from binaries
[samba.git] / nsswitch / wins.c
index ac062fe311977ad9c79a360c7306642d70cc53e1..5136c94c76e6e395e150bc73f290242bb4b8d7a9 100644 (file)
@@ -45,54 +45,10 @@ NSS_STATUS _nss_wins_gethostbyname_r(const char *hostname, struct hostent *he,
 NSS_STATUS _nss_wins_gethostbyname2_r(const char *name, int af, struct hostent *he,
                           char *buffer, size_t buflen, int *h_errnop);
 
-/* Use our own create socket code so we don't recurse.... */
-
-static int wins_lookup_open_socket_in(void)
-{
-       struct sockaddr_in sock;
-       int val=1;
-       int res;
-
-       memset((char *)&sock,'\0',sizeof(sock));
-
-#ifdef HAVE_SOCK_SIN_LEN
-       sock.sin_len = sizeof(sock);
-#endif
-       sock.sin_port = 0;
-       sock.sin_family = AF_INET;
-       sock.sin_addr.s_addr = interpret_addr("0.0.0.0");
-       res = socket(AF_INET, SOCK_DGRAM, 0);
-       if (res == -1)
-               return -1;
-
-       if (setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)) != 0) {
-               close(res);
-               return -1;
-       }
-#ifdef SO_REUSEPORT
-       if (setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val)) != 0) {
-               close(res);
-               return -1;
-       }
-#endif /* SO_REUSEPORT */
-
-       /* now we've got a socket - we need to bind it */
-
-       if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) {
-               close(res);
-               return(-1);
-       }
-
-       set_socket_options(res,"SO_BROADCAST");
-
-       return res;
-}
-
-
 static void nss_wins_init(void)
 {
        initialised = 1;
-       load_case_tables();
+       load_case_tables_library();
        lp_set_cmdline("log level", "0");
 
        TimeInit();
@@ -103,10 +59,9 @@ static void nss_wins_init(void)
 
 static struct in_addr *lookup_byname_backend(const char *name, int *count)
 {
-       int fd = -1;
        struct ip_service *address = NULL;
        struct in_addr *ret = NULL;
-       int j, flags = 0;
+       int j;
 
        if (!initialised) {
                nss_wins_init();
@@ -125,16 +80,12 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count)
                        free(ret);
                        return NULL;
                }
-               *ret = ((struct sockaddr_in *)&address[0].ss)->sin_addr;
+               *ret = ((struct sockaddr_in *)(void *)&address[0].ss)
+                       ->sin_addr;
                free( address );
                return ret;
        }
 
-       fd = wins_lookup_open_socket_in();
-       if (fd == -1) {
-               return NULL;
-       }
-
        /* uggh, we have to broadcast to each interface in turn */
        for (j=iface_count() - 1;j >= 0;j--) {
                const struct in_addr *bcast = iface_n_bcast_v4(j);
@@ -146,8 +97,8 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count)
                        continue;
                }
                in_addr_to_sockaddr_storage(&ss, *bcast);
-               status = name_query(fd, name, 0x00, True, True, &ss,
-                                   NULL, &pss, count, &flags, NULL);
+               status = name_query(name, 0x00, True, True, &ss,
+                                   NULL, &pss, count, NULL);
                if (pss) {
                        if ((ret = SMB_MALLOC_P(struct in_addr)) == NULL) {
                                return NULL;
@@ -158,12 +109,54 @@ static struct in_addr *lookup_byname_backend(const char *name, int *count)
                }
        }
 
-       close(fd);
        return ret;
 }
 
 #ifdef HAVE_NS_API_H
 
+/* Use our own create socket code so we don't recurse.... */
+
+static int wins_lookup_open_socket_in(void)
+{
+       struct sockaddr_in sock;
+       int val=1;
+       int res;
+
+       memset((char *)&sock,'\0',sizeof(sock));
+
+#ifdef HAVE_SOCK_SIN_LEN
+       sock.sin_len = sizeof(sock);
+#endif
+       sock.sin_port = 0;
+       sock.sin_family = AF_INET;
+       sock.sin_addr.s_addr = interpret_addr("0.0.0.0");
+       res = socket(AF_INET, SOCK_DGRAM, 0);
+       if (res == -1)
+               return -1;
+
+       if (setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)) != 0) {
+               close(res);
+               return -1;
+       }
+#ifdef SO_REUSEPORT
+       if (setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val)) != 0) {
+               close(res);
+               return -1;
+       }
+#endif /* SO_REUSEPORT */
+
+       /* now we've got a socket - we need to bind it */
+
+       if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) {
+               close(res);
+               return(-1);
+       }
+
+       set_socket_options(res,"SO_BROADCAST");
+
+       return res;
+}
+
 static struct node_status *lookup_byaddr_backend(char *addr, int *count)
 {
        int fd;