2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Jeremy Allison 1998-2002
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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "system/network.h"
23 #include "system/filesys.h"
26 The idea is that this file will eventually have wrappers around all
27 important system calls in samba. The aims are:
29 - to enable easier porting by putting OS dependent stuff in here
31 - to allow for hooks into other "pseudo-filesystems"
33 - to allow easier integration of things like the japanese extensions
35 - to support the philosophy of Samba to expose the features of
36 the OS within the SMB model. In general whatever file/printer/variable
37 expansions/etc make sense to the OS should be acceptable to Samba.
40 /**************************************************************************
41 A wrapper for gethostbyname() that tries avoids looking up hostnames
42 in the root domain, which can cause dial-on-demand links to come up for no
44 ****************************************************************************/
46 _PUBLIC_
struct hostent
*sys_gethostbyname(const char *name
)
48 #ifdef REDUCE_ROOT_DNS_LOOKUPS
49 char query
[256], hostname
[256];
52 /* Does this name have any dots in it? If so, make no change */
54 if (strchr(name
, '.'))
55 return(gethostbyname(name
));
57 /* Get my hostname, which should have domain name
58 attached. If not, just do the gethostname on the
62 gethostname(hostname
, sizeof(hostname
) - 1);
63 hostname
[sizeof(hostname
) - 1] = 0;
64 if ((domain
= strchr(hostname
, '.')) == NULL
)
65 return(gethostbyname(name
));
67 /* Attach domain name to query and do modified query.
68 If names too large, just do gethostname on the
72 if((strlen(name
) + strlen(domain
)) >= sizeof(query
))
73 return(gethostbyname(name
));
75 slprintf(query
, sizeof(query
)-1, "%s%s", name
, domain
);
76 return(gethostbyname(query
));
77 #else /* REDUCE_ROOT_DNS_LOOKUPS */
78 return(gethostbyname(name
));
79 #endif /* REDUCE_ROOT_DNS_LOOKUPS */
82 _PUBLIC_
struct in_addr
sys_inet_makeaddr(int net
, int host
)
86 in
= inet_makeaddr(net
, host
);
87 in2
.s_addr
= in
.s_addr
;
91 /**************************************************************************
92 Wrapper for fork. Ensures we clear our pid cache.
93 ****************************************************************************/
95 static pid_t mypid
= (pid_t
)-1;
97 _PUBLIC_ pid_t
sys_fork(void)
99 pid_t forkret
= fork();
101 if (forkret
== (pid_t
)0) {
102 /* Child - reset mypid so sys_getpid does a system call. */
109 /**************************************************************************
110 Wrapper for getpid. Ensures we only do a system call *once*.
111 ****************************************************************************/
113 _PUBLIC_ pid_t
sys_getpid(void)
115 if (mypid
== (pid_t
)-1)