Discussion:
[dev] [sdhcp] Part 1/3 Bugs
Sean MacLennan
2018-11-13 00:05:38 UTC
Permalink
I am surprised you are getting away with binding the socket to the
broadcast address. The other bug is just a simple compiler warning.

diff --git a/sdhcp.c b/sdhcp.c
index e2a641e..47cabf6 100644
--- a/sdhcp.c
+++ b/sdhcp.c
@@ -467,7 +467,7 @@ main(int argc, char *argv[])
if (argc)
ifname = argv[0]; /* interface name */
if (argc >= 2)
- strlcpy(cid, argv[1], sizeof(cid)); /* client-id */
+ strlcpy((char *)cid, argv[1], sizeof(cid)); /* client-id */

memset(&ifreq, 0, sizeof(ifreq));
signal(SIGALRM, nop);
@@ -482,7 +482,7 @@ main(int argc, char *argv[])
ioctl(sock, SIOCGIFINDEX, &ifreq);
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, &ifreq, sizeof ifreq) == -1)
eprintf("setsockopt:");
- iptoaddr(&addr, IP(255, 255, 255, 255), 68);
+ iptoaddr(&addr, IP(0, 0, 0, 0), 68);
if (bind(sock, (void*)&addr, sizeof addr) != 0)
eprintf("bind:");
ioctl(sock, SIOCGIFHWADDR, &ifreq);
Michael Forney
2018-11-15 01:13:15 UTC
Permalink
Post by Sean MacLennan
I am surprised you are getting away with binding the socket to the
broadcast address.
I found in ip(7):

INADDR_BROADCAST (255.255.255.255) means any host and has the same
effect on bind as INADDR_ANY for historical reasons.

So that explains why it worked.

BTW, is there going to be a part 3/3?
Sean MacLennan
2018-11-15 01:27:51 UTC
Permalink
On Wed, 14 Nov 2018 17:13:15 -0800
Post by Michael Forney
Post by Sean MacLennan
I am surprised you are getting away with binding the socket to the
broadcast address.
INADDR_BROADCAST (255.255.255.255) means any host and has the same
effect on bind as INADDR_ANY for historical reasons.
So that explains why it worked.
Interesting. I obviously hit a case where it doesn't, but that could
be a bug on my side.
Post by Michael Forney
BTW, is there going to be a part 3/3?
Part 3/3 relies heavily on part 1/3 being accepted ;)

Cheers,
Sean

Continue reading on narkive:
Loading...