From 446c058fa644dee0631413a544f319b0f7e27cb0 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Sun, 23 Feb 2020 09:44:40 -0800 Subject: [PATCH] net: rename net.if.info to net.ifinfo (#3033) Reserved words are always reserved in Lua, so let's not have people typing net["if"]... --- app/modules/net.c | 10 ++----- docs/modules/net.md | 72 ++++++++++++++++++++++----------------------- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/app/modules/net.c b/app/modules/net.c index d8678ec9..4565f53d 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -1008,12 +1008,12 @@ field_from_ipaddr(lua_State *L, const char * field_name, ip_addr_t* addr) { lua_setfield(L, -2, field_name); } -static int net_if_info( lua_State* L ) { +static int net_ifinfo( lua_State* L ) { int ifidx = luaL_optint(L, 1, 0); struct netif * nif = eagle_lwip_getif(ifidx); if (nif == NULL) { - return luaL_error( L, "unknown network interface index %d", ifidx); + return 0; } lua_createtable(L, 0, @@ -1088,18 +1088,14 @@ LROT_BEGIN(net_dns) LROT_FUNCENTRY( resolve, net_dns_static ) LROT_END( net_dns, net_dns, 0 ) -LROT_BEGIN(net_if) - LROT_FUNCENTRY( info, net_if_info ) -LROT_END(net_if, net_if, 0) - LROT_BEGIN(net) LROT_FUNCENTRY( createServer, net_createServer ) LROT_FUNCENTRY( createConnection, net_createConnection ) LROT_FUNCENTRY( createUDPSocket, net_createUDPSocket ) + LROT_FUNCENTRY( ifinfo, net_ifinfo ) LROT_FUNCENTRY( multicastJoin, net_multicastJoin ) LROT_FUNCENTRY( multicastLeave, net_multicastLeave ) LROT_TABENTRY( dns, net_dns ) - LROT_TABENTRY( if, net_if ) #ifdef TLS_MODULE_PRESENT LROT_TABENTRY( cert, tls_cert ) #endif diff --git a/docs/modules/net.md b/docs/modules/net.md index 7f6b70e4..d15cec42 100644 --- a/docs/modules/net.md +++ b/docs/modules/net.md @@ -83,6 +83,41 @@ none #### See also [`net.createConnection()`](#netcreateconnection) +## net.ifinfo() + +Return information about a network interface, specified by index. + +#### Syntax +`net.ifinfo(if_index)` + +#### Parameters +- `if_index` the interface index; on ESP8266, `0` is the wifi client (STA) and `1` + is the wifi AP. + +#### Returns +`nil` if the given `if_index` does not correspond to an interface. Otherwise, +a table containing ... + +* `ip`, `netmask`, and `gateway` configured for this interface, as dotted quad strings + or `nil` if none is set. + +* if DHCP was used to configure the interface, then `dhcp` will be a table containing... + + * `server_ip` -- the DHCP server itself, as a dotted quad + + * `client_ip` -- the IP address suggested for the client; likely, this equals `ip` + above, unless the configuration has been overridden. + + * `ntp_server` -- the NTP server suggested by the DHCP server. + +DNS servers are not tracked per-interface in LwIP and, as such, are not +reported here; use [`net.dns:getdnsserver()`](#netdnsgetdnsserver). + +#### Example + +`print(net.ifinfo(0).dhcp.ntp_server)` will show the NTP server suggested by +the DHCP server. + ## net.multicastJoin() Join multicast group. @@ -618,43 +653,6 @@ Sets the IP of the DNS server used to resolve hostnames. Default: resolver1.open #### See also [`net.dns:getdnsserver()`](#netdnsgetdnsserver) -# net.if Module - -## net.if.info() - -Return information about a network interface, specified by index. - -#### Syntax -`net.if.info(if_index)` - -#### Parameters -- `if_index` the interface index; on ESP8266, `0` is the wifi client (STA) and `1` - is the wifi AP. - -#### Returns -`nil` if the given `if_index` does not correspond to an interface. Otherwise, -a table containing ... - -* `ip`, `netmask`, and `gateway` configured for this interface, as dotted quad strings - or `nil` if none is set. - -* if DHCP was used to configure the interface, then `dhcp` will be a table containing... - - * `server_ip` -- the DHCP server itself, as a dotted quad - - * `client_ip` -- the IP address suggested for the client; likely, this equals `ip` - above, unless the configuration has been overridden. - - * `ntp_server` -- the NTP server suggested by the DHCP server. - -DNS servers are not tracked per-interface in LwIP and, as such, are not -reported here; use [`net.dns:getdnsserver()`](#netdnsgetdnsserver). - -#### Example - -`print(net.if.info(0).dhcp.ntp_server)` will show the NTP server suggested by -the DHCP server. - # net.cert Module This part gone to the [TLS](tls.md) module, link kept for backward compatibility.