1 /* @(#)hostname.h	1.22 14/01/01 Copyright 1995-2014 J. Schilling */
2 /*
3  *	This file has been separated from libport.h in order to avoid
4  *	to include netdb.h in case gethostname() is not needed.
5  *
6  *	Copyright (c) 1995-2014 J. Schilling
7  */
8 /*
9  * The contents of this file are subject to the terms of the
10  * Common Development and Distribution License, Version 1.0 only
11  * (the "License").  You may not use this file except in compliance
12  * with the License.
13  *
14  * See the file CDDL.Schily.txt in this distribution for details.
15  * A copy of the CDDL is also available via the Internet at
16  * http://www.opensource.org/licenses/cddl1.txt
17  *
18  * When distributing Covered Code, include this CDDL HEADER in each
19  * file and include the License file CDDL.Schily.txt from this distribution.
20  */
21 
22 
23 #ifndef _SCHILY_HOSTNAME_H
24 #define	_SCHILY_HOSTNAME_H
25 
26 #ifndef	_SCHILY_MCONFIG_H
27 #include <schily/mconfig.h>
28 #endif
29 #ifndef _SCHILY_TYPES_H
30 #include <schily/types.h>
31 #endif
32 
33 /*
34  * Try to get HOST_NAME_MAX for gethostname() from unistd.h or limits.h
35  */
36 #ifndef _SCHILY_UNISTD_H
37 #include <schily/unistd.h>
38 #endif
39 #ifndef _SCHILY_LIMITS_H
40 #include <schily/limits.h>
41 #endif
42 
43 #ifndef HOST_NAME_MAX
44 #if	defined(HAVE_NETDB_H) && !defined(HOST_NOT_FOUND) && \
45 				!defined(_INCL_NETDB_H)
46 #ifndef	_SCHILY_NETDB_H
47 #include <schily/netdb.h>	/* #defines MAXHOSTNAMELEN */
48 #endif
49 #endif
50 #ifdef	MAXHOSTNAMELEN
51 #define	HOST_NAME_MAX	MAXHOSTNAMELEN
52 #endif
53 #endif
54 
55 #ifndef HOST_NAME_MAX
56 #ifndef	_SCHILY_PARAM_H
57 #include <schily/param.h>	/* Include various defs needed with some OS */
58 #endif				/* Linux MAXHOSTNAMELEN */
59 #ifdef	MAXHOSTNAMELEN
60 #define	HOST_NAME_MAX	MAXHOSTNAMELEN
61 #endif
62 #endif
63 
64 #ifndef HOST_NAME_MAX
65 #define	HOST_NAME_MAX	255
66 #endif
67 #ifndef	MAXHOSTNAMELEN
68 #define	MAXHOSTNAMELEN	HOST_NAME_MAX
69 #endif
70 
71 #ifdef	__cplusplus
72 extern "C" {
73 #endif
74 
75 /*
76  * The gethostname() prototype from Win-DOS are in the wrong include files
77  * (winsock*.h instead of unistd.h) and they are in conflict with the standard.
78  * Because the prototype is in the wrong file and the function is not in libc,
79  * configure will believe gethostname() is missing.
80  * We cannot define our own correct prototype, but this is not a problem as the
81  * return type is int.
82  */
83 #if !defined(__MINGW32__)
84 #ifndef	HAVE_GETHOSTNAME
85 extern	int		gethostname	__PR((char *name, int namelen));
86 #endif
87 #endif
88 #ifndef	HAVE_GETDOMAINNAME
89 extern	int		getdomainname	__PR((char *name, int namelen));
90 #endif
91 
92 #ifdef	__SUNOS4
93 /*
94  * Define prototypes for POSIX standard functions that are missing on SunOS-4.x
95  * to make compilation smooth.
96  */
97 extern	int		gethostname	__PR((char *name, int namelen));
98 extern	int		getdomainname	__PR((char *name, int namelen));
99 #endif	/* __SUNOS4 */
100 
101 #ifdef	__cplusplus
102 }
103 #endif
104 
105 #endif	/* _SCHILY_HOSTNAME_H */
106