Software /
code /
prosody
Annotate
util-src/net.c @ 13652:a08065207ef0
net.server_epoll: Call :shutdown() on TLS sockets when supported
Comment from Matthew:
This fixes a potential issue where the Prosody process gets blocked on sockets
waiting for them to close. Unlike non-TLS sockets, closing a TLS socket sends
layer 7 data, and this can cause problems for sockets which are in the process
of being cleaned up.
This depends on LuaSec changes which are not yet upstream.
From Martijn's original email:
So first my analysis of luasec. in ssl.c the socket is put into blocking
mode right before calling SSL_shutdown() inside meth_destroy(). My best
guess to why this is is because meth_destroy is linked to the __close
and __gc methods, which can't exactly be called multiple times and
luasec does want to make sure that a tls session is shutdown as clean
as possible.
I can't say I disagree with this reasoning and don't want to change this
behaviour. My solution to this without changing the current behaviour is
to introduce a shutdown() method. I am aware that this overlaps in a
conflicting way with tcp's shutdown method, but it stays close to the
OpenSSL name. This method calls SSL_shutdown() in the current
(non)blocking mode of the underlying socket and returns a boolean
whether or not the shutdown is completed (matching SSL_shutdown()'s 0
or 1 return values), and returns the familiar ssl_ioerror() strings on
error with a false for completion. This error can then be used to
determine if we have wantread/wantwrite to finalize things. Once
meth_shutdown() has been called once a shutdown flag will be set, which
indicates to meth_destroy() that the SSL_shutdown() has been handled
by the application and it shouldn't be needed to set the socket to
blocking mode. I've left the SSL_shutdown() call in the
LSEC_STATE_CONNECTED to prevent TOCTOU if the application reaches a
timeout for the shutdown code, which might allow SSL_shutdown() to
clean up anyway at the last possible moment.
Another thing I've changed to luasec is the call to socket_setblocking()
right before calling close(2) in socket_destroy() in usocket.c.
According to the latest POSIX[0]:
Note that the requirement for close() on a socket to block for up to
the current linger interval is not conditional on the O_NONBLOCK
setting.
Which I read to mean that removing O_NONBLOCK on the socket before close
doesn't impact the behaviour and only causes noise in system call
tracers. I didn't touch the windows bits of this, since I don't do
windows.
For the prosody side of things I've made the TLS shutdown bits resemble
interface:onwritable(), and put it under a combined guard of self._tls
and self.conn.shutdown. The self._tls bit is there to prevent getting
stuck on this condition, and self.conn.shutdown is there to prevent the
code being called by instances where the patched luasec isn't deployed.
The destroy() method can be called from various places and is read by
me as the "we give up" error path. To accommodate for these unexpected
entrypoints I've added a single call to self.conn:shutdown() to prevent
the socket being put into blocking mode. I have no expectations that
there is any other use here. Same as previous, the self.conn.shutdown
check is there to make sure it's not called on unpatched luasec
deployments and self._tls is there to make sure we don't call shutdown()
on tcp sockets.
I wouldn't recommend logging of the conn:shutdown() error inside
close(), since a lot of clients simply close the connection before
SSL_shutdown() is done.
author | Martijn van Duren <martijn@openbsd.org> |
---|---|
date | Thu, 06 Feb 2025 15:04:38 +0000 |
parent | 12976:a187600ec7d6 |
rev | line source |
---|---|
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 /* Prosody IM |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- This project is MIT/X11 licensed. Please see the |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- COPYING file in the source package for more information. |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- Copyright (C) 2012 Paul Aurich |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- Copyright (C) 2013 Matthew Wild |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 -- Copyright (C) 2013 Florian Zeitz |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 -- |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 */ |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
9150
c1d5f52274cf
net, pposix, signal: Check for redefined defines, fix warnings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8426
diff
changeset
|
12 #ifndef _GNU_SOURCE |
7931
b619b85e01aa
util.pposix, configure: Move _GNU_SOURCE macro into source files
Kim Alvefur <zash@zash.se>
parents:
7889
diff
changeset
|
13 #define _GNU_SOURCE |
9150
c1d5f52274cf
net, pposix, signal: Check for redefined defines, fix warnings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8426
diff
changeset
|
14 #endif |
c1d5f52274cf
net, pposix, signal: Check for redefined defines, fix warnings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8426
diff
changeset
|
15 |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 #include <stddef.h> |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 #include <string.h> |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 #include <errno.h> |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 #ifndef _WIN32 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
21 #include <sys/ioctl.h> |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
22 #include <sys/types.h> |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
23 #include <sys/socket.h> |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
24 #include <net/if.h> |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
25 #include <ifaddrs.h> |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
26 #include <arpa/inet.h> |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
27 #include <netinet/in.h> |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 #endif |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 #include <lua.h> |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 #include <lauxlib.h> |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
10921
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
10637
diff
changeset
|
33 #if (LUA_VERSION_NUM < 504) |
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
10637
diff
changeset
|
34 #define luaL_pushfail lua_pushnil |
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
10637
diff
changeset
|
35 #endif |
6413
a552f4170aed
util-src/*.c: Add macro for compiling with Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
6411
diff
changeset
|
36 |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 /* Enumerate all locally configured IP addresses */ |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
10480
94cacf9fd0ae
util.*.c: Add static qualifiers everywhere
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9150
diff
changeset
|
39 static const char *const type_strings[] = { |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 "both", |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 "ipv4", |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 "ipv6", |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 NULL |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 }; |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
46 static int lc_local_addresses(lua_State *L) { |
5752
729c78581308
util.net: Fix compilation on Windows (outputs an empty list of addresses for now) (tested only in my head)
Matthew Wild <mwild1@gmail.com>
parents:
5750
diff
changeset
|
47 #ifndef _WIN32 |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 /* Link-local IPv4 addresses; see RFC 3927 and RFC 5735 */ |
10637
aa304109fa1b
util.net: Fix signedness warning on ARM
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
10480
diff
changeset
|
49 const uint32_t ip4_linklocal = htonl(0xa9fe0000); /* 169.254.0.0 */ |
aa304109fa1b
util.net: Fix signedness warning on ARM
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
10480
diff
changeset
|
50 const uint32_t ip4_mask = htonl(0xffff0000); |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
51 struct ifaddrs *addr = NULL, *a; |
5810
99ad8d42d0c9
util.net: Fix s2sout on Windows (return 0.0.0.0 and :: instead of an empty list)
Kim Alvefur <zash@zash.se>
parents:
5752
diff
changeset
|
52 #endif |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 int n = 1; |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 int type = luaL_checkoption(L, 1, "both", type_strings); |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 const char link_local = lua_toboolean(L, 2); /* defaults to 0 (false) */ |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 const char ipv4 = (type == 0 || type == 1); |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 const char ipv6 = (type == 0 || type == 2); |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 #ifndef _WIN32 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
60 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
61 if(getifaddrs(&addr) < 0) { |
10921
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
10637
diff
changeset
|
62 luaL_pushfail(L); |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 lua_pushfstring(L, "getifaddrs failed (%d): %s", errno, |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
64 strerror(errno)); |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 return 2; |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 } |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
67 |
5752
729c78581308
util.net: Fix compilation on Windows (outputs an empty list of addresses for now) (tested only in my head)
Matthew Wild <mwild1@gmail.com>
parents:
5750
diff
changeset
|
68 #endif |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 lua_newtable(L); |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 |
5752
729c78581308
util.net: Fix compilation on Windows (outputs an empty list of addresses for now) (tested only in my head)
Matthew Wild <mwild1@gmail.com>
parents:
5750
diff
changeset
|
71 #ifndef _WIN32 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
72 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
73 for(a = addr; a; a = a->ifa_next) { |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 int family; |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 char ipaddr[INET6_ADDRSTRLEN]; |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
76 const char *tmp = NULL; |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
78 if(a->ifa_addr == NULL || a->ifa_flags & IFF_LOOPBACK) { |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 continue; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
80 } |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 family = a->ifa_addr->sa_family; |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
84 if(ipv4 && family == AF_INET) { |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
85 struct sockaddr_in *sa = (struct sockaddr_in *)a->ifa_addr; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
86 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
87 if(!link_local && ((sa->sin_addr.s_addr & ip4_mask) == ip4_linklocal)) { |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 continue; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
89 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
90 |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 tmp = inet_ntop(family, &sa->sin_addr, ipaddr, sizeof(ipaddr)); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
92 } else if(ipv6 && family == AF_INET6) { |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
93 struct sockaddr_in6 *sa = (struct sockaddr_in6 *)a->ifa_addr; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
94 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
95 if(!link_local && IN6_IS_ADDR_LINKLOCAL(&sa->sin6_addr)) { |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 continue; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
97 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
98 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
99 if(IN6_IS_ADDR_V4MAPPED(&sa->sin6_addr) || IN6_IS_ADDR_V4COMPAT(&sa->sin6_addr)) { |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 continue; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
101 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
102 |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 tmp = inet_ntop(family, &sa->sin6_addr, ipaddr, sizeof(ipaddr)); |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 } |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
106 if(tmp != NULL) { |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 lua_pushstring(L, tmp); |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 lua_rawseti(L, -2, n++); |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 } |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
110 |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 /* TODO: Error reporting? */ |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 } |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 freeifaddrs(addr); |
5810
99ad8d42d0c9
util.net: Fix s2sout on Windows (return 0.0.0.0 and :: instead of an empty list)
Kim Alvefur <zash@zash.se>
parents:
5752
diff
changeset
|
115 #else |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
116 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
117 if(ipv4) { |
5810
99ad8d42d0c9
util.net: Fix s2sout on Windows (return 0.0.0.0 and :: instead of an empty list)
Kim Alvefur <zash@zash.se>
parents:
5752
diff
changeset
|
118 lua_pushstring(L, "0.0.0.0"); |
99ad8d42d0c9
util.net: Fix s2sout on Windows (return 0.0.0.0 and :: instead of an empty list)
Kim Alvefur <zash@zash.se>
parents:
5752
diff
changeset
|
119 lua_rawseti(L, -2, n++); |
99ad8d42d0c9
util.net: Fix s2sout on Windows (return 0.0.0.0 and :: instead of an empty list)
Kim Alvefur <zash@zash.se>
parents:
5752
diff
changeset
|
120 } |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
121 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
122 if(ipv6) { |
5810
99ad8d42d0c9
util.net: Fix s2sout on Windows (return 0.0.0.0 and :: instead of an empty list)
Kim Alvefur <zash@zash.se>
parents:
5752
diff
changeset
|
123 lua_pushstring(L, "::"); |
99ad8d42d0c9
util.net: Fix s2sout on Windows (return 0.0.0.0 and :: instead of an empty list)
Kim Alvefur <zash@zash.se>
parents:
5752
diff
changeset
|
124 lua_rawseti(L, -2, n++); |
99ad8d42d0c9
util.net: Fix s2sout on Windows (return 0.0.0.0 and :: instead of an empty list)
Kim Alvefur <zash@zash.se>
parents:
5752
diff
changeset
|
125 } |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
126 |
5752
729c78581308
util.net: Fix compilation on Windows (outputs an empty list of addresses for now) (tested only in my head)
Matthew Wild <mwild1@gmail.com>
parents:
5750
diff
changeset
|
127 #endif |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 return 1; |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 } |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 |
8426
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
131 static int lc_pton(lua_State *L) { |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
132 char buf[16]; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
133 const char *ipaddr = luaL_checkstring(L, 1); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
134 int errno_ = 0; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
135 int family = strchr(ipaddr, ':') ? AF_INET6 : AF_INET; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
136 |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
137 switch(inet_pton(family, ipaddr, &buf)) { |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
138 case 1: |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
139 lua_pushlstring(L, buf, family == AF_INET6 ? 16 : 4); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
140 return 1; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
141 |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
142 case -1: |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
143 errno_ = errno; |
10921
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
10637
diff
changeset
|
144 luaL_pushfail(L); |
8426
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
145 lua_pushstring(L, strerror(errno_)); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
146 lua_pushinteger(L, errno_); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
147 return 3; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
148 |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
149 default: |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
150 case 0: |
10921
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
10637
diff
changeset
|
151 luaL_pushfail(L); |
8426
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
152 lua_pushstring(L, strerror(EINVAL)); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
153 lua_pushinteger(L, EINVAL); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
154 return 3; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
155 } |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
156 |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
157 } |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
158 |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
159 static int lc_ntop(lua_State *L) { |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
160 char buf[INET6_ADDRSTRLEN]; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
161 int family; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
162 int errno_; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
163 size_t l; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
164 const char *ipaddr = luaL_checklstring(L, 1, &l); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
165 |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
166 if(l == 16) { |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
167 family = AF_INET6; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
168 } |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
169 else if(l == 4) { |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
170 family = AF_INET; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
171 } |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
172 else { |
10921
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
10637
diff
changeset
|
173 luaL_pushfail(L); |
8426
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
174 lua_pushstring(L, strerror(EAFNOSUPPORT)); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
175 lua_pushinteger(L, EAFNOSUPPORT); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
176 return 3; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
177 } |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
178 |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
179 if(!inet_ntop(family, ipaddr, buf, INET6_ADDRSTRLEN)) |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
180 { |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
181 errno_ = errno; |
10921
6eb5d2bb11af
util-src: Use the luaL_pushfail API added in Lua 5.4 to highlight all failure conditions
Kim Alvefur <zash@zash.se>
parents:
10637
diff
changeset
|
182 luaL_pushfail(L); |
8426
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
183 lua_pushstring(L, strerror(errno_)); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
184 lua_pushinteger(L, errno_); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
185 return 3; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
186 } |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
187 |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
188 lua_pushstring(L, (const char *)(&buf)); |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
189 return 1; |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
190 } |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
191 |
12976
a187600ec7d6
util: Add compat for prosody module name change to C sources
Kim Alvefur <zash@zash.se>
parents:
12575
diff
changeset
|
192 int luaopen_prosody_util_net(lua_State *L) { |
7818
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
193 luaL_checkversion(L); |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 luaL_Reg exports[] = { |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 { "local_addresses", lc_local_addresses }, |
8426
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
196 { "pton", lc_pton }, |
8b612ec00e4a
util.net: Add bindings to inet_ntop and inet_pton
Kim Alvefur <zash@zash.se>
parents:
7969
diff
changeset
|
197 { "ntop", lc_ntop }, |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 { NULL, NULL } |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 }; |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 |
7969
1c6a07606309
util-src: Specify size of various tables to be allocated
Kim Alvefur <zash@zash.se>
parents:
7931
diff
changeset
|
201 lua_createtable(L, 0, 1); |
6789
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6615
diff
changeset
|
202 luaL_setfuncs(L, exports, 0); |
5699
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 return 1; |
e9f5384f5ff1
util.net: Add util.net, containing local_addresses() (removed from LuaSocket 3.0)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 } |
12976
a187600ec7d6
util: Add compat for prosody module name change to C sources
Kim Alvefur <zash@zash.se>
parents:
12575
diff
changeset
|
205 int luaopen_util_net(lua_State *L) { |
a187600ec7d6
util: Add compat for prosody module name change to C sources
Kim Alvefur <zash@zash.se>
parents:
12575
diff
changeset
|
206 return luaopen_prosody_util_net(L); |
a187600ec7d6
util: Add compat for prosody module name change to C sources
Kim Alvefur <zash@zash.se>
parents:
12575
diff
changeset
|
207 } |