summaryrefslogtreecommitdiff
path: root/libnet/src/libnet_build_dhcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnet/src/libnet_build_dhcp.c')
-rw-r--r--libnet/src/libnet_build_dhcp.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/libnet/src/libnet_build_dhcp.c b/libnet/src/libnet_build_dhcp.c
index d147958..7d3f172 100644
--- a/libnet/src/libnet_build_dhcp.c
+++ b/libnet/src/libnet_build_dhcp.c
@@ -43,7 +43,7 @@ libnet_ptag_t
libnet_build_dhcpv4(uint8_t opcode, uint8_t htype, uint8_t hlen,
uint8_t hopcount, uint32_t xid, uint16_t secs, uint16_t flags,
uint32_t cip, uint32_t yip, uint32_t sip, uint32_t gip, const uint8_t *chaddr,
-uint8_t *sname, const uint8_t *file, const uint8_t *payload, uint32_t payload_s,
+const char *sname, const char *file, const uint8_t *payload, uint32_t payload_s,
libnet_t *l, libnet_ptag_t ptag)
{
uint32_t n, h;
@@ -82,32 +82,21 @@ libnet_t *l, libnet_ptag_t ptag)
dhcp_hdr.dhcp_gip = htonl(gip);
if (chaddr)
- {
- strncpy((char *)dhcp_hdr.dhcp_chaddr, (const char *)chaddr, sizeof (dhcp_hdr.dhcp_chaddr) - 2);
- }
- else
{
- memset(dhcp_hdr.dhcp_chaddr, 0, sizeof (dhcp_hdr.dhcp_chaddr));
+ size_t n = sizeof (dhcp_hdr.dhcp_chaddr);
+ if (hlen < n)
+ n = hlen;
+ memcpy(dhcp_hdr.dhcp_chaddr, chaddr, n);
}
-
if (sname)
{
- strncpy((const char *)dhcp_hdr.dhcp_sname, (char *)sname, sizeof (dhcp_hdr.dhcp_sname) - 2);
- }
- else
- {
- memset(dhcp_hdr.dhcp_sname, 0, sizeof (dhcp_hdr.dhcp_sname));
+ strncpy(dhcp_hdr.dhcp_sname, sname, sizeof (dhcp_hdr.dhcp_sname) - 1);
}
-
if (file)
{
- strncpy(dhcp_hdr.dhcp_file, file, sizeof (dhcp_hdr.dhcp_file) - 2);
- }
- else
- {
- memset(dhcp_hdr.dhcp_file, 0, sizeof(dhcp_hdr.dhcp_file));
+ strncpy(dhcp_hdr.dhcp_file, file, sizeof (dhcp_hdr.dhcp_file) - 1);
}
- dhcp_hdr.dhcp_magic = htonl(DHCP_MAGIC); /* should this be tunable? */
+ dhcp_hdr.dhcp_magic = htonl(DHCP_MAGIC);
n = libnet_pblock_append(l, p, (uint8_t *)&dhcp_hdr, LIBNET_DHCPV4_H);
if (n == -1)
@@ -142,7 +131,7 @@ libnet_ptag_t
libnet_build_bootpv4(uint8_t opcode, uint8_t htype, uint8_t hlen,
uint8_t hopcount, uint32_t xid, uint16_t secs, uint16_t flags,
uint32_t cip, uint32_t yip, uint32_t sip, uint32_t gip, const uint8_t *chaddr,
-uint8_t *sname, const uint8_t *file, const uint8_t *payload, uint32_t payload_s,
+const char *sname, const char *file, const uint8_t *payload, uint32_t payload_s,
libnet_t *l, libnet_ptag_t ptag)
{
return (libnet_build_dhcpv4(opcode, htype, hlen, hopcount, xid, secs,
@@ -150,4 +139,4 @@ libnet_t *l, libnet_ptag_t ptag)
l, ptag));
}
-/* EOF */ \ No newline at end of file
+/* EOF */