Hostname Configuration
Overview
A networked device might need a hostname, for example, if the device
is configured to be a mDNS responder (see DNS Resolve for
details) and needs to respond to <hostname>.local
DNS queries.
The CONFIG_NET_HOSTNAME_ENABLE
must be set in order
to store the hostname and enable the relevant APIs. If the option is enabled,
then the default hostname is set to be zephyr
by
CONFIG_NET_HOSTNAME
option.
If the same firmware image is used to flash multiple boards, then it is not
practical to use the same hostname in all of the boards. In that case, one
can enable CONFIG_NET_HOSTNAME_UNIQUE
which will add a unique
postfix to the hostname. By default the link local address of the first network
interface is used as a postfix. In Ethernet networks, the link local address
refers to MAC address. For example, if the link local address is
01:02:03:04:05:06
, then the unique hostname could be
zephyr010203040506
. If you want to set the prefix yourself, then call
net_hostname_set_postfix()
before the network interfaces are created.
For example for the Ethernet networks, the initialization priority is set by
CONFIG_ETH_INIT_PRIORITY
so you would need to set the postfix before
that. The postfix can be set only once.
API Reference
- group net_hostname
Network hostname configuration library.
Defines
-
NET_HOSTNAME_MAX_LEN
Functions
-
static inline const char *net_hostname_get(void)
Get the device hostname.
Return pointer to device hostname.
- Returns:
Pointer to hostname or NULL if not set.
-
static inline void net_hostname_init(void)
Initialize and set the device hostname.
-
static inline int net_hostname_set_postfix(const uint8_t *hostname_postfix, int postfix_len)
Set the device hostname postfix.
Set the device hostname to some value. This is only used if CONFIG_NET_HOSTNAME_UNIQUE is set.
- Parameters:
hostname_postfix – Usually link address. The function will convert this to a string.
postfix_len – Length of the hostname_postfix array.
- Returns:
0 if ok, <0 if error
-
NET_HOSTNAME_MAX_LEN