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
2c5c00a5
Commit
2c5c00a5
authored
Feb 14, 2015
by
funshine
Browse files
add net.socket:getpeer() api, returns peer ip,port
parent
fab1f956
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/modules/net.c
View file @
2c5c00a5
...
...
@@ -1241,6 +1241,31 @@ static int net_socket_unhold( lua_State* L )
return
0
;
}
// Lua: ip,port = sk:getpeer()
static
int
net_socket_getpeer
(
lua_State
*
L
)
{
lnet_userdata
*
nud
;
const
char
*
mt
=
"net.socket"
;
nud
=
(
lnet_userdata
*
)
luaL_checkudata
(
L
,
1
,
mt
);
luaL_argcheck
(
L
,
nud
,
1
,
"Server/Socket expected"
);
if
(
nud
!=
NULL
&&
nud
->
pesp_conn
!=
NULL
){
char
temp
[
20
]
=
{
0
};
c_sprintf
(
temp
,
IPSTR
,
IP2STR
(
&
(
nud
->
pesp_conn
->
proto
.
tcp
->
remote_ip
)
)
);
if
(
nud
->
pesp_conn
->
proto
.
tcp
->
remote_port
!=
0
)
{
lua_pushstring
(
L
,
temp
);
lua_pushinteger
(
L
,
nud
->
pesp_conn
->
proto
.
tcp
->
remote_port
);
}
else
{
lua_pushnil
(
L
);
lua_pushnil
(
L
);
}
}
else
{
lua_pushnil
(
L
);
lua_pushnil
(
L
);
}
return
2
;
}
// Lua: socket:dns( string, function(ip) )
static
int
net_socket_dns
(
lua_State
*
L
)
{
...
...
@@ -1302,6 +1327,7 @@ static const LUA_REG_TYPE net_socket_map[] =
{
LSTRKEY
(
"hold"
),
LFUNCVAL
(
net_socket_hold
)
},
{
LSTRKEY
(
"unhold"
),
LFUNCVAL
(
net_socket_unhold
)
},
{
LSTRKEY
(
"dns"
),
LFUNCVAL
(
net_socket_dns
)
},
{
LSTRKEY
(
"getpeer"
),
LFUNCVAL
(
net_socket_getpeer
)
},
// { LSTRKEY( "delete" ), LFUNCVAL ( net_socket_delete ) },
{
LSTRKEY
(
"__gc"
),
LFUNCVAL
(
net_socket_delete
)
},
#if LUA_OPTIMIZE_MEMORY > 0
...
...
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