diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-12 11:32:33 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-11-12 11:32:33 -0700 |
commit | a0386a75584842d01b312d8c6990857c85fb0d65 (patch) | |
tree | 94fe6a3a3fd491394137fde3cd9d84a276ba0fb1 | |
parent | 309b5776552282028908482badd9c45b82ecdaca (diff) |
libdhcp: Don't bother copying hostname
-rw-r--r-- | libdhcp/dhcp_client.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/libdhcp/dhcp_client.c b/libdhcp/dhcp_client.c index 3728e19..dad039c 100644 --- a/libdhcp/dhcp_client.c +++ b/libdhcp/dhcp_client.c @@ -132,7 +132,7 @@ struct dhcp_client { implements_net_iface *iface; implements_net_packet_conn *sock; struct net_eth_addr self_eth_addr; - char self_hostname[63]; + char *self_hostname; size_t self_id_len; void *self_id_dat; @@ -394,7 +394,6 @@ static bool dhcp_client_send(struct dhcp_client *client, uint8_t msgtyp, const c #define V_RAW(len, ptr) val = (typeof(val)){ len, ptr } #define V_OBJ(x) V_RAW(sizeof(x), &x) #define V_STR(x) V_RAW(x ? strlen(x) : 0, x) -#define V_STRN(x) V_RAW(strnlen(x, sizeof(x)), x) #define V_NONE() V_RAW(0, NULL) switch (opt) { /* For clarity, list all options mentioned in "Table 5: @@ -421,11 +420,10 @@ static bool dhcp_client_send(struct dhcp_client *client, uint8_t msgtyp, const c break; case DHCP_OPT_DHCP_MESSAGE: V_STR(errstr); break; /* "Site-specific" and "All others". */ - case DHCP_OPT_HOSTNAME: V_STRN(client->self_hostname); break; + case DHCP_OPT_HOSTNAME: V_STR(client->self_hostname); break; default: V_NONE(); }; #undef V_NONE -#undef V_STRN #undef V_STR #undef V_OBJ #undef V_RAW @@ -903,15 +901,13 @@ __attribute__((noreturn)) void dhcp_client_main(implements_net_iface *iface, .iface = iface, .sock = VCALL(iface, udp_conn, DHCP_PORT_CLIENT), .self_eth_addr = VCALL(iface, hwaddr), + .self_hostname = self_hostname, .self_id_len = sizeof(client_id), .self_id_dat = &client_id, /* Mutable. */ .state = STATE_INIT, }; - if (self_hostname) - strncpy(client.self_hostname, self_hostname, sizeof(client.self_hostname)); - assert(client.sock); struct dhcp_recv_msg scratch; |