DhcpServer library for mbed-os.

Fork of DhcpServer by Daiki Kato

mbedボードをDHCPサーバとして使用するためのライブラリです。mbedボードとPCを直結する際などに使用してください。
このクラスは5つのIPアドレスを割り当てられることができます。
IPアドレスの上位3バイトはサーバーアドレスと同じで、下の1バイトは、10-14が割り当てられます。
例えば、サーバーアドレスが"192.168.0.1"の場合、IPアドレスは"192.168.0.10"~"192.168.0.14"が割り当てられます。

EthernetInterfaceでconnectを実行した後に、DhcpServerを使用してください。

    EthernetInterface eth;
    eth.init("192.168.0.1", "255.255.255.0", "192.168.0.1");
    eth.connect();
    DhcpServer dhcp_server(&eth, "HostName");


Library in Beta!

This library is in Beta.
このライブラリはβ版です。

Files at this revision

API Documentation at this revision

Comitter:
dkato
Date:
Thu Jun 21 10:37:18 2018 +0000
Parent:
3:bdea854c0ec8
Commit message:
Supports mbed-os 5.9.1

Changed in this revision

DhcpServer.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/DhcpServer.cpp	Fri Jun 23 11:44:52 2017 +0000
+++ b/DhcpServer.cpp	Thu Jun 21 10:37:18 2018 +0000
@@ -1,14 +1,38 @@
 #include "mbed.h"
 #include "rtos.h"
-#include "lwip/netif.h"
 #include "TCPSocket.h"
 #include "TCPServer.h"
 #include "SocketAddress.h"
 #include "UDPSocket.h"
-#include "prot/ip4.h"
-#include "prot/dhcp.h"
 #include "DhcpServer.h"
 
+ /* DHCP message item offsets and length */
+#define DHCP_SNAME_LEN    64U
+
+/* DHCP message types */
+#define DHCP_DISCOVER               1
+#define DHCP_OFFER                  2
+#define DHCP_REQUEST                3
+#define DHCP_DECLINE                4
+#define DHCP_ACK                    5
+#define DHCP_NAK                    6
+#define DHCP_RELEASE                7
+#define DHCP_INFORM                 8
+
+/* BootP options */
+#define DHCP_OPTION_SUBNET_MASK     1 /* RFC 2132 3.3 */
+#define DHCP_OPTION_ROUTER          3
+#define DHCP_OPTION_DNS_SERVER      6
+
+/* DHCP options */
+#define DHCP_OPTION_LEASE_TIME      51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
+
+#define DHCP_OPTION_MESSAGE_TYPE    53 /* RFC 2132 9.6, important for DHCP */
+#define DHCP_OPTION_MESSAGE_TYPE_LEN 1
+
+#define DHCP_OPTION_SERVER_ID       54 /* RFC 2132 9.7, server IP address */
+
+
 #define IP_ADDER_START (10)
 
 #define OFS_XID        (4)