I found a couple of bugs in sdhcp... both having to do with renewal. If you are having problems renewing your lease or find that your IP keeps changing... read on.
The first problem is that sdhcp assumes the renew and rebind times will be set. These fields are optional, only the lease time is required. So you may end up never timing out until the lease expires. This can cause you to lose your IP depending on the server. Because the optget() is a relatively expensive call, it is actually cheaper to calculate the times every time. I have attached a patch that does this. The second problem is the server IP. sdhcp assumes that the server id (ODserverid) is the IP of the server. This is not always the case. It seems that the only safe IP is the address from the recvfrom(). Currently sdhcp ignores this value, but it should set server IP to this. I don't have a patch for this since the suckless sdhcp and my sdhcp have diverged a lot here. If you ask nicely I might roll up a patch. All the ODserverid code should be safe to remove. Cheers, Sean
diff --git a/sdhcp.c b/sdhcp.c index 1fcf5e6..21e6372 100644 --- a/sdhcp.c +++ b/sdhcp.c @@ -434,12 +434,13 @@ Bound: optget(&bp, mask, OBmask, sizeof(mask)); optget(&bp, router, OBrouter, sizeof(router)); optget(&bp, dns, OBdnsserver, sizeof(dns)); - optget(&bp, &renewaltime, ODrenewaltime, sizeof(renewaltime)); - optget(&bp, &rebindingtime, ODrebindingtime, sizeof(rebindingtime)); optget(&bp, &lease, ODlease, sizeof(lease)); - renewaltime = ntohl(renewaltime); - rebindingtime = ntohl(rebindingtime); lease = ntohl(lease); + /* Renew and rebind times are optional. It is faster to just + * calculate the times. Assumes: lease > 4s and < ~20 years. + */ + renewaltime = lease / 2; + rebindingtime = lease * 7 / 8; acceptlease(); fputs("Congrats! You should be on the 'net.\n", stdout); if (!fflag && !forked) {