1 /* getdomainname emulation for systems that doesn't have it.
3 Copyright (C) 2003, 2006, 2008, 2010-2024 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* Written by Simon Josefsson. */
29 #if HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H /* IRIX, OSF/1, Solaris */
30 # include <sys/systeminfo.h>
33 /* Return the NIS domain name of the machine.
34 WARNING! The NIS domain name is unrelated to the fully qualified host name
35 of the machine. It is also unrelated to email addresses.
36 WARNING! The NIS domain name is usually the empty string or "(none)" when
39 Put up to LEN bytes of the NIS domain name into NAME.
40 Null terminate it if the name is shorter than LEN.
41 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
42 Return 0 if successful, otherwise set errno and return -1. */
44 getdomainname (char *name
, size_t len
)
47 #if HAVE_GETDOMAINNAME /* Mac OS X, FreeBSD, AIX, IRIX, OSF/1 */
48 extern int getdomainname (char *, int);
52 return getdomainname (name
, (int) len
);
53 #elif HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H && defined SI_SRPC_DOMAIN
57 /* The third argument is a 'long', but the return value must fit in an
58 'int', therefore it's better to avoid arguments > INT_MAX. */
59 ret
= sysinfo (SI_SRPC_DOMAIN
, name
, len
> INT_MAX
? INT_MAX
: len
);
61 /* errno is set here. */
69 #else /* HP-UX, Cygwin, mingw */
70 const char *result
= ""; /* Hardcode your domain name if you want. */
71 size_t result_len
= strlen (result
);
78 memcpy (name
, result
, result_len
);
80 name
[result_len
] = '\0';