Skip to content

Commit d3963de

Browse files
Dave Van Wagnerbogdanm
authored andcommitted
Added methods to retrieve gateway and netmask from DHCP assignment
1 parent 53edc82 commit d3963de

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

libraries/net/eth/EthernetInterface/EthernetInterface.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ static struct netif lpcNetif;
3333

3434
static char mac_addr[19];
3535
static char ip_addr[17] = "\0";
36+
static char gateway[17] = "\0";
37+
static char networkmask[17] = "\0";
3638
static bool use_dhcp = false;
3739

3840
static Semaphore tcpip_inited(0);
@@ -52,6 +54,8 @@ static void netif_link_callback(struct netif *netif) {
5254
static void netif_status_callback(struct netif *netif) {
5355
if (netif_is_up(netif)) {
5456
strcpy(ip_addr, inet_ntoa(netif->ip_addr));
57+
strcpy(gateway, inet_ntoa(netif->gw));
58+
strcpy(networkmask, inet_ntoa(netif->netmask));
5559
netif_up.release();
5660
}
5761
}
@@ -142,3 +146,13 @@ char* EthernetInterface::getMACAddress() {
142146
char* EthernetInterface::getIPAddress() {
143147
return ip_addr;
144148
}
149+
150+
char* EthernetInterface::getGateway() {
151+
return gateway;
152+
}
153+
154+
char* EthernetInterface::getNetworkMask() {
155+
return networkmask;
156+
}
157+
158+

libraries/net/eth/EthernetInterface/EthernetInterface.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ class EthernetInterface {
6969
* \return a pointer to a string containing the IP address
7070
*/
7171
static char* getIPAddress();
72+
73+
/** Get the Gateway address of your Ethernet interface
74+
* \return a pointer to a string containing the Gateway address
75+
*/
76+
static char* getGateway();
77+
78+
/** Get the Network mask of your Ethernet interface
79+
* \return a pointer to a string containing the Network mask
80+
*/
81+
static char* getNetworkMask();
7282
};
7383

7484
#include "TCPSocketConnection.h"

0 commit comments

Comments
 (0)