diff options
Diffstat (limited to 'src/unixudp.c')
-rw-r--r-- | src/unixudp.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/unixudp.c b/src/unixudp.c index 1088c6b..0e0a19a 100644 --- a/src/unixudp.c +++ b/src/unixudp.c | |||
@@ -34,6 +34,7 @@ static int meth_setfd(lua_State *L); | |||
34 | static int meth_dirty(lua_State *L); | 34 | static int meth_dirty(lua_State *L); |
35 | static int meth_receivefrom(lua_State *L); | 35 | static int meth_receivefrom(lua_State *L); |
36 | static int meth_sendto(lua_State *L); | 36 | static int meth_sendto(lua_State *L); |
37 | static int meth_getsockname(lua_State *L); | ||
37 | 38 | ||
38 | static const char *unixudp_tryconnect(p_unix un, const char *path); | 39 | static const char *unixudp_tryconnect(p_unix un, const char *path); |
39 | static const char *unixudp_trybind(p_unix un, const char *path); | 40 | static const char *unixudp_trybind(p_unix un, const char *path); |
@@ -55,6 +56,7 @@ static luaL_Reg unixudp_methods[] = { | |||
55 | {"setoption", meth_setoption}, | 56 | {"setoption", meth_setoption}, |
56 | {"setpeername", meth_connect}, | 57 | {"setpeername", meth_connect}, |
57 | {"setsockname", meth_bind}, | 58 | {"setsockname", meth_bind}, |
59 | {"getsockname", meth_getsockname}, | ||
58 | {"settimeout", meth_settimeout}, | 60 | {"settimeout", meth_settimeout}, |
59 | {"gettimeout", meth_gettimeout}, | 61 | {"gettimeout", meth_gettimeout}, |
60 | {NULL, NULL} | 62 | {NULL, NULL} |
@@ -290,6 +292,22 @@ static int meth_bind(lua_State *L) | |||
290 | return 1; | 292 | return 1; |
291 | } | 293 | } |
292 | 294 | ||
295 | static int meth_getsockname(lua_State *L) | ||
296 | { | ||
297 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); | ||
298 | struct sockaddr_un peer = {0}; | ||
299 | socklen_t peer_len = sizeof(peer); | ||
300 | |||
301 | if (getsockname(un->sock, (SA *) &peer, &peer_len) < 0) { | ||
302 | lua_pushnil(L); | ||
303 | lua_pushstring(L, socket_strerror(errno)); | ||
304 | return 2; | ||
305 | } | ||
306 | |||
307 | lua_pushstring(L, peer.sun_path); | ||
308 | return 1; | ||
309 | } | ||
310 | |||
293 | /*-------------------------------------------------------------------------*\ | 311 | /*-------------------------------------------------------------------------*\ |
294 | * Turns a master unixudp object into a client object. | 312 | * Turns a master unixudp object into a client object. |
295 | \*-------------------------------------------------------------------------*/ | 313 | \*-------------------------------------------------------------------------*/ |