1 /** @file 2 * @brief Hostname configuration definitions 3 */ 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 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 /** 19 * @brief Network hostname configuration library 20 * @defgroup net_hostname Network Hostname Library 21 * @ingroup networking 22 * @{ 23 */ 24 25 #define NET_HOSTNAME_MAX_LEN \ 26 (sizeof(CONFIG_NET_HOSTNAME) - 1 + \ 27 (IS_ENABLED(CONFIG_NET_HOSTNAME_UNIQUE) ? \ 28 sizeof("0011223344556677") - 1 : 0)) 29 30 /** 31 * @brief Get the device hostname 32 * 33 * @details Return pointer to device hostname. 34 * 35 * @return Pointer to hostname or NULL if not set. 36 */ 37 #if defined(CONFIG_NET_HOSTNAME_ENABLE) 38 const char *net_hostname_get(void); 39 #else 40 static inline const char *net_hostname_get(void) 41 { 42 return "zephyr"; 43 } 44 #endif /* CONFIG_NET_HOSTNAME_ENABLE */ 45 46 /** 47 * @brief Initialize and set the device hostname. 48 * 49 */ 50 #if defined(CONFIG_NET_HOSTNAME_ENABLE) 51 void net_hostname_init(void); 52 #else net_hostname_init(void)53static inline void net_hostname_init(void) 54 { 55 } 56 #endif /* CONFIG_NET_HOSTNAME_ENABLE */ 57 58 /** 59 * @brief Set the device hostname postfix 60 * 61 * @details Set the device hostname to some value. This is only used if 62 * CONFIG_NET_HOSTNAME_UNIQUE is set. 63 * 64 * @param hostname_postfix Usually link address. The function will convert this 65 * to a string. 66 * @param postfix_len Length of the hostname_postfix array. 67 * 68 * @return 0 if ok, <0 if error 69 */ 70 #if defined(CONFIG_NET_HOSTNAME_UNIQUE) 71 int net_hostname_set_postfix(const uint8_t *hostname_postfix, 72 int postfix_len); 73 #else net_hostname_set_postfix(const uint8_t * hostname_postfix,int postfix_len)74static inline int net_hostname_set_postfix(const uint8_t *hostname_postfix, 75 int postfix_len) 76 { 77 return -EMSGSIZE; 78 } 79 #endif /* CONFIG_NET_HOSTNAME_UNIQUE */ 80 81 /** 82 * @} 83 */ 84 85 #ifdef __cplusplus 86 } 87 #endif 88 89 #endif /* ZEPHYR_INCLUDE_NET_HOSTNAME_H_ */ 90