2 Unix SMB/Netbios implementation.
5 Copyright (C) Andrew Tridgell 1999
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 extern int DEBUGLEVEL;
34 struct in_addr *lookup_backend(const char *name, int *count)
37 static int initialised;
46 setup_logging("nss_wins",True);
48 lp_load(CONFIGFILE,True,False,False);
54 fd = open_socket_in(SOCK_DGRAM,0, 3, interpret_addr("0.0.0.0"), True);
55 if (fd == -1) return NULL;
57 set_socket_options(fd,"SO_BROADCAST");
61 ret = name_query(fd,name,0x20,False,True, *interpret_addr2(p), count);
65 if (lp_wins_support()) {
66 /* we are our own WINS server */
67 ret = name_query(fd,name,0x20,False,True, *interpret_addr2("127.0.0.1"), count);
71 /* uggh, we have to broadcast to each interface in turn */
72 for (j=iface_count() - 1;
75 struct in_addr *bcast = iface_n_bcast(j);
76 ret = name_query(fd,name,0x20,True,True,*bcast,count);
86 /****************************************************************************
87 gethostbyname() - we ignore any domain portion of the name and only
88 handle names that are at most 15 characters long
89 **************************************************************************/
91 _nss_wins_gethostbyname_r(const char *name, struct hostent *he,
92 char *buffer, size_t buflen, int *errnop,
95 char **host_addresses;
96 struct in_addr *ip_list;
99 ip_list = lookup_backend(name, &count);
101 return NSS_STATUS_NOTFOUND;
104 if (buflen < (2*count+1)*INADDRSZ) {
105 /* no ENOMEM error type?! */
106 return NSS_STATUS_NOTFOUND;
110 host_addresses = (char **)buffer;
111 he->h_addr_list = host_addresses;
112 host_addresses[count] = NULL;
113 buffer += (count + 1) * INADDRSZ;
114 buflen += (count + 1) * INADDRSZ;
115 he->h_addrtype = AF_INET;
116 he->h_length = INADDRSZ;
118 for (i=0;i<count;i++) {
119 memcpy(buffer, &ip_list[i].s_addr, INADDRSZ);
120 *host_addresses = buffer;
126 if (ip_list) free(ip_list);
128 return NSS_STATUS_SUCCESS;