sdhcp

simple dhcp client
git clone git://git.2f30.org/sdhcp
Log | Files | Refs | LICENSE

commit a3a3e615d0e66b388b436196863095aede5c9dbe
parent 5ad98876ed3e0d8024c8e65174a675bd35ce058e
Author: sin <sin@2f30.org>
Date:   Wed, 13 Jan 2016 19:34:17 +0000

client id is always fixed at 16 bytes

Diffstat:
Msdhcp.c | 15+++++----------
1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/sdhcp.c b/sdhcp.c @@ -87,7 +87,6 @@ static unsigned char hwaddr[16]; static time_t starttime; static char *ifname = "eth0"; static unsigned char cid[16]; -static size_t cidlen; static char *program = ""; static int sock; /* sav */ @@ -275,7 +274,7 @@ dhcpsend(int type, int how) memcpy(bp.chaddr, hwaddr, sizeof bp.chaddr); p = bp.optdata; p = hnoptput(p, ODtype, type, 1); - p = optput(p, ODclientid, cid, cidlen); + p = optput(p, ODclientid, cid, sizeof(cid)); switch(type) { case DHCPdiscover: @@ -466,12 +465,8 @@ main(int argc, char *argv[]) if (argc) ifname = argv[0]; /* interface name */ - if (argc >= 2) { - cidlen = strlen(argv[1]); - if (cidlen > sizeof(cid)) - cidlen = sizeof(cid); - strlcpy(cid, argv[1], cidlen); /* client-id */ - } + if (argc >= 2) + strlcpy(cid, argv[1], sizeof(cid)); /* client-id */ memset(&ifreq, 0, sizeof(ifreq)); signal(SIGALRM, nop); @@ -491,8 +486,8 @@ main(int argc, char *argv[]) eprintf("bind:"); ioctl(sock, SIOCGIFHWADDR, &ifreq); memcpy(hwaddr, ifreq.ifr_hwaddr.sa_data, sizeof ifreq.ifr_hwaddr.sa_data); - if (!cidlen) - memcpy(cid, hwaddr, cidlen = sizeof(hwaddr)); + if (!cid[0]) + memcpy(cid, hwaddr, sizeof(cid)); if ((rnd = open("/dev/urandom", O_RDONLY)) == -1) eprintf("can't open /dev/urandom to generate unique transaction identifier:");