1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
10 typedef enum GetHostnameFlags
{
11 GET_HOSTNAME_ALLOW_LOCALHOST
= 1 << 0, /* accepts "localhost" or friends. */
12 GET_HOSTNAME_FALLBACK_DEFAULT
= 1 << 1, /* use default hostname if no hostname is set. */
13 GET_HOSTNAME_SHORT
= 1 << 2, /* kills the FQDN part if present. */
16 int gethostname_full(GetHostnameFlags flags
, char **ret
);
17 static inline int gethostname_strict(char **ret
) {
18 return gethostname_full(0, ret
);
21 static inline char* gethostname_malloc(void) {
24 if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST
| GET_HOSTNAME_FALLBACK_DEFAULT
, &s
) < 0)
30 static inline char* gethostname_short_malloc(void) {
33 if (gethostname_full(GET_HOSTNAME_ALLOW_LOCALHOST
| GET_HOSTNAME_FALLBACK_DEFAULT
| GET_HOSTNAME_SHORT
, &s
) < 0)
39 char* get_default_hostname(void);
41 bool valid_ldh_char(char c
) _const_
;
43 typedef enum ValidHostnameFlags
{
44 VALID_HOSTNAME_TRAILING_DOT
= 1 << 0, /* Accept trailing dot on multi-label names */
45 VALID_HOSTNAME_DOT_HOST
= 1 << 1, /* Accept ".host" as valid hostname */
48 bool hostname_is_valid(const char *s
, ValidHostnameFlags flags
) _pure_
;
49 char* hostname_cleanup(char *s
);
51 bool is_localhost(const char *hostname
);
53 static inline bool is_gateway_hostname(const char *hostname
) {
54 /* This tries to identify the valid syntaxes for the our synthetic "gateway" host. */
55 return STRCASE_IN_SET(hostname
, "_gateway", "_gateway.");
58 static inline bool is_outbound_hostname(const char *hostname
) {
59 /* This tries to identify the valid syntaxes for the our synthetic "outbound" host. */
60 return STRCASE_IN_SET(hostname
, "_outbound", "_outbound.");
63 static inline bool is_dns_stub_hostname(const char *hostname
) {
64 return STRCASE_IN_SET(hostname
, "_localdnsstub", "_localdnsstub.");
67 static inline bool is_dns_proxy_stub_hostname(const char *hostname
) {
68 return STRCASE_IN_SET(hostname
, "_localdnsproxy", "_localdnsproxy.");
71 int get_pretty_hostname(char **ret
);