diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-30 23:15:06 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-30 23:15:06 +0000 |
commit | 28e08c18929a9841cd36f6ba726048e10fe4168e (patch) | |
tree | c69e66f9d6b3bb7799e701ddcf2fc6f1b06c8f54 /nuttx/netutils/dhcpd/dhcpd.c | |
parent | f2475599fef8877dadbec64887131e5c7d99834b (diff) | |
download | px4-nuttx-28e08c18929a9841cd36f6ba726048e10fe4168e.tar.gz px4-nuttx-28e08c18929a9841cd36f6ba726048e10fe4168e.tar.bz2 px4-nuttx-28e08c18929a9841cd36f6ba726048e10fe4168e.zip |
Basic DHPC client functionality
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@419 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/netutils/dhcpd/dhcpd.c')
-rw-r--r-- | nuttx/netutils/dhcpd/dhcpd.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/nuttx/netutils/dhcpd/dhcpd.c b/nuttx/netutils/dhcpd/dhcpd.c index 331d945a9..f160dcc21 100644 --- a/nuttx/netutils/dhcpd/dhcpd.c +++ b/nuttx/netutils/dhcpd/dhcpd.c @@ -692,8 +692,8 @@ static inline int dhcpd_socket(void) int sockfd; #if defined(HAVE_SO_REUSEADDR) || defined(HAVE_SO_BROADCAST) int optval; -#endif int ret; +#endif /* Create a socket to listen for requests from DHCP clients */ @@ -815,6 +815,7 @@ static int dhcpd_sendpacket(int bbroadcast) struct sockaddr_in addr; in_addr_t ipaddr; int sockfd; + int len; int ret = ERROR; /* Determine which address to respond to (or if we need to broadcast the response) */ @@ -850,8 +851,10 @@ static int dhcpd_sendpacket(int bbroadcast) addr.sin_port = HTONS(DHCP_CLIENT_PORT); addr.sin_addr.s_addr = ipaddr; - ret = sendto(sockfd, - &g_state.ds_outpacket, sizeof(struct dhcpmsg_s), 0, + /* Send the minimum sized packet that includes the END option */ + + len = (g_state.ds_optend - (uint8*)&g_state.ds_outpacket) + 1; + ret = sendto(sockfd, &g_state.ds_outpacket, len, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); close(sockfd); } @@ -1031,9 +1034,8 @@ static inline int dhcpd_request(void) * already offered to the client. */ - if (g_state.ds_optserverip == g_state.ds_serverip && - g_state.ds_optreqip != 0 && - g_state.ds_optreqip == ipaddr) + if (g_state.ds_optserverip == ntohl(g_state.ds_serverip) && + (g_state.ds_optreqip != 0 || g_state.ds_optreqip == ipaddr)) { response = DHCPACK; } @@ -1278,6 +1280,12 @@ int dhcpd_run(void) continue; } +#ifdef CONFIG_NETUTILS_DHCPD_HOST + /* Get the poor little uC a change to get its recvfrom in place */ + + sleep(2); +#endif + /* Now process the incoming DHCP message by its message type */ switch (g_state.ds_optmsgtype) |