inet: pragma visibility

This commit is contained in:
E. Westbrook 2019-02-27 20:57:14 -07:00
parent 4bf3eb6db2
commit 611cdd19cc
2 changed files with 25 additions and 31 deletions

View File

@ -3,17 +3,12 @@
* LuaSocket toolkit * LuaSocket toolkit
\*=========================================================================*/ \*=========================================================================*/
#include "luasocket.h" #include "luasocket.h"
#include "inet.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "lua.h"
#include "lauxlib.h"
#include "compat.h"
#include "inet.h"
/*=========================================================================*\ /*=========================================================================*\
* Internal function prototypes. * Internal function prototypes.
\*=========================================================================*/ \*=========================================================================*/
@ -34,13 +29,10 @@ static luaL_Reg func[] = {
{ NULL, NULL} { NULL, NULL}
}; };
/*=========================================================================*\
* Exported functions
\*=========================================================================*/
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Initializes module * Initializes module
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_PRIVATE int inet_open(lua_State *L) int inet_open(lua_State *L)
{ {
lua_pushstring(L, "dns"); lua_pushstring(L, "dns");
lua_newtable(L); lua_newtable(L);
@ -145,7 +137,7 @@ static int inet_global_toip(lua_State *L)
return 2; return 2;
} }
LUASOCKET_PRIVATE int inet_optfamily(lua_State* L, int narg, const char* def) int inet_optfamily(lua_State* L, int narg, const char* def)
{ {
static const char* optname[] = { "unspec", "inet", "inet6", NULL }; static const char* optname[] = { "unspec", "inet", "inet6", NULL };
static int optvalue[] = { AF_UNSPEC, AF_INET, AF_INET6, 0 }; 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)
return optvalue[luaL_checkoption(L, narg, def, optname)]; return optvalue[luaL_checkoption(L, narg, def, optname)];
} }
LUASOCKET_PRIVATE int inet_optsocktype(lua_State* L, int narg, const char* def) int inet_optsocktype(lua_State* L, int narg, const char* def)
{ {
static const char* optname[] = { "stream", "dgram", NULL }; static const char* optname[] = { "stream", "dgram", NULL };
static int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 }; static int optvalue[] = { SOCK_STREAM, SOCK_DGRAM, 0 };
@ -244,7 +236,7 @@ static int inet_global_gethostname(lua_State *L)
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Retrieves socket peer name * Retrieves socket peer name
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_PRIVATE int inet_meth_getpeername(lua_State *L, p_socket ps, int family) int inet_meth_getpeername(lua_State *L, p_socket ps, int family)
{ {
int err; int err;
struct sockaddr_storage peer; struct sockaddr_storage peer;
@ -278,7 +270,7 @@ LUASOCKET_PRIVATE int inet_meth_getpeername(lua_State *L, p_socket ps, int famil
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Retrieves socket local name * Retrieves socket local name
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_PRIVATE int inet_meth_getsockname(lua_State *L, p_socket ps, int family) int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
{ {
int err; int err;
struct sockaddr_storage peer; struct sockaddr_storage peer;
@ -354,7 +346,7 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp)
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Tries to create a new inet socket * Tries to create a new inet socket
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_PRIVATE const char *inet_trycreate(p_socket ps, int family, int type, int protocol) { const char *inet_trycreate(p_socket ps, int family, int type, int protocol) {
const char *err = socket_strerror(socket_create(ps, family, type, protocol)); const char *err = socket_strerror(socket_create(ps, family, type, protocol));
if (err == NULL && family == AF_INET6) { if (err == NULL && family == AF_INET6) {
int yes = 1; int yes = 1;
@ -366,7 +358,7 @@ LUASOCKET_PRIVATE const char *inet_trycreate(p_socket ps, int family, int type,
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* "Disconnects" a DGRAM socket * "Disconnects" a DGRAM socket
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_PRIVATE const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm) const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm)
{ {
switch (family) { switch (family) {
case AF_INET: { case AF_INET: {
@ -393,7 +385,7 @@ LUASOCKET_PRIVATE const char *inet_trydisconnect(p_socket ps, int family, p_time
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Tries to connect to remote address (address, port) * Tries to connect to remote address (address, port)
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_PRIVATE const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *inet_tryconnect(p_socket ps, int *family, const char *address,
const char *serv, p_timeout tm, struct addrinfo *connecthints) const char *serv, p_timeout tm, struct addrinfo *connecthints)
{ {
struct addrinfo *iterator = NULL, *resolved = NULL; struct addrinfo *iterator = NULL, *resolved = NULL;
@ -439,7 +431,7 @@ LUASOCKET_PRIVATE const char *inet_tryconnect(p_socket ps, int *family, const ch
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Tries to accept a socket * Tries to accept a socket
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_PRIVATE const char *inet_tryaccept(p_socket server, int family, p_socket client, const char *inet_tryaccept(p_socket server, int family, p_socket client,
p_timeout tm) { p_timeout tm) {
socklen_t len; socklen_t len;
t_sockaddr_storage addr; t_sockaddr_storage addr;
@ -455,7 +447,7 @@ LUASOCKET_PRIVATE const char *inet_tryaccept(p_socket server, int family, p_sock
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Tries to bind socket to (address, port) * Tries to bind socket to (address, port)
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
LUASOCKET_PRIVATE const char *inet_trybind(p_socket ps, int *family, const char *address, const char *inet_trybind(p_socket ps, int *family, const char *address,
const char *serv, struct addrinfo *bindhints) { const char *serv, struct addrinfo *bindhints) {
struct addrinfo *iterator = NULL, *resolved = NULL; struct addrinfo *iterator = NULL, *resolved = NULL;
const char *err = NULL; const char *err = NULL;
@ -499,7 +491,7 @@ LUASOCKET_PRIVATE const char *inet_trybind(p_socket ps, int *family, const char
* Some systems do not provide these so that we provide our own. * Some systems do not provide these so that we provide our own.
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
#ifdef LUASOCKET_INET_ATON #ifdef LUASOCKET_INET_ATON
LUASOCKET_PRIVATE int inet_aton(const char *cp, struct in_addr *inp) int inet_aton(const char *cp, struct in_addr *inp)
{ {
unsigned int a = 0, b = 0, c = 0, d = 0; unsigned int a = 0, b = 0, c = 0, d = 0;
int n = 0, r; int n = 0, r;
@ -521,7 +513,7 @@ LUASOCKET_PRIVATE int inet_aton(const char *cp, struct in_addr *inp)
#endif #endif
#ifdef LUASOCKET_INET_PTON #ifdef LUASOCKET_INET_PTON
LUASOCKET_PRIVATE int inet_pton(int af, const char *src, void *dst) int inet_pton(int af, const char *src, void *dst)
{ {
struct addrinfo hints, *res; struct addrinfo hints, *res;
int ret = 1; int ret = 1;

View File

@ -14,7 +14,7 @@
* *
* The Lua functions toip and tohostname are also implemented here. * The Lua functions toip and tohostname are also implemented here.
\*=========================================================================*/ \*=========================================================================*/
#include "lua.h" #include "luasocket.h"
#include "socket.h" #include "socket.h"
#include "timeout.h" #include "timeout.h"
@ -22,21 +22,21 @@
#define LUASOCKET_INET_ATON #define LUASOCKET_INET_ATON
#endif #endif
#pragma GCC visibility push(hidden)
int inet_open(lua_State *L); int inet_open(lua_State *L);
const char *inet_trycreate(p_socket ps, int family, int type, int protocol); int inet_optfamily(lua_State* L, int narg, const char* def);
const char *inet_tryconnect(p_socket ps, int *family, const char *address, int inet_optsocktype(lua_State* L, int narg, const char* def);
const char *serv, p_timeout tm, struct addrinfo *connecthints);
const char *inet_trybind(p_socket ps, int *family, const char *address,
const char *serv, struct addrinfo *bindhints);
const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm);
const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm);
int inet_meth_getpeername(lua_State *L, p_socket ps, int family); int inet_meth_getpeername(lua_State *L, p_socket ps, int family);
int inet_meth_getsockname(lua_State *L, p_socket ps, int family); int inet_meth_getsockname(lua_State *L, p_socket ps, int family);
int inet_optfamily(lua_State* L, int narg, const char* def); const char *inet_trycreate(p_socket ps, int family, int type, int protocol);
int inet_optsocktype(lua_State* L, int narg, const char* def); const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm);
const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints);
const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm);
const char *inet_trybind(p_socket ps, int *family, const char *address, const char *serv, struct addrinfo *bindhints);
#ifdef LUASOCKET_INET_ATON #ifdef LUASOCKET_INET_ATON
int inet_aton(const char *cp, struct in_addr *inp); 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);
int inet_pton(int af, const char *src, void *dst); int inet_pton(int af, const char *src, void *dst);
#endif #endif
#pragma GCC visibility pop
#endif /* INET_H */ #endif /* INET_H */