diff --git a/CHANGELOG b/CHANGELOG index edac6dbf..8129fd6a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,13 @@ HISTORY ++ New features: + 2007-03-28 Frédéric Bernon + * opt.h, netif.h, dhcp.h, dhcp.c: New configuration option LWIP_NETIF_HOSTNAME allow to + define a hostname in netif struct (this is just a pointer, so, you can use a hardcoded + string, point on one of your's ethernetif field, or alloc a string you will free yourself). + It will be used by DHCP to register a client hostname, but can also be use when you call + snmp_set_sysname. + 2007-03-28 Frédéric Bernon * netif.h, netif.c: A new NETIF_FLAG_ETHARP flag is defined in netif.h, to allow to initialize a network interface's flag with. It tell this interface is an ethernet diff --git a/src/core/dhcp.c b/src/core/dhcp.c index 0f508f60..02953be1 100644 --- a/src/core/dhcp.c +++ b/src/core/dhcp.c @@ -217,6 +217,10 @@ static err_t dhcp_select(struct netif *netif) struct dhcp *dhcp = netif->dhcp; err_t result; u16_t msecs; +#if LWIP_NETIF_HOSTNAME + const char *p; +#endif /* LWIP_NETIF_HOSTNAME */ + LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_select(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num)); /* create and initialize the DHCP message header */ @@ -242,6 +246,16 @@ static err_t dhcp_select(struct netif *netif) dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST); dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER); +#if LWIP_NETIF_HOSTNAME + p = ( const char *)netif->hostname; + if (p!=NULL) { + dhcp_option(dhcp, DHCP_OPTION_HOSTNAME, strlen(p)); + while(*p) { + dhcp_option_byte(dhcp, *p++); + } + } +#endif /* LWIP_NETIF_HOSTNAME */ + dhcp_option_trailer(dhcp); /* shrink the pbuf to the actual content length */ pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); diff --git a/src/include/lwip/dhcp.h b/src/include/lwip/dhcp.h index bfe753f2..2cd1167a 100644 --- a/src/include/lwip/dhcp.h +++ b/src/include/lwip/dhcp.h @@ -210,6 +210,7 @@ void dhcp_fine_tmr(void); #define DHCP_OPTION_T1 58 /* T1 renewal time */ #define DHCP_OPTION_T2 59 /* T2 rebinding time */ +#define DHCP_OPTION_US 60 #define DHCP_OPTION_CLIENT_ID 61 #define DHCP_OPTION_TFTP_SERVERNAME 66 #define DHCP_OPTION_BOOTFILE 67 diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 776e5345..595b61aa 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -104,6 +104,10 @@ struct netif { /** the DHCP client state information for this netif */ struct dhcp *dhcp; #endif /* LWIP_DHCP */ +#if LWIP_NETIF_HOSTNAME + /* the hostname for this netif, NULL is a valid value */ + char* hostname; +#endif /* LWIP_NETIF_HOSTNAME */ /** number of bytes used in hwaddr */ u8_t hwaddr_len; /** link level hardware address of this interface */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index aa9ff5dc..804a9027 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -383,6 +383,13 @@ a lot of data that needs to be copied, this should be set high. */ #define TCP_SNDLOWAT TCP_SND_BUF/2 #endif + +/* ---- Network Interfaces options ---- */ +/* 1 if you want to use DHCP_OPTION_HOSTNAME with netif's hostname field */ +#ifndef LWIP_NETIF_HOSTNAME +#define LWIP_NETIF_HOSTNAME 0 +#endif + /* Support network interface callbacks */ #ifndef LWIP_NETIF_CALLBACK #define LWIP_NETIF_CALLBACK 0 @@ -401,6 +408,8 @@ a lot of data that needs to be copied, this should be set high. */ #define LWIP_CALLBACK_API 0 #endif + +/* ---------- Thread options ---------- */ #ifndef TCPIP_THREAD_PRIO #define TCPIP_THREAD_PRIO 1 #endif @@ -418,7 +427,7 @@ a lot of data that needs to be copied, this should be set high. */ #endif -/* ---------- Socket Options ---------- */ +/* ---------- Socket options ---------- */ /* Enable BSD-style sockets functions names */ #ifndef LWIP_COMPAT_SOCKETS #define LWIP_COMPAT_SOCKETS 1