diff options
author | Stavros Passas <stavros.passas@movidius.com> | 2017-01-20 09:22:46 +0000 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-06-08 10:06:33 +0200 |
commit | 258534718910c903451f1fe2e8fe1197c224c8e7 (patch) | |
tree | 8940058ea0c6a816617b63b5872508e47ca2dd42 /cpukit/libnetworking/rtems/rtems_dhcp.c | |
parent | bsps/arm: Fix ARMv7-M interrupt suppport (diff) | |
download | rtems-258534718910c903451f1fe2e8fe1197c224c8e7.tar.bz2 |
network: Fix DHCP client protocol
Close #2877.
Diffstat (limited to 'cpukit/libnetworking/rtems/rtems_dhcp.c')
-rw-r--r-- | cpukit/libnetworking/rtems/rtems_dhcp.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/cpukit/libnetworking/rtems/rtems_dhcp.c b/cpukit/libnetworking/rtems/rtems_dhcp.c index fa7589071d..13c06bc732 100644 --- a/cpukit/libnetworking/rtems/rtems_dhcp.c +++ b/cpukit/libnetworking/rtems/rtems_dhcp.c @@ -760,7 +760,8 @@ dhcp_task (rtems_task_argument _sdl) /* * Send the Request. */ - error = bootpc_call ((struct bootp_packet *)&call, (struct bootp_packet *)&dhcp_req, procp); + error = bootpc_call ((struct bootp_packet *)&call, + (struct bootp_packet *)&dhcp_req, procp, NULL, 0); if (error) { rtems_bsdnet_semaphore_release (); printf ("DHCP call failed -- error %d", error); @@ -901,6 +902,7 @@ dhcp_init (int update_files) struct ifaddr *ifa; struct sockaddr_dl *sdl = NULL; struct proc *procp = NULL; + char expected_dhcp_payload[7]; clean_dns_entries(); @@ -957,15 +959,26 @@ dhcp_init (int update_files) return -1; } + /* * Build the DHCP Discover */ dhcp_discover_req (&call, sdl, &xid); /* + * Expect a DHCP offer as response to DHCP discover + */ + memcpy(expected_dhcp_payload, dhcp_magic_cookie, sizeof(dhcp_magic_cookie)); + expected_dhcp_payload[sizeof(dhcp_magic_cookie) ]=0x35; /* DHCP */ + expected_dhcp_payload[sizeof(dhcp_magic_cookie)+1]=0x01; /* Length : 1 */ + expected_dhcp_payload[sizeof(dhcp_magic_cookie)+2]=0x02; /* DHCP_OFFER */ + + /* * Send the Discover. */ - error = bootpc_call ((struct bootp_packet *)&call, (struct bootp_packet *)&reply, procp); + error = bootpc_call ((struct bootp_packet *)&call, + (struct bootp_packet *)&reply, procp, + expected_dhcp_payload, sizeof(expected_dhcp_payload)); if (error) { printf ("BOOTP call failed -- %s\n", strerror(error)); soclose (so); @@ -990,11 +1003,20 @@ dhcp_init (int update_files) } /* + * Expect a DHCP_ACK as response to the DHCP REQUEST + * No need to reinitialize the whole expected_dhcp_payload variable, + * header and first two bytes of the payload are filled from DHCP offer + */ + expected_dhcp_payload[sizeof(dhcp_magic_cookie)+2]=0x05; /* DHCP_ACK */ + + /* * Send a DHCP REQUEST */ dhcp_request_req (&call, &reply, sdl, true); - error = bootpc_call ((struct bootp_packet *)&call, (struct bootp_packet *)&reply, procp); + error = bootpc_call ((struct bootp_packet *)&call, + (struct bootp_packet *)&reply, procp, + expected_dhcp_payload, sizeof(expected_dhcp_payload)); if (error) { printf ("BOOTP call failed -- %s\n", strerror(error)); soclose (so); |