forked from Imagelibrary/rtems
committed by
Sebastian Huber
parent
ce3ac00cfc
commit
2585347189
@@ -284,7 +284,9 @@ int
|
||||
bootpc_call(
|
||||
struct bootp_packet *call,
|
||||
struct bootp_packet *reply, /* output */
|
||||
struct proc *procp)
|
||||
struct proc *procp,
|
||||
const void *exp_vend,
|
||||
size_t exp_vend_len)
|
||||
{
|
||||
struct socket *so;
|
||||
struct sockaddr_in *sin;
|
||||
@@ -450,6 +452,9 @@ bootpc_call(
|
||||
if (bcmp(reply->chaddr,call->chaddr,call->hlen))
|
||||
continue;
|
||||
|
||||
if (exp_vend_len > 0 && bcmp(exp_vend, reply->vend, exp_vend_len))
|
||||
continue;
|
||||
|
||||
goto gotreply; /* break two levels */
|
||||
|
||||
} /* while secs */
|
||||
@@ -1051,7 +1056,7 @@ bootpc_init(bool update_files, bool forever)
|
||||
call.secs = 0;
|
||||
call.flags = htons(0x8000); /* We need an broadcast answer */
|
||||
|
||||
error = bootpc_call(&call,&reply,procp);
|
||||
error = bootpc_call(&call,&reply,procp, NULL, 0);
|
||||
|
||||
if (!error)
|
||||
break;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#if !defined (__RTEMS_BOOTP_H__)
|
||||
#define __RTEMS_BOOTP_H__
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#if __cplusplus
|
||||
@@ -21,7 +22,9 @@ bool bootpc_init(bool, bool);
|
||||
int bootpc_call(
|
||||
struct bootp_packet *call,
|
||||
struct bootp_packet *reply,
|
||||
struct proc *procp);
|
||||
struct proc *procp,
|
||||
const void *exp_vend,
|
||||
size_t exp_vend_len);
|
||||
int bootpc_fakeup_interface(struct ifreq *ireq,
|
||||
struct socket *so,
|
||||
struct proc *procp);
|
||||
|
||||
@@ -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);
|
||||
@@ -989,12 +1002,21 @@ dhcp_init (int update_files)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
Reference in New Issue
Block a user