I have attached a more complete diff. This diff has Linux raw sockets,
portability, and some bug fixes. I have also pushed the changes to
github and they can be found here:
https://github.com/smaclennan/sdhcp.
The diff is quite big, but not really that complicated. The main change
is moving all the low level socket calls to util/compat.c. And the bulk
of that is the raw udpsend() since you need to build all the headers.
So it looks large, but it is really just a lot of simple assignments.
IMHO this actually makes sdhcp.c slightly more readable (although it
was good before). sdhcp.c has no ifdefs and now really only deals with
the DHCP protocol and not socket details. Timers where also moved to
compat.c.
I have tested the code to work under three main environments:
1) Linux laptops. Just needed raw socket.
2) QNX. Just needed Linux specific code removed and MSG_DONTROUTE
flag when sending. This is my main use case for sdhcp.
3) My Linux router connecting to Rogers. For this I needed binary cid
support. I also found I had to send the params option or Rogers would
not send me the router (GW) address.
I have my dhcp server set for a 2 hour lease so the systems (except
Rogers) renew after an hour. I instrumented sdhcp so it logged that the
renews (and hence the timers) where working.
I kept the timerfd API for Linux... it just seems to work better. I use
timer_create and a set a wrapper functions for other OSes. I then wrote
a compat functions create_timers() that takes a recreate arg. I could
detect when it was a recreate, but I think explicitly setting the arg
makes it cleaner.
The code compiles under FreeBSD (you need -lrt), but doesn't work:
sendto fails with network unreachable. I am not a BSD guy, so I didn't
even try to fix it.
Note that I cheat for non-Linux systems. You must provide a -e script to
actually set the IP parameters. With some work this might not be needed,
but this is just so much easier.
Cheers,
Sean
- text/x-patch attachment: diff
Received on Sun Feb 10 2019 - 02:32:02 CET