sdhcp

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

commit 7780d06e8ee64392f8c852ae24cdf5ff8c11845a
parent 253bb65b9f029890469c3726c446daf34747bcba
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Fri, 25 Apr 2014 21:58:18 +0200

replace UDPWRAPPER macro with readable normal version

fix some compiler warnings aswell (signed/unsigned)

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Msdhcp.c | 31++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/sdhcp.c b/sdhcp.c @@ -122,16 +122,29 @@ iptoaddr(unsigned char ip[4], int port) return *(struct sockaddr*)&ifaddr; } -#define UDPWRAPPER(name, func, port, hack) \ -static int name(unsigned char ip[4], int fd, void *data, size_t n){\ - struct sockaddr addr = iptoaddr(ip, port);\ - int x, y = sizeof addr;\ - if((x=func(fd, data, n, 0, &addr, hack y))==-1)\ - die(#func);\ - return x;\ +/* sendto UDP wrapper */ +static ssize_t +udpsend(unsigned char ip[4], int fd, void *data, size_t n) { + struct sockaddr addr = iptoaddr(ip, 67); + socklen_t addrlen = sizeof addr; + ssize_t sent; + + if((sent = sendto(fd, data, n, 0, &addr, addrlen)) == -1) + eprintf("sendto:"); + return sent; +} + +/* recvfrom UDP wrapper */ +static ssize_t +udprecv(unsigned char ip[4], int fd, void *data, size_t n) { + struct sockaddr addr = iptoaddr(ip, 68); + socklen_t addrlen = sizeof addr; + ssize_t r; + + if((r = recvfrom(fd, data, n, 0, &addr, &addrlen)) == -1) + eprintf("recvfrom:"); + return r; } -UDPWRAPPER(udpsend, sendto, 67, ) -UDPWRAPPER(udprecv, recvfrom, 68, &) static void setip(unsigned char ip[4], unsigned char mask[4], unsigned char gateway[4])