Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
hostname.h
Go to the documentation of this file.
1
4
5/*
6 * Copyright (c) 2017 Intel Corporation
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10
11#ifndef ZEPHYR_INCLUDE_NET_HOSTNAME_H_
12#define ZEPHYR_INCLUDE_NET_HOSTNAME_H_
13
14#include <errno.h>
15
16#include <zephyr/sys/util.h>
17#include <zephyr/toolchain.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
31
32#if defined(CONFIG_NET_HOSTNAME_MAX_LEN)
33#define NET_HOSTNAME_MAX_LEN \
34 MAX(CONFIG_NET_HOSTNAME_MAX_LEN, \
35 (sizeof(CONFIG_NET_HOSTNAME) - 1 + \
36 (IS_ENABLED(CONFIG_NET_HOSTNAME_UNIQUE) ? sizeof("0011223344556677") - 1 : 0)))
37#else
39#define NET_HOSTNAME_MAX_LEN \
40 (sizeof(CONFIG_NET_HOSTNAME) - 1 + \
41 (IS_ENABLED(CONFIG_NET_HOSTNAME_UNIQUE) ? sizeof("0011223344556677") - 1 : 0))
42#endif
43
45
46#if defined(CONFIG_NET_HOSTNAME_ENABLE)
47#define NET_HOSTNAME_SIZE NET_HOSTNAME_MAX_LEN + 1
48#else
49#define NET_HOSTNAME_SIZE 1
50#endif
51
53
61#if defined(CONFIG_NET_HOSTNAME_ENABLE)
62const char *net_hostname_get(void);
63#else
64static inline const char *net_hostname_get(void)
65{
66 return "zephyr";
67}
68#endif /* CONFIG_NET_HOSTNAME_ENABLE */
69
78#if defined(CONFIG_NET_HOSTNAME_DYNAMIC)
79int net_hostname_set(char *host, size_t len);
80#else
81static inline int net_hostname_set(char *host, size_t len)
82{
83 ARG_UNUSED(host);
84 ARG_UNUSED(len);
85 return -ENOTSUP;
86}
87#endif
88
93#if defined(CONFIG_NET_HOSTNAME_ENABLE)
94void net_hostname_init(void);
95#else
96static inline void net_hostname_init(void)
97{
98}
99#endif /* CONFIG_NET_HOSTNAME_ENABLE */
100
114#if defined(CONFIG_NET_HOSTNAME_UNIQUE)
115int net_hostname_set_postfix(const uint8_t *hostname_postfix,
116 int postfix_len);
117#else
118static inline int net_hostname_set_postfix(const uint8_t *hostname_postfix,
119 int postfix_len)
120{
121 ARG_UNUSED(hostname_postfix);
122 ARG_UNUSED(postfix_len);
123 return -EMSGSIZE;
124}
125#endif /* CONFIG_NET_HOSTNAME_UNIQUE */
126
141#if defined(CONFIG_NET_HOSTNAME_UNIQUE)
142int net_hostname_set_postfix_str(const uint8_t *hostname_postfix,
143 int postfix_len);
144#else
145static inline int net_hostname_set_postfix_str(const uint8_t *hostname_postfix,
146 int postfix_len)
147{
148 ARG_UNUSED(hostname_postfix);
149 ARG_UNUSED(postfix_len);
150 return -EMSGSIZE;
151}
152#endif /* CONFIG_NET_HOSTNAME_UNIQUE */
153
157
158#ifdef __cplusplus
159}
160#endif
161
162#endif /* ZEPHYR_INCLUDE_NET_HOSTNAME_H_ */
System error numbers.
static int net_hostname_set(char *host, size_t len)
Set the device hostname.
Definition hostname.h:81
static int net_hostname_set_postfix_str(const uint8_t *hostname_postfix, int postfix_len)
Set the postfix string for the network hostname.
Definition hostname.h:145
static int net_hostname_set_postfix(const uint8_t *hostname_postfix, int postfix_len)
Set the device hostname postfix.
Definition hostname.h:118
static const char * net_hostname_get(void)
Get the device hostname.
Definition hostname.h:64
static void net_hostname_init(void)
Initialize and set the device hostname.
Definition hostname.h:96
#define ENOTSUP
Unsupported value.
Definition errno.h:114
#define EMSGSIZE
Message size.
Definition errno.h:106
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Misc utilities.
Macros to abstract toolchain specific capabilities.