- prepared for cheap request
git-svn-id: http://moon:8086/svn/mips@224 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
@@ -15,10 +15,11 @@
|
||||
|
||||
const char hostname[] = "ml402";
|
||||
const char vendor[] = "Jayfield Inc.";
|
||||
static uint32_t xid = 0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Testing
|
||||
void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_addr_src, uint8_t *inet_addr_src, uint8_t *inet_addr_dst, DHCP *pLast)
|
||||
void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_addr_src, uint8_t *inet_addr_src, uint8_t *inet_addr_dst)
|
||||
{
|
||||
DHCP dhcp;
|
||||
uint32_t size;
|
||||
@@ -57,9 +58,10 @@ void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_ad
|
||||
{
|
||||
case DHCP_MSG_DHCPDISCOVER:
|
||||
{
|
||||
pDHCP->xid = (uint32_t)rand();
|
||||
|
||||
// Request subnet mask
|
||||
xid = (uint32_t)rand();
|
||||
pDHCP->xid = xid;
|
||||
|
||||
// Request list
|
||||
size = 0;
|
||||
buffer[size++] = DHCP_OPT_SUBNETMASK;
|
||||
buffer[size++] = DHCP_OPT_ROUTER;
|
||||
@@ -74,10 +76,18 @@ void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_ad
|
||||
|
||||
case DHCP_MSG_DHCPREQUEST:
|
||||
{
|
||||
pDHCP->xid = pLast->xid;
|
||||
pDHCP->xid = xid;
|
||||
|
||||
// Set requested IP address
|
||||
option_list_append(&options, DHCP_OPT_REQIP, pLast->yiaddr, size);
|
||||
// Request list
|
||||
size = 0;
|
||||
buffer[size++] = DHCP_OPT_SUBNETMASK;
|
||||
buffer[size++] = DHCP_OPT_ROUTER;
|
||||
buffer[size++] = DHCP_OPT_DOMAIN_NS;
|
||||
buffer[size++] = 121;
|
||||
buffer[size++] = 249;
|
||||
buffer[size++] = 42;
|
||||
buffer[size++] = 158;
|
||||
option_list_append(&options, DHCP_OPT_PARAM_REQ_LIST, buffer, size);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ typedef struct _soption_list_t
|
||||
#define DHCP_MSG_DHCPRELEASE 7
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_addr_src, uint8_t *inet_addr_src, uint8_t *inet_addr_dst, DHCP *pLast);
|
||||
void DHCP_request_send(packet_t *pPacket, uint8_t dhcp_msg_type, uint8_t *mac_addr_src, uint8_t *inet_addr_src, uint8_t *inet_addr_dst);
|
||||
void option_list_init(option_list_t *pObj, void *pBuffer, size_t size);
|
||||
void option_list_append(option_list_t *pObj, uint8_t option_type, void const *pData, size_t size);
|
||||
size_t data_entry_create(void *pDst, uint8_t type, void const *pData, size_t size);
|
||||
|
||||
+13
-13
@@ -336,28 +336,28 @@ int main()
|
||||
DHCP *pDHCP;
|
||||
if (dhcp_state == 1)
|
||||
{
|
||||
for (int kk=0; kk < 1; kk++)
|
||||
{
|
||||
printf("---------------------------------------------------------------\n");
|
||||
printf("- Send DHCP Discover ------------------------------------------\n");
|
||||
printf("---------------------------------------------------------------\n");
|
||||
sleep(3000);
|
||||
Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst);
|
||||
DHCP_request_send(&packet, DHCP_MSG_DHCPDISCOVER, eth_myself, ip_zero, ip_bcast, NULL);
|
||||
PrintBuffer8((uint8_t*)packet.pkt_buf, 16, packet.size);
|
||||
Eth_pkt_send(&packet);
|
||||
}
|
||||
dhcp_state = 0;
|
||||
sleep(3000);
|
||||
printf("---------------------------------------------------------------\n");
|
||||
printf("- Send DHCP Discover ------------------------------------------\n");
|
||||
printf("---------------------------------------------------------------\n");
|
||||
Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst);
|
||||
DHCP_request_send(&packet, DHCP_MSG_DHCPDISCOVER, eth_myself, ip_zero, ip_bcast);
|
||||
PrintBuffer8((uint8_t*)packet.pkt_buf, 16, packet.size);
|
||||
Eth_pkt_send(&packet);
|
||||
dhcp_state = 2;
|
||||
}
|
||||
|
||||
if (dhcp_state == 2)
|
||||
{
|
||||
sleep(3000);
|
||||
printf("---------------------------------------------------------------\n");
|
||||
printf("- Send DHCP Request -------------------------------------------\n");
|
||||
printf("---------------------------------------------------------------\n");
|
||||
Eth_pkt_create(&packet, TYPE_PROTO_IP, eth_myself, eth_bcst);
|
||||
DHCP_request_send(&packet, DHCP_MSG_DHCPREQUEST, eth_myself, ip_zero, ip_bcast, pDHCP);
|
||||
DHCP_request_send(&packet, DHCP_MSG_DHCPREQUEST, eth_myself, ip_zero, ip_bcast);
|
||||
Eth_pkt_send(&packet);
|
||||
dhcp_state = 0;
|
||||
|
||||
}
|
||||
|
||||
if (dhcp_state == 3)
|
||||
|
||||
Reference in New Issue
Block a user