Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
4c1d46c7
Commit
4c1d46c7
authored
Jun 21, 2019
by
devsaurus
Browse files
fix compile warnings for ipaddr_aton
parent
5f3c05bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
components/modules/wifi_ap.c
View file @
4c1d46c7
...
@@ -125,72 +125,77 @@ void wifi_ap_init (void)
...
@@ -125,72 +125,77 @@ void wifi_ap_init (void)
static
int
wifi_ap_setip
(
lua_State
*
L
)
static
int
wifi_ap_setip
(
lua_State
*
L
)
{
{
tcpip_adapter_ip_info_t
ipInfo
;
tcpip_adapter_ip_info_t
ipInfo
;
ip_addr_t
dns
;
ip_addr_t
dns
;
uint8_t
opt
;
uint8_t
opt
;
size_t
len
;
size_t
len
;
const
char
*
str
;
const
char
*
str
;
luaL_checkanytable
(
L
,
1
);
ip_addr_t
ipAddr
;
ipAddr
.
type
=
IPADDR_TYPE_V4
;
//memset(&ipInfo, 0, sizeof(tcpip_adapter_ip_info_t));
luaL_checkanytable
(
L
,
1
);
lua_getfield
(
L
,
1
,
"ip"
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
//memset(&ipInfo, 0, sizeof(tcpip_adapter_ip_info_t));
if
(
!
ipaddr_aton
(
str
,
&
ipInfo
.
ip
))
{
lua_getfield
(
L
,
1
,
"ip"
);
return
luaL_error
(
L
,
"Could not parse IP address, aborting"
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
}
if
(
!
ipaddr_aton
(
str
,
&
ipAddr
))
{
lua_getfield
(
L
,
1
,
"gateway"
);
return
luaL_error
(
L
,
"Could not parse IP address, aborting"
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
}
if
(
!
ipaddr_aton
(
str
,
&
ipInfo
.
gw
))
ipInfo
.
ip
=
ipAddr
.
u_addr
.
ip4
;
{
return
luaL_error
(
L
,
"Could not parse Gateway address, aborting"
);
lua_getfield
(
L
,
1
,
"gateway"
);
}
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
if
(
!
ipaddr_aton
(
str
,
&
ipAddr
))
lua_getfield
(
L
,
1
,
"netmask"
);
{
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
return
luaL_error
(
L
,
"Could not parse Gateway address, aborting"
);
if
(
!
ipaddr_aton
(
str
,
&
ipInfo
.
netmask
))
}
{
ipInfo
.
gw
=
ipAddr
.
u_addr
.
ip4
;
return
luaL_error
(
L
,
"Could not parse Netmask, aborting"
);
}
lua_getfield
(
L
,
1
,
"netmask"
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
ESP_ERROR_CHECK
(
tcpip_adapter_dhcps_stop
(
TCPIP_ADAPTER_IF_AP
));
if
(
!
ipaddr_aton
(
str
,
&
ipAddr
))
{
tcpip_adapter_set_ip_info
(
TCPIP_ADAPTER_IF_AP
,
&
ipInfo
);
return
luaL_error
(
L
,
"Could not parse Netmask, aborting"
);
}
lua_getfield
(
L
,
1
,
"dns"
);
ipInfo
.
netmask
=
ipAddr
.
u_addr
.
ip4
;
str
=
luaL_optlstring
(
L
,
-
1
,
""
,
&
len
);
if
(
ipaddr_aton
(
str
,
&
dns
))
ESP_ERROR_CHECK
(
tcpip_adapter_dhcps_stop
(
TCPIP_ADAPTER_IF_AP
));
{
tcpip_adapter_set_ip_info
(
TCPIP_ADAPTER_IF_AP
,
&
ipInfo
);
opt
=
1
;
dhcps_dns_setserver
(
&
dns
);
lua_getfield
(
L
,
1
,
"dns"
);
tcpip_adapter_dhcps_option
(
TCPIP_ADAPTER_OP_SET
,
DOMAIN_NAME_SERVER
,
&
opt
,
sizeof
(
opt
));
str
=
luaL_optlstring
(
L
,
-
1
,
""
,
&
len
);
if
(
ipaddr_aton
(
str
,
&
dns
))
}
{
ESP_ERROR_CHECK
(
tcpip_adapter_dhcps_start
(
TCPIP_ADAPTER_IF_AP
));
opt
=
1
;
dhcps_dns_setserver
(
&
dns
);
return
0
;
tcpip_adapter_dhcps_option
(
TCPIP_ADAPTER_OP_SET
,
DOMAIN_NAME_SERVER
,
&
opt
,
sizeof
(
opt
));
}
ESP_ERROR_CHECK
(
tcpip_adapter_dhcps_start
(
TCPIP_ADAPTER_IF_AP
));
return
0
;
}
}
static
int
wifi_ap_sethostname
(
lua_State
*
L
)
static
int
wifi_ap_sethostname
(
lua_State
*
L
)
{
{
size_t
l
;
size_t
l
;
esp_err_t
err
;
esp_err_t
err
;
const
char
*
hostname
=
luaL_checklstring
(
L
,
1
,
&
l
);
const
char
*
hostname
=
luaL_checklstring
(
L
,
1
,
&
l
);
err
=
tcpip_adapter_set_hostname
(
TCPIP_ADAPTER_IF_AP
,
hostname
);
err
=
tcpip_adapter_set_hostname
(
TCPIP_ADAPTER_IF_AP
,
hostname
);
if
(
err
!=
ESP_OK
)
if
(
err
!=
ESP_OK
)
return
luaL_error
(
L
,
"failed to set hostname, code %d"
,
err
);
return
luaL_error
(
L
,
"failed to set hostname, code %d"
,
err
);
lua_pushboolean
(
L
,
err
==
ESP_OK
);
lua_pushboolean
(
L
,
err
==
ESP_OK
);
return
1
;
return
1
;
}
}
static
int
wifi_ap_config
(
lua_State
*
L
)
static
int
wifi_ap_config
(
lua_State
*
L
)
...
...
components/modules/wifi_sta.c
View file @
4c1d46c7
...
@@ -165,65 +165,70 @@ static void do_connect (const system_event_t *evt)
...
@@ -165,65 +165,70 @@ static void do_connect (const system_event_t *evt)
// --- Lua API functions ----------------------------------------------------
// --- Lua API functions ----------------------------------------------------
static
int
wifi_sta_setip
(
lua_State
*
L
)
static
int
wifi_sta_setip
(
lua_State
*
L
)
{
{
tcpip_adapter_ip_info_t
ipInfo
;
tcpip_adapter_ip_info_t
ipInfo
;
tcpip_adapter_dns_info_t
dnsinfo
;
tcpip_adapter_dns_info_t
dnsinfo
;
size_t
len
;
size_t
len
;
const
char
*
str
;
const
char
*
str
;
luaL_checkanytable
(
L
,
1
);
ip_addr_t
ipAddr
;
ipAddr
.
type
=
IPADDR_TYPE_V4
;
luaL_checkanytable
(
L
,
1
);
//memset(&ipInfo, 0, sizeof(tcpip_adapter_ip_info_t));
//memset(&ipInfo, 0, sizeof(tcpip_adapter_ip_info_t));
lua_getfield
(
L
,
1
,
"ip"
);
lua_getfield
(
L
,
1
,
"ip"
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
if
(
!
ipaddr_aton
(
str
,
&
ipInfo
.
ip
))
if
(
!
ipaddr_aton
(
str
,
&
ipAddr
))
{
{
return
luaL_error
(
L
,
"Could not parse IP address, aborting"
);
return
luaL_error
(
L
,
"Could not parse IP address, aborting"
);
}
}
ipInfo
.
ip
=
ipAddr
.
u_addr
.
ip4
;
lua_getfield
(
L
,
1
,
"netmask"
);
lua_getfield
(
L
,
1
,
"netmask"
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
if
(
!
ipaddr_aton
(
str
,
&
ipInfo
.
netmask
))
if
(
!
ipaddr_aton
(
str
,
&
ipAddr
))
{
{
return
luaL_error
(
L
,
"Could not parse Netmask, aborting"
);
return
luaL_error
(
L
,
"Could not parse Netmask, aborting"
);
}
}
ipInfo
.
netmask
=
ipAddr
.
u_addr
.
ip4
;
lua_getfield
(
L
,
1
,
"gateway"
);
lua_getfield
(
L
,
1
,
"gateway"
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
str
=
luaL_checklstring
(
L
,
-
1
,
&
len
);
if
(
!
ipaddr_aton
(
str
,
&
ipInfo
.
gw
))
if
(
!
ipaddr_aton
(
str
,
&
ipAddr
))
{
{
return
luaL_error
(
L
,
"Could not parse Gateway address, aborting"
);
return
luaL_error
(
L
,
"Could not parse Gateway address, aborting"
);
}
}
ipInfo
.
gw
=
ipAddr
.
u_addr
.
ip4
;
lua_getfield
(
L
,
1
,
"dns"
);
lua_getfield
(
L
,
1
,
"dns"
);
str
=
luaL_optlstring
(
L
,
-
1
,
str
,
&
len
);
str
=
luaL_optlstring
(
L
,
-
1
,
str
,
&
len
);
if
(
!
ipaddr_aton
(
str
,
&
dnsinfo
.
ip
))
if
(
!
ipaddr_aton
(
str
,
&
dnsinfo
.
ip
))
{
{
return
luaL_error
(
L
,
"Could not parse DNS address, aborting"
);
return
luaL_error
(
L
,
"Could not parse DNS address, aborting"
);
}
}
ESP_ERROR_CHECK
(
tcpip_adapter_dhcpc_stop
(
TCPIP_ADAPTER_IF_STA
));
ESP_ERROR_CHECK
(
tcpip_adapter_dhcpc_stop
(
TCPIP_ADAPTER_IF_STA
));
tcpip_adapter_set_ip_info
(
TCPIP_ADAPTER_IF_STA
,
&
ipInfo
);
tcpip_adapter_set_ip_info
(
TCPIP_ADAPTER_IF_STA
,
&
ipInfo
);
tcpip_adapter_set_dns_info
(
TCPIP_ADAPTER_IF_STA
,
TCPIP_ADAPTER_DNS_MAIN
,
&
dnsinfo
);
tcpip_adapter_set_dns_info
(
TCPIP_ADAPTER_IF_STA
,
TCPIP_ADAPTER_DNS_MAIN
,
&
dnsinfo
);
return
0
;
return
0
;
}
}
static
int
wifi_sta_sethostname
(
lua_State
*
L
)
static
int
wifi_sta_sethostname
(
lua_State
*
L
)
{
{
size_t
l
;
size_t
l
;
esp_err_t
err
;
esp_err_t
err
;
const
char
*
hostname
=
luaL_checklstring
(
L
,
1
,
&
l
);
const
char
*
hostname
=
luaL_checklstring
(
L
,
1
,
&
l
);
err
=
tcpip_adapter_set_hostname
(
TCPIP_ADAPTER_IF_STA
,
hostname
);
if
(
err
!=
ESP_OK
)
return
luaL_error
(
L
,
"failed to set hostname, code %d"
,
err
);
lua_pushboolean
(
L
,
err
==
ESP_OK
);
err
=
tcpip_adapter_set_hostname
(
TCPIP_ADAPTER_IF_STA
,
hostname
);
return
1
;
if
(
err
!=
ESP_OK
)
return
luaL_error
(
L
,
"failed to set hostname, code %d"
,
err
);
lua_pushboolean
(
L
,
err
==
ESP_OK
);
return
1
;
}
}
static
int
wifi_sta_config
(
lua_State
*
L
)
static
int
wifi_sta_config
(
lua_State
*
L
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment