Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Internet/DHCP/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ uint32_t DHCP_XID; // Any number

RIP_MSG* pDHCPMSG; // Buffer pointer for DHCP processing

uint8_t HOST_NAME[] = DCHP_HOST_NAME;
uint8_t HOST_NAME[DHCP_HOST_NAME_MAX_LEN + 1] = DHCP_HOST_NAME;

uint8_t DHCP_CHADDR[6]; // DHCP Client MAC address.

Expand Down Expand Up @@ -331,6 +331,14 @@ void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_co
}
}

void DHCP_set_hostname(const char* hostname) {
uint8_t i;
for (i = 0; i < DHCP_HOST_NAME_MAX_LEN && hostname[i] != 0; i++) {
HOST_NAME[i] = (uint8_t)hostname[i];
}
HOST_NAME[i] = 0;
}

/* make the common DHCP message */
void makeDHCPMSG(void) {
uint8_t bk_mac[6];
Expand Down
14 changes: 13 additions & 1 deletion Internet/DHCP/dhcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ extern "C" {

#define MAGIC_COOKIE 0x63825363 ///< You should not modify it number.

#define DCHP_HOST_NAME "WIZnet\0"
#define DHCP_HOST_NAME "WIZnet\0"

/* Maximum length (excluding null terminator) of a hostname set via @ref DHCP_set_hostname */
#define DHCP_HOST_NAME_MAX_LEN 32

/*
@brief return value of @ref DHCP_run()
Expand Down Expand Up @@ -108,6 +111,15 @@ void DHCP_time_handler(void);
*/
void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));

/*
@brief Set the hostname (DHCP option 12) sent with DISCOVER/REQUEST messages
@param hostname - null-terminated hostname string. Truncated to @ref DHCP_HOST_NAME_MAX_LEN
characters if longer. May be called at any time before/while DHCP is running;
takes effect on the next message sent.
@note If never called, defaults to @ref DHCP_HOST_NAME
*/
void DHCP_set_hostname(const char* hostname);

/*
@brief DHCP client in the main loop
@return The value is as the follow \n
Expand Down