diff options
author | E. Westbrook <github@westbrook.io> | 2019-02-27 20:57:14 -0700 |
---|---|---|
committer | E. Westbrook <github@westbrook.io> | 2019-03-10 00:03:04 -0700 |
commit | 611cdd19cc8cf783f028d558cf23e9397db4fa1f (patch) | |
tree | d571734ff0d62a43d7a5eed609c6a0d615f90048 /src | |
parent | 4bf3eb6db2315fef8f3d18c8ce742752f7e4fda2 (diff) | |
download | luasocket-611cdd19cc8cf783f028d558cf23e9397db4fa1f.tar.gz luasocket-611cdd19cc8cf783f028d558cf23e9397db4fa1f.tar.bz2 luasocket-611cdd19cc8cf783f028d558cf23e9397db4fa1f.zip |
inet: pragma visibility
Diffstat (limited to 'src')
-rw-r--r-- | src/inet.c | 34 | ||||
-rw-r--r-- | src/inet.h | 22 |
2 files changed, 25 insertions, 31 deletions
@@ -3,17 +3,12 @@ | |||
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | \*=========================================================================*/ | 4 | \*=========================================================================*/ |
5 | #include "luasocket.h" | 5 | #include "luasocket.h" |
6 | #include "inet.h" | ||
6 | 7 | ||
7 | #include <stdio.h> | 8 | #include <stdio.h> |
8 | #include <stdlib.h> | 9 | #include <stdlib.h> |
9 | #include <string.h> | 10 | #include <string.h> |
10 | 11 | ||
11 | #include "lua.h" | ||
12 | #include "lauxlib.h" | ||
13 | #include "compat.h" | ||
14 | |||
15 | #include "inet.h" | ||
16 | |||
17 | /*=========================================================================*\ | 12 | /*=========================================================================*\ |
18 | * Internal function prototypes. | 13 | * Internal function prototypes. |
19 | \*=========================================================================*/ | 14 | \*=========================================================================*/ |
@@ -34,13 +29,10 @@ static luaL_Reg func[] = { | |||
34 | { NULL, NULL} | 29 | { NULL, NULL} |
35 | }; | 30 | }; |
36 | 31 | ||
37 | /*=========================================================================*\ | ||
38 | * Exported functions | ||
39 | \*=========================================================================*/ | ||
40 | /*-------------------------------------------------------------------------*\ | 32 | /*-------------------------------------------------------------------------*\ |
41 | * Initializes module | 33 | * Initializes module |
42 | \*-------------------------------------------------------------------------*/ | 34 | \*-------------------------------------------------------------------------*/ |
43 | LUASOCKET_PRIVATE int inet_open(lua_State *L) | 35 | int inet_open(lua_State *L) |
44 | { | 36 | { |
45 | lua_pushstring(L, "dns"); | 37 | lua_pushstring(L, "dns"); |
46 | lua_newtable(L); | 38 | lua_newtable(L); |
@@ -145,7 +137,7 @@ static int inet_global_toip(lua_State *L) | |||
145 | return 2; | 137 | return 2; |
146 | } | 138 | } |
147 | 139 | ||
148 | LUASOCKET_PRIVATE int inet_optfamily(lua_State* L, int narg, const char* def) | 140 | int inet_optfamily(lua_State* L, int narg, const char* def) |
149 | { | 141 | { |
150 | static const char* optname[] = { "unspec", "inet", "inet6", NULL }; | 142 | static const char* optname[] = { "unspec", "inet", "inet6", NULL }; |
151 | static int optvalue[] = { AF_UNSPEC, AF_INET, AF_INET6, 0 }; | 143 | static int optvalue[] = { AF_UNSPEC, AF_INET, AF_INET6, 0 }; |
@@ -153,7 +145,7 @@ LUASOCKET_PRIVATE int inet_optfamily(lua_State* L, int narg, const char* def) | |||
153 | return optvalue[luaL_checkoption(L, narg, def, optname)]; | 145 | return optvalue[luaL_checkoption(L, narg, def, optname)]; |
154 | } | 146 | } |
155 | 147 | ||
156 | LUASOCKET_PRIVATE int inet_optsocktype(lua_State* L, int narg, const char* def) | 148 | int inet_optsocktype(lua_State* L, int narg, const char* def) |
157 | { | 149 | { |
158 | static const char* optname[] = { "stream", "dgram", NULL }; | 150 | static const char* optname[] = { "stream", "dgram", NULL }; |
159 | static int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 }; | 151 | static int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 }; |
@@ -244,7 +236,7 @@ static int inet_global_gethostname(lua_State *L) | |||
244 | /*-------------------------------------------------------------------------*\ | 236 | /*-------------------------------------------------------------------------*\ |
245 | * Retrieves socket peer name | 237 | * Retrieves socket peer name |
246 | \*-------------------------------------------------------------------------*/ | 238 | \*-------------------------------------------------------------------------*/ |
247 | LUASOCKET_PRIVATE int inet_meth_getpeername(lua_State *L, p_socket ps, int family) | 239 | int inet_meth_getpeername(lua_State *L, p_socket ps, int family) |
248 | { | 240 | { |
249 | int err; | 241 | int err; |
250 | struct sockaddr_storage peer; | 242 | struct sockaddr_storage peer; |
@@ -278,7 +270,7 @@ LUASOCKET_PRIVATE int inet_meth_getpeername(lua_State *L, p_socket ps, int famil | |||
278 | /*-------------------------------------------------------------------------*\ | 270 | /*-------------------------------------------------------------------------*\ |
279 | * Retrieves socket local name | 271 | * Retrieves socket local name |
280 | \*-------------------------------------------------------------------------*/ | 272 | \*-------------------------------------------------------------------------*/ |
281 | LUASOCKET_PRIVATE int inet_meth_getsockname(lua_State *L, p_socket ps, int family) | 273 | int inet_meth_getsockname(lua_State *L, p_socket ps, int family) |
282 | { | 274 | { |
283 | int err; | 275 | int err; |
284 | struct sockaddr_storage peer; | 276 | struct sockaddr_storage peer; |
@@ -354,7 +346,7 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp) | |||
354 | /*-------------------------------------------------------------------------*\ | 346 | /*-------------------------------------------------------------------------*\ |
355 | * Tries to create a new inet socket | 347 | * Tries to create a new inet socket |
356 | \*-------------------------------------------------------------------------*/ | 348 | \*-------------------------------------------------------------------------*/ |
357 | LUASOCKET_PRIVATE const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { | 349 | const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { |
358 | const char *err = socket_strerror(socket_create(ps, family, type, protocol)); | 350 | const char *err = socket_strerror(socket_create(ps, family, type, protocol)); |
359 | if (err == NULL && family == AF_INET6) { | 351 | if (err == NULL && family == AF_INET6) { |
360 | int yes = 1; | 352 | int yes = 1; |
@@ -366,7 +358,7 @@ LUASOCKET_PRIVATE const char *inet_trycreate(p_socket ps, int family, int type, | |||
366 | /*-------------------------------------------------------------------------*\ | 358 | /*-------------------------------------------------------------------------*\ |
367 | * "Disconnects" a DGRAM socket | 359 | * "Disconnects" a DGRAM socket |
368 | \*-------------------------------------------------------------------------*/ | 360 | \*-------------------------------------------------------------------------*/ |
369 | LUASOCKET_PRIVATE const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) | 361 | const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) |
370 | { | 362 | { |
371 | switch (family) { | 363 | switch (family) { |
372 | case AF_INET: { | 364 | case AF_INET: { |
@@ -393,7 +385,7 @@ LUASOCKET_PRIVATE const char *inet_trydisconnect(p_socket ps, int family, p_time | |||
393 | /*-------------------------------------------------------------------------*\ | 385 | /*-------------------------------------------------------------------------*\ |
394 | * Tries to connect to remote address (address, port) | 386 | * Tries to connect to remote address (address, port) |
395 | \*-------------------------------------------------------------------------*/ | 387 | \*-------------------------------------------------------------------------*/ |
396 | LUASOCKET_PRIVATE const char *inet_tryconnect(p_socket ps, int *family, const char *address, | 388 | const char *inet_tryconnect(p_socket ps, int *family, const char *address, |
397 | const char *serv, p_timeout tm, struct addrinfo *connecthints) | 389 | const char *serv, p_timeout tm, struct addrinfo *connecthints) |
398 | { | 390 | { |
399 | struct addrinfo *iterator = NULL, *resolved = NULL; | 391 | struct addrinfo *iterator = NULL, *resolved = NULL; |
@@ -439,7 +431,7 @@ LUASOCKET_PRIVATE const char *inet_tryconnect(p_socket ps, int *family, const ch | |||
439 | /*-------------------------------------------------------------------------*\ | 431 | /*-------------------------------------------------------------------------*\ |
440 | * Tries to accept a socket | 432 | * Tries to accept a socket |
441 | \*-------------------------------------------------------------------------*/ | 433 | \*-------------------------------------------------------------------------*/ |
442 | LUASOCKET_PRIVATE const char *inet_tryaccept(p_socket server, int family, p_socket client, | 434 | const char *inet_tryaccept(p_socket server, int family, p_socket client, |
443 | p_timeout tm) { | 435 | p_timeout tm) { |
444 | socklen_t len; | 436 | socklen_t len; |
445 | t_sockaddr_storage addr; | 437 | t_sockaddr_storage addr; |
@@ -455,7 +447,7 @@ LUASOCKET_PRIVATE const char *inet_tryaccept(p_socket server, int family, p_sock | |||
455 | /*-------------------------------------------------------------------------*\ | 447 | /*-------------------------------------------------------------------------*\ |
456 | * Tries to bind socket to (address, port) | 448 | * Tries to bind socket to (address, port) |
457 | \*-------------------------------------------------------------------------*/ | 449 | \*-------------------------------------------------------------------------*/ |
458 | LUASOCKET_PRIVATE const char *inet_trybind(p_socket ps, int *family, const char *address, | 450 | const char *inet_trybind(p_socket ps, int *family, const char *address, |
459 | const char *serv, struct addrinfo *bindhints) { | 451 | const char *serv, struct addrinfo *bindhints) { |
460 | struct addrinfo *iterator = NULL, *resolved = NULL; | 452 | struct addrinfo *iterator = NULL, *resolved = NULL; |
461 | const char *err = NULL; | 453 | const char *err = NULL; |
@@ -499,7 +491,7 @@ LUASOCKET_PRIVATE const char *inet_trybind(p_socket ps, int *family, const char | |||
499 | * Some systems do not provide these so that we provide our own. | 491 | * Some systems do not provide these so that we provide our own. |
500 | \*-------------------------------------------------------------------------*/ | 492 | \*-------------------------------------------------------------------------*/ |
501 | #ifdef LUASOCKET_INET_ATON | 493 | #ifdef LUASOCKET_INET_ATON |
502 | LUASOCKET_PRIVATE int inet_aton(const char *cp, struct in_addr *inp) | 494 | int inet_aton(const char *cp, struct in_addr *inp) |
503 | { | 495 | { |
504 | unsigned int a = 0, b = 0, c = 0, d = 0; | 496 | unsigned int a = 0, b = 0, c = 0, d = 0; |
505 | int n = 0, r; | 497 | int n = 0, r; |
@@ -521,7 +513,7 @@ LUASOCKET_PRIVATE int inet_aton(const char *cp, struct in_addr *inp) | |||
521 | #endif | 513 | #endif |
522 | 514 | ||
523 | #ifdef LUASOCKET_INET_PTON | 515 | #ifdef LUASOCKET_INET_PTON |
524 | LUASOCKET_PRIVATE int inet_pton(int af, const char *src, void *dst) | 516 | int inet_pton(int af, const char *src, void *dst) |
525 | { | 517 | { |
526 | struct addrinfo hints, *res; | 518 | struct addrinfo hints, *res; |
527 | int ret = 1; | 519 | int ret = 1; |
@@ -14,7 +14,7 @@ | |||
14 | * | 14 | * |
15 | * The Lua functions toip and tohostname are also implemented here. | 15 | * The Lua functions toip and tohostname are also implemented here. |
16 | \*=========================================================================*/ | 16 | \*=========================================================================*/ |
17 | #include "lua.h" | 17 | #include "luasocket.h" |
18 | #include "socket.h" | 18 | #include "socket.h" |
19 | #include "timeout.h" | 19 | #include "timeout.h" |
20 | 20 | ||
@@ -22,21 +22,21 @@ | |||
22 | #define LUASOCKET_INET_ATON | 22 | #define LUASOCKET_INET_ATON |
23 | #endif | 23 | #endif |
24 | 24 | ||
25 | #pragma GCC visibility push(hidden) | ||
26 | |||
25 | int inet_open(lua_State *L); | 27 | int inet_open(lua_State *L); |
26 | 28 | ||
27 | const char *inet_trycreate(p_socket ps, int family, int type, int protocol); | 29 | int inet_optfamily(lua_State* L, int narg, const char* def); |
28 | const char *inet_tryconnect(p_socket ps, int *family, const char *address, | 30 | int inet_optsocktype(lua_State* L, int narg, const char* def); |
29 | const char *serv, p_timeout tm, struct addrinfo *connecthints); | ||
30 | const char *inet_trybind(p_socket ps, int *family, const char *address, | ||
31 | const char *serv, struct addrinfo *bindhints); | ||
32 | const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm); | ||
33 | const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm); | ||
34 | 31 | ||
35 | int inet_meth_getpeername(lua_State *L, p_socket ps, int family); | 32 | int inet_meth_getpeername(lua_State *L, p_socket ps, int family); |
36 | int inet_meth_getsockname(lua_State *L, p_socket ps, int family); | 33 | int inet_meth_getsockname(lua_State *L, p_socket ps, int family); |
37 | 34 | ||
38 | int inet_optfamily(lua_State* L, int narg, const char* def); | 35 | const char *inet_trycreate(p_socket ps, int family, int type, int protocol); |
39 | int inet_optsocktype(lua_State* L, int narg, const char* def); | 36 | const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm); |
37 | const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints); | ||
38 | const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm); | ||
39 | const char *inet_trybind(p_socket ps, int *family, const char *address, const char *serv, struct addrinfo *bindhints); | ||
40 | 40 | ||
41 | #ifdef LUASOCKET_INET_ATON | 41 | #ifdef LUASOCKET_INET_ATON |
42 | int inet_aton(const char *cp, struct in_addr *inp); | 42 | int inet_aton(const char *cp, struct in_addr *inp); |
@@ -47,4 +47,6 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); | |||
47 | int inet_pton(int af, const char *src, void *dst); | 47 | int inet_pton(int af, const char *src, void *dst); |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | #pragma GCC visibility pop | ||
51 | |||
50 | #endif /* INET_H */ | 52 | #endif /* INET_H */ |