summaryrefslogtreecommitdiff
path: root/lib/networking/dhserver.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/networking/dhserver.c')
-rw-r--r--lib/networking/dhserver.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/networking/dhserver.c b/lib/networking/dhserver.c
index 590739236..2f14f7a09 100644
--- a/lib/networking/dhserver.c
+++ b/lib/networking/dhserver.c
@@ -2,17 +2,17 @@
* The MIT License (MIT)
*
* Copyright (c) 2015 by Sergey Fetisov <[email protected]>
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -86,7 +86,7 @@ typedef struct
uint8_t dp_giaddr[4]; /* gateway IP address */
uint8_t dp_chaddr[16]; /* client hardware address */
uint8_t dp_legacy[192];
- uint8_t dp_magic[4];
+ uint8_t dp_magic[4];
uint8_t dp_options[275]; /* options area */
} DHCP_TYPE;
@@ -240,7 +240,15 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
unsigned n = p->len;
if (n > sizeof(dhcp_data)) n = sizeof(dhcp_data);
memcpy(&dhcp_data, p->payload, n);
- switch (dhcp_data.dp_options[2])
+
+ ptr = find_dhcp_option(dhcp_data.dp_options, sizeof(dhcp_data.dp_options), DHCP_MESSAGETYPE);
+ if (ptr == NULL)
+ {
+ pbuf_free(p);
+ return;
+ }
+
+ switch (ptr[2])
{
case DHCP_DISCOVER:
entry = entry_by_mac(dhcp_data.dp_chaddr);
@@ -259,7 +267,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
DHCP_OFFER,
config->domain,
config->dns,
- entry->lease,
+ entry->lease,
*netif_ip4_addr(netif),
config->router,
*netif_ip4_netmask(netif));
@@ -301,7 +309,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
DHCP_ACK,
config->domain,
config->dns,
- entry->lease,
+ entry->lease,
*netif_ip4_addr(netif),
config->router,
*netif_ip4_netmask(netif));