aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorE. Westbrook <github@westbrook.io>2019-02-27 20:57:14 -0700
committerE. Westbrook <github@westbrook.io>2019-03-10 00:03:04 -0700
commit611cdd19cc8cf783f028d558cf23e9397db4fa1f (patch)
treed571734ff0d62a43d7a5eed609c6a0d615f90048 /src
parent4bf3eb6db2315fef8f3d18c8ce742752f7e4fda2 (diff)
downloadluasocket-611cdd19cc8cf783f028d558cf23e9397db4fa1f.tar.gz
luasocket-611cdd19cc8cf783f028d558cf23e9397db4fa1f.tar.bz2
luasocket-611cdd19cc8cf783f028d558cf23e9397db4fa1f.zip
inet: pragma visibility
Diffstat (limited to 'src')
-rw-r--r--src/inet.c34
-rw-r--r--src/inet.h22
2 files changed, 25 insertions, 31 deletions
diff --git a/src/inet.c b/src/inet.c
index bed8a7c..ec73fea 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -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\*-------------------------------------------------------------------------*/
43LUASOCKET_PRIVATE int inet_open(lua_State *L) 35int 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
148LUASOCKET_PRIVATE int inet_optfamily(lua_State* L, int narg, const char* def) 140int 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
156LUASOCKET_PRIVATE int inet_optsocktype(lua_State* L, int narg, const char* def) 148int 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\*-------------------------------------------------------------------------*/
247LUASOCKET_PRIVATE int inet_meth_getpeername(lua_State *L, p_socket ps, int family) 239int 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\*-------------------------------------------------------------------------*/
281LUASOCKET_PRIVATE int inet_meth_getsockname(lua_State *L, p_socket ps, int family) 273int 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\*-------------------------------------------------------------------------*/
357LUASOCKET_PRIVATE const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { 349const 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\*-------------------------------------------------------------------------*/
369LUASOCKET_PRIVATE const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) 361const 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\*-------------------------------------------------------------------------*/
396LUASOCKET_PRIVATE const char *inet_tryconnect(p_socket ps, int *family, const char *address, 388const 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\*-------------------------------------------------------------------------*/
442LUASOCKET_PRIVATE const char *inet_tryaccept(p_socket server, int family, p_socket client, 434const 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\*-------------------------------------------------------------------------*/
458LUASOCKET_PRIVATE const char *inet_trybind(p_socket ps, int *family, const char *address, 450const 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
502LUASOCKET_PRIVATE int inet_aton(const char *cp, struct in_addr *inp) 494int 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
524LUASOCKET_PRIVATE int inet_pton(int af, const char *src, void *dst) 516int 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;
diff --git a/src/inet.h b/src/inet.h
index feb3541..2e00e58 100644
--- a/src/inet.h
+++ b/src/inet.h
@@ -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
25int inet_open(lua_State *L); 27int inet_open(lua_State *L);
26 28
27const char *inet_trycreate(p_socket ps, int family, int type, int protocol); 29int inet_optfamily(lua_State* L, int narg, const char* def);
28const char *inet_tryconnect(p_socket ps, int *family, const char *address, 30int inet_optsocktype(lua_State* L, int narg, const char* def);
29 const char *serv, p_timeout tm, struct addrinfo *connecthints);
30const char *inet_trybind(p_socket ps, int *family, const char *address,
31 const char *serv, struct addrinfo *bindhints);
32const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm);
33const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm);
34 31
35int inet_meth_getpeername(lua_State *L, p_socket ps, int family); 32int inet_meth_getpeername(lua_State *L, p_socket ps, int family);
36int inet_meth_getsockname(lua_State *L, p_socket ps, int family); 33int inet_meth_getsockname(lua_State *L, p_socket ps, int family);
37 34
38int inet_optfamily(lua_State* L, int narg, const char* def); 35const char *inet_trycreate(p_socket ps, int family, int type, int protocol);
39int inet_optsocktype(lua_State* L, int narg, const char* def); 36const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm);
37const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints);
38const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm);
39const 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
42int inet_aton(const char *cp, struct in_addr *inp); 42int 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);
47int inet_pton(int af, const char *src, void *dst); 47int 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 */