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");
59 /* The next four lines commented out by JHT
60 and replaced with the four lines following */
61 /* if( !zero_ip( wins_ip ) ) {
62 * ret = name_query( fd, name, 0x20, False, True, wins_src_ip(), count );
68 ret
= name_query(fd
,name
,0x20,False
,True
, p
, count
);
72 if (lp_wins_support()) {
73 /* we are our own WINS server */
74 ret
= name_query(fd
,name
,0x20,False
,True
, *interpret_addr2("127.0.0.1"), count
);
78 /* uggh, we have to broadcast to each interface in turn */
79 for (j
=iface_count() - 1;
82 struct in_addr
*bcast
= iface_n_bcast(j
);
83 ret
= name_query(fd
,name
,0x20,True
,True
,*bcast
,count
);
93 /****************************************************************************
94 gethostbyname() - we ignore any domain portion of the name and only
95 handle names that are at most 15 characters long
96 **************************************************************************/
98 _nss_wins_gethostbyname_r(const char *name
, struct hostent
*he
,
99 char *buffer
, size_t buflen
, int *errnop
,
102 char **host_addresses
;
103 struct in_addr
*ip_list
;
106 ip_list
= lookup_backend(name
, &count
);
108 return NSS_STATUS_NOTFOUND
;
111 if (buflen
< (2*count
+1)*INADDRSZ
) {
112 /* no ENOMEM error type?! */
113 return NSS_STATUS_NOTFOUND
;
117 host_addresses
= (char **)buffer
;
118 he
->h_addr_list
= host_addresses
;
119 host_addresses
[count
] = NULL
;
120 buffer
+= (count
+ 1) * INADDRSZ
;
121 buflen
+= (count
+ 1) * INADDRSZ
;
122 he
->h_addrtype
= AF_INET
;
123 he
->h_length
= INADDRSZ
;
125 for (i
=0;i
<count
;i
++) {
126 memcpy(buffer
, &ip_list
[i
].s_addr
, INADDRSZ
);
127 *host_addresses
= buffer
;
133 if (ip_list
) free(ip_list
);
135 return NSS_STATUS_SUCCESS
;