source: branches/samba-3.0/source/nsswitch/wins.c@ 612

Last change on this file since 612 was 312, checked in by Herwig Bauernfeind, 16 years ago

Update 3.0 to final 3.0.36 (source)

File size: 9.7 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 a WINS nsswitch module
4 Copyright (C) Andrew Tridgell 1999
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20*/
21
22#include "includes.h"
23#ifdef HAVE_NS_API_H
24#undef VOLATILE
25
26#include <ns_daemon.h>
27#endif
28
29#if HAVE_PTHREAD_H
30#include <pthread.h>
31#endif
32
33#if HAVE_PTHREAD
34static pthread_mutex_t wins_nss_mutex = PTHREAD_MUTEX_INITIALIZER;
35#endif
36
37#ifndef INADDRSZ
38#define INADDRSZ 4
39#endif
40
41static int initialised;
42
43extern BOOL AllowDebugChange;
44
45NSS_STATUS _nss_wins_gethostbyname_r(const char *hostname, struct hostent *he,
46 char *buffer, size_t buflen, int *h_errnop);
47NSS_STATUS _nss_wins_gethostbyname2_r(const char *name, int af, struct hostent *he,
48 char *buffer, size_t buflen, int *h_errnop);
49
50/* Use our own create socket code so we don't recurse.... */
51
52static int wins_lookup_open_socket_in(void)
53{
54 struct sockaddr_in sock;
55 int val=1;
56 int res;
57
58 memset((char *)&sock,'\0',sizeof(sock));
59
60#ifdef HAVE_SOCK_SIN_LEN
61 sock.sin_len = sizeof(sock);
62#endif
63 sock.sin_port = 0;
64 sock.sin_family = AF_INET;
65 sock.sin_addr.s_addr = interpret_addr("0.0.0.0");
66 res = socket(AF_INET, SOCK_DGRAM, 0);
67 if (res == -1)
68 return -1;
69
70 setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val));
71#ifdef SO_REUSEPORT
72 setsockopt(res,SOL_SOCKET,SO_REUSEPORT,(char *)&val,sizeof(val));
73#endif /* SO_REUSEPORT */
74
75 /* now we've got a socket - we need to bind it */
76
77 if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) {
78 close(res);
79 return(-1);
80 }
81
82 set_socket_options(res,"SO_BROADCAST");
83
84 return res;
85}
86
87
88static void nss_wins_init(void)
89{
90 initialised = 1;