samueldotj / dhcp-client Goto Github PK
View Code? Open in Web Editor NEWA simple DHCP client
A simple DHCP client
Hi,How do I get the client to send something other than a broadcast packet
On running make on OS X Yosemite, I see the error dump below
dhcp-client.c:153:36: error: incomplete definition of type 'struct sockaddr_dl'
memcpy((void *)mac, sdp->sdl_data + sdp->sdl_nlen, 6);
~~~^
/usr/include/secure/_string.h:65:33: note: expanded from macro 'memcpy'
__builtin___memcpy_chk (dest, src, len, __darwin_obsz0 (dest))
^~~
dhcp-client.c:150:20: note: forward declaration of 'struct sockaddr_dl'
struct sockaddr_dl* sdp;
^
dhcp-client.c:153:52: error: incomplete definition of type 'struct sockaddr_dl'
memcpy((void *)mac, sdp->sdl_data + sdp->sdl_nlen, 6);
~~~^
/usr/include/secure/_string.h:65:33: note: expanded from macro 'memcpy'
__builtin___memcpy_chk (dest, src, len, __darwin_obsz0 (dest))
^~~
dhcp-client.c:150:20: note: forward declaration of 'struct sockaddr_dl'
struct sockaddr_dl* sdp;
^
dhcp-client.c:286:24: warning: implicit conversion from '__uint32_t' (aka 'unsigned int') to 'u_short' (aka 'unsigned short')
changes value from 4294901760 to 0 [-Wconstant-conversion]
ip_header->ip_id = htonl(0xffff);
~ ^~~~~~~~~~~~~
/usr/include/sys/_endian.h:136:18: note: expanded from macro 'htonl'
#define htonl(x) __DARWIN_OSSwapInt32(x)
^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/libkern/_OSByteOrder.h:75:32: note: expanded from macro '__DARWIN_OSSwapInt32'
(__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt32(x) : _OSSwapInt32(x))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/libkern/_OSByteOrder.h:48:6: note: expanded from macro '__DARWIN_OSSwapConstInt32'
((__uint32_t)((((__uint32_t)(x) & 0xff000000) >> 24) | \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dhcp-client.c:387:18: warning: passing 'char [4096]' to parameter of type 'u_char *' (aka 'unsigned char *') converts between
pointers to integer types with different sign [-Wpointer-sign]
ether_output(packet, mac, len);
^~~~~~
dhcp-client.c:256:22: note: passing argument to parameter 'frame' here
ether_output(u_char *frame, u_int8_t *mac, int len)
^
2 warnings and 2 errors generated.
make: *** [dhcp-client] Error 1
Currently, the client does discovery & then wait for the offer from the server. My Openwrt router shows following lines when I launch the client
Sun Oct 9 05:04:08 2016 daemon.info dnsmasq-dhcp[1828]: DHCPDISCOVER(br-lan) 192.168.1.10 02:f6:01:6f:ca:95
Sun Oct 9 05:04:08 2016 daemon.info dnsmasq-dhcp[1828]: DHCPOFFER(br-lan) 192.168.7.113 02:f6:01:6f:ca:95
I am working on writing a network client that does DHCP to the server. When an actual network client connects, I see the following logs on the router
Sun Oct 9 05:03:16 2016 daemon.info dnsmasq-dhcp[1828]: DHCPREQUEST(br-lan) 192.168.7.173 dc:41:5f:9d:76:49
Sun Oct 9 05:03:16 2016 daemon.info dnsmasq-dhcp[1828]: DHCPACK(br-lan) 192.168.7.173 dc:41:5f:9d:76:49 M1036381siPhone
Can you pass me some reference material so that I can modify the source for the above sequence to be followed when the client spawns rather discovery & offer. I think that way, this client would be close to an actual dhcp client.
Hi,
I think there is an error in dhcp_input function.
It should be
if (dhcp->opcode != DHCP_OPTION_OFFER) -> if (dhcp->opcode != DHCP_BOOTREPLY)
And there are some defines error.
#define DHCP_OPTION_DECLINE 4
#define DHCP_OPTION_PACK 4->5
Anyway, thank you for your sharing, it helps me to understand DHCP behavior :)
Thanks,
g548462
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.