aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--makefile20
-rw-r--r--src/inet.c48
-rw-r--r--src/makefile78
3 files changed, 124 insertions, 22 deletions
diff --git a/makefile b/makefile
index 8e9e967..934485b 100644
--- a/makefile
+++ b/makefile
@@ -1,13 +1,23 @@
1PLAT?= macosx 1# luasocket makefile
2#
3# see src/makefile for description of how to customize the build
4#
5# Targets:
6# install install system independent support
7# install-unix also install unix-only support
8# install-both install both lua5.1 and lua5.2 socket support
9# print print the build settings
10
11PLAT?= linux
2PLATS= macosx linux win32 12PLATS= macosx linux win32
3 13
4#------
5# Hopefully no need to change anything below this line
6#
7all: $(PLAT) 14all: $(PLAT)
8 15
9$(PLATS) none install install-unix local clean: 16$(PLATS) none install install-unix local clean:
10 @cd src; $(MAKE) $@ 17 $(MAKE) -C src $@
18
19print:
20 $(MAKE) -C src $@
11 21
12test: 22test:
13 lua test/hello.lua 23 lua test/hello.lua
diff --git a/src/inet.c b/src/inet.c
index 5823c36..55e89d7 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -16,6 +16,7 @@
16static int inet_global_toip(lua_State *L); 16static int inet_global_toip(lua_State *L);
17static int inet_global_getaddrinfo(lua_State *L); 17static int inet_global_getaddrinfo(lua_State *L);
18static int inet_global_tohostname(lua_State *L); 18static int inet_global_tohostname(lua_State *L);
19static int inet_global_getnameinfo(lua_State *L);
19static void inet_pushresolved(lua_State *L, struct hostent *hp); 20static void inet_pushresolved(lua_State *L, struct hostent *hp);
20static int inet_global_gethostname(lua_State *L); 21static int inet_global_gethostname(lua_State *L);
21 22
@@ -24,6 +25,7 @@ static luaL_Reg func[] = {
24 { "toip", inet_global_toip}, 25 { "toip", inet_global_toip},
25 { "getaddrinfo", inet_global_getaddrinfo}, 26 { "getaddrinfo", inet_global_getaddrinfo},
26 { "tohostname", inet_global_tohostname}, 27 { "tohostname", inet_global_tohostname},
28 { "getnameinfo", inet_global_getnameinfo},
27 { "gethostname", inet_global_gethostname}, 29 { "gethostname", inet_global_gethostname},
28 { NULL, NULL} 30 { NULL, NULL}
29}; 31};
@@ -76,6 +78,52 @@ static int inet_global_tohostname(lua_State *L) {
76 return 2; 78 return 2;
77} 79}
78 80
81static int inet_global_getnameinfo(lua_State *L) {
82 int i, ret;
83 char host[1024];
84 char serv[32];
85 struct addrinfo hints;
86 struct addrinfo *resolved, *iter;
87 const char *node = luaL_optstring(L, 1, NULL);
88 const char *service = luaL_optstring(L, 2, NULL);
89
90 if (!(node || service))
91 luaL_error(L, "You have to specify a hostname, a service, or both");
92
93 memset(&hints, 0, sizeof(hints));
94 hints.ai_socktype = SOCK_STREAM;
95 hints.ai_family = PF_UNSPEC;
96
97 /* getaddrinfo must get a node and a service argument */
98 ret = getaddrinfo(node ? node : "127.0.0.1", service ? service : "7",
99 &hints, &resolved);
100 if (ret != 0) {
101 lua_pushnil(L);
102 lua_pushstring(L, socket_gaistrerror(ret));
103 return 2;
104 }
105
106 lua_newtable(L);
107 for (i = 1, iter = resolved; iter; i++, iter = iter->ai_next) {
108 getnameinfo(iter->ai_addr, iter->ai_addrlen, host,
109 node ? sizeof(host) : 0, serv, service ? sizeof(serv) : 0, 0);
110
111 if (node) {
112 lua_pushnumber(L, i);
113 lua_pushstring(L, host);
114 lua_settable(L, -3);
115 }
116 }
117 freeaddrinfo(resolved);
118
119 if (service) {
120 lua_pushstring(L, serv);
121 return 2;
122 } else {
123 return 1;
124 }
125}
126
79/*-------------------------------------------------------------------------*\ 127/*-------------------------------------------------------------------------*\
80* Returns all information provided by the resolver given a host name 128* Returns all information provided by the resolver given a host name
81* or ip address 129* or ip address
diff --git a/src/makefile b/src/makefile
index 6225ce4..4df62bd 100644
--- a/src/makefile
+++ b/src/makefile
@@ -1,21 +1,65 @@
1PLAT?=macosx 1# luasocket src/makefile
2#
3# Definitions in this section can be overriden on the command line or in the
4# environment.
5#
6# These are equivalent:
7#
8# export PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw
9# make
10#
11# and
12#
13# make PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw
14
15# PLAT: linux macosx win32
16# platform to build for
17PLAT?=linux
18
19# LUAV: 5.1 5.2
20# lua version to build against
2LUAV?=5.1 21LUAV?=5.1
3prefix=../../../build/lua/$(LUAV)
4#prefix=/usr/local
5#prefix=/opt/local
6#prefix=.
7 22
8LUAINC_macosx=../../../build/lua/$(LUAV)/include 23# DEBUG: NODEBUG DEBUG
9#LUAINC_macosx=/opt/local/include 24# debug mode causes luasocket to collect and returns timing information useful
10#LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.2.0-beta/src 25# for testing and debugging luasocket itself
11#LUAINC_macosx=../../../../projects/lua_env/luaenv/lua_versions/lua-5.1.4/src 26DEBUG?=NODEBUG
12 27
13#LUAINC_linux=/usr/local/include/lua$(LUAV) 28# prefix: /usr/local /usr /opt/local /sw
14LUAINC_linux=/usr/include/lua$(LUAV) 29# the top of the default install tree
15#LUAINC_linux=/usr/local/include 30prefix?=/usr/local
31
32# where lua headers are found for macosx builds
33# LUAINC_macosx: /opt/local/include
34LUAINC_macosx?=/opt/local/include
35# FIXME default should be where fink puts lua
36
37# LUAINC_linux: /usr/include/lua$(LUAV) /usr/local/include /usr/local/include/lua$(LUAV)
38# where lua headers are found for linux builds
39LUAINC_linux?=/usr/include/lua$(LUAV)
40
41# LUAINC_win32:
42# LUALIB_win32:
43# where lua headers and libraries are found for win32 builds
44LUAINC_win32?="../../lua-5.1.3/src"
45LUALIB_win32?="../../lua-5.1.3"
46# FIXME default should be where lua-for-windows puts lua
47
48# DESTDIR: (no default)
49# used by package managers to install into a temporary destination
50DESTDIR=
51
52#------
53# Definitions below can be overridden on the make command line, but
54# shouldn't have to be.
16 55
17LUAINC_win32="../../lua-5.1.3/src" 56print:
18LUALIB_win32="../../lua-5.1.3" 57 @echo PLAT=$(PLAT)
58 @echo LUAV=$(LUAV)
59 @echo DEBUG=$(DEBUG)
60 @echo prefix=$(prefix)
61 @echo LUAINC_$(PLAT)=$(LUAINC_$(PLAT))
62 @echo LUALIB_$(PLAT)=$(LUALIB_$(PLAT))
19 63
20#------ 64#------
21# Install directories 65# Install directories
@@ -44,7 +88,7 @@ PLATS= macosx linux win32
44SO_macosx=so 88SO_macosx=so
45O_macosx=o 89O_macosx=o
46CC_macosx=gcc 90CC_macosx=gcc
47DEF_macosx= -DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN -DLUA_COMPAT_MODULE \ 91DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN -DLUA_COMPAT_MODULE \
48 -DLUASOCKET_API='__attribute__((visibility("default")))' \ 92 -DLUASOCKET_API='__attribute__((visibility("default")))' \
49 -DMIME_API='__attribute__((visibility("default")))' 93 -DMIME_API='__attribute__((visibility("default")))'
50CFLAGS_macosx= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ 94CFLAGS_macosx= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \
@@ -59,7 +103,7 @@ SOCKET_macosx=usocket.o
59SO_linux=so 103SO_linux=so
60O_linux=o 104O_linux=o
61CC_linux=gcc 105CC_linux=gcc
62DEF_linux=-DLUASOCKET_DEBUG \ 106DEF_linux=-DLUASOCKET_$(DEBUG) \
63 -DLUASOCKET_API='__attribute__((visibility("default")))' \ 107 -DLUASOCKET_API='__attribute__((visibility("default")))' \
64 -DMIME_API='__attribute__((visibility("default")))' 108 -DMIME_API='__attribute__((visibility("default")))'
65CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic \ 109CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic \
@@ -75,7 +119,7 @@ SO_win32=dll
75O_win32=obj 119O_win32=obj
76CC_win32=cl 120CC_win32=cl
77DEF_win32= /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" \ 121DEF_win32= /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" \
78 /D "LUASOCKET_API=__declspec(dllexport)" /D "LUASOCKET_DEBUG" \ 122 /D "LUASOCKET_API=__declspec(dllexport)" /D "LUASOCKET_$(DEBUG)" \
79 /D "_CRT_SECURE_NO_WARNINGS" /D "_WINDLL" 123 /D "_CRT_SECURE_NO_WARNINGS" /D "_WINDLL"
80CFLAGS_win32=/I$(LUAINC) $(DEF) /O2 /Ot /MD /W3 /nologo 124CFLAGS_win32=/I$(LUAINC) $(DEF) /O2 /Ot /MD /W3 /nologo
81LDFLAGS_win32= /nologo /link /NOLOGO /DLL /INCREMENTAL:NO \ 125LDFLAGS_win32= /nologo /link /NOLOGO /DLL /INCREMENTAL:NO \