aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <diego.nehab@gmail.com>2013-05-30 16:50:28 +0800
committerunknown <diego.nehab@gmail.com>2013-05-30 16:50:28 +0800
commit5eefc73b572e591bd127b8c2873f0fa9522dc0b9 (patch)
tree5dbd3040b73a40d13174335fcb6b91d497ce36b4
parenta233e27865d96566a6cb13960d08605ce34d9f0d (diff)
downloadluasocket-5eefc73b572e591bd127b8c2873f0fa9522dc0b9.tar.gz
luasocket-5eefc73b572e591bd127b8c2873f0fa9522dc0b9.tar.bz2
luasocket-5eefc73b572e591bd127b8c2873f0fa9522dc0b9.zip
Remove warnings. Move windows specific code.
-rw-r--r--src/inet.c11
-rw-r--r--src/options.c28
-rw-r--r--src/udp.c12
-rw-r--r--src/usocket.h16
-rw-r--r--src/wsocket.h4
5 files changed, 40 insertions, 31 deletions
diff --git a/src/inet.c b/src/inet.c
index 50b3e5c..25482a3 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -246,9 +246,10 @@ int inet_meth_getpeername(lua_State *L, p_socket ps, int family)
246 lua_pushstring(L, socket_strerror(errno)); 246 lua_pushstring(L, socket_strerror(errno));
247 return 2; 247 return 2;
248 } 248 }
249 if ((err = getnameinfo((struct sockaddr *) &peer, peer_len, 249 err = getnameinfo((struct sockaddr *) &peer, peer_len,
250 name, INET6_ADDRSTRLEN, 250 name, INET6_ADDRSTRLEN,
251 port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV))) { 251 port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV);
252 if (err) {
252 lua_pushnil(L); 253 lua_pushnil(L);
253 lua_pushstring(L, gai_strerror(err)); 254 lua_pushstring(L, gai_strerror(err));
254 return 2; 255 return 2;
@@ -280,9 +281,9 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
280 lua_pushstring(L, socket_strerror(errno)); 281 lua_pushstring(L, socket_strerror(errno));
281 return 2; 282 return 2;
282 } 283 }
283 if ((err=getnameinfo((struct sockaddr *)&peer, peer_len, 284 err=getnameinfo((struct sockaddr *)&peer, peer_len,
284 name, INET6_ADDRSTRLEN, 285 name, INET6_ADDRSTRLEN, port, 6, NI_NUMERICHOST | NI_NUMERICSERV);
285 port, 6, NI_NUMERICHOST | NI_NUMERICSERV))) { 286 if (err) {
286 lua_pushnil(L); 287 lua_pushnil(L);
287 lua_pushstring(L, gai_strerror(err)); 288 lua_pushstring(L, gai_strerror(err));
288 return 2; 289 return 2;
diff --git a/src/options.c b/src/options.c
index 8737d9c..55b65a7 100644
--- a/src/options.c
+++ b/src/options.c
@@ -3,9 +3,6 @@
3* LuaSocket toolkit 3* LuaSocket toolkit
4\*=========================================================================*/ 4\*=========================================================================*/
5#include <string.h> 5#include <string.h>
6#include <sys/types.h>
7#include <sys/socket.h>
8#include <net/if.h>
9 6
10#include "lauxlib.h" 7#include "lauxlib.h"
11 8
@@ -13,20 +10,6 @@
13#include "options.h" 10#include "options.h"
14#include "inet.h" 11#include "inet.h"
15 12
16/* Some platforms use IPV6_JOIN_GROUP instead if
17 * IPV6_ADD_MEMBERSHIP. The semantics are same, though. */
18#ifndef IPV6_ADD_MEMBERSHIP
19#ifdef IPV6_JOIN_GROUP
20#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
21#endif /* IPV6_JOIN_GROUP */
22#endif /* !IPV6_ADD_MEMBERSHIP */
23
24/* Same with IPV6_DROP_MEMBERSHIP / IPV6_LEAVE_GROUP. */
25#ifndef IPV6_DROP_MEMBERSHIP
26#ifdef IPV6_LEAVE_GROUP
27#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
28#endif /* IPV6_LEAVE_GROUP */
29#endif /* !IPV6_DROP_MEMBERSHIP */
30 13
31/*=========================================================================*\ 14/*=========================================================================*\
32* Internal functions prototypes 15* Internal functions prototypes
@@ -296,19 +279,22 @@ static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name)
296 lua_pushstring(L, "interface"); 279 lua_pushstring(L, "interface");
297 lua_gettable(L, 3); 280 lua_gettable(L, 3);
298 /* By default we listen to interface on default route 281 /* By default we listen to interface on default route
299 * (sigh). However, interface= can override it. We support either 282 * (sigh). However, interface= can override it. We should
300 * number, or name for it. */ 283 * support either number, or name for it. Waiting for
284 * windows port of if_nametoindex */
301 if (!lua_isnil(L, -1)) { 285 if (!lua_isnil(L, -1)) {
302 if (lua_isnumber(L, -1)) { 286 if (lua_isnumber(L, -1)) {
303 val.ipv6mr_interface = lua_tonumber(L, -1); 287 val.ipv6mr_interface = (unsigned int) lua_tonumber(L, -1);
288#if 0
304 } else if (lua_isstring(L, -1)) { 289 } else if (lua_isstring(L, -1)) {
305 if (!(val.ipv6mr_interface = if_nametoindex(lua_tostring(L, -1)))) { 290 if (!(val.ipv6mr_interface = if_nametoindex(lua_tostring(L, -1)))) {
306 lua_pushnil(L); 291 lua_pushnil(L);
307 lua_pushstring(L, "nonexistent interface"); 292 lua_pushstring(L, "nonexistent interface");
308 return 2; 293 return 2;
309 } 294 }
295#endif
310 } else 296 } else
311 luaL_argerror(L, -1, "number/string 'interface' field expected"); 297 luaL_argerror(L, -1, "number 'interface' field expected");
312 } 298 }
313 return opt_set(L, ps, level, name, (char *) &val, sizeof(val)); 299 return opt_set(L, ps, level, name, (char *) &val, sizeof(val));
314} 300}
diff --git a/src/udp.c b/src/udp.c
index 8638b1d..a9f2393 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -175,14 +175,15 @@ static int meth_sendto(lua_State *L) {
175 aihint.ai_family = udp->family; 175 aihint.ai_family = udp->family;
176 aihint.ai_socktype = SOCK_DGRAM; 176 aihint.ai_socktype = SOCK_DGRAM;
177 aihint.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; 177 aihint.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
178 if ((err = getaddrinfo(ip, port, &aihint, &ai))) { 178 err = getaddrinfo(ip, port, &aihint, &ai);
179 if (err) {
179 lua_pushnil(L); 180 lua_pushnil(L);
180 lua_pushstring(L, udp_strerror(err)); 181 lua_pushstring(L, gai_strerror(err));
181 return 2; 182 return 2;
182 } 183 }
183 timeout_markstart(tm); 184 timeout_markstart(tm);
184 err = socket_sendto(&udp->sock, data, count, &sent, ai->ai_addr, 185 err = socket_sendto(&udp->sock, data, count, &sent, ai->ai_addr,
185 ai->ai_addrlen, tm); 186 (socklen_t) ai->ai_addrlen, tm);
186 freeaddrinfo(ai); 187 freeaddrinfo(ai);
187 if (err != IO_DONE) { 188 if (err != IO_DONE) {
188 lua_pushnil(L); 189 lua_pushnil(L);
@@ -243,8 +244,9 @@ static int meth_receivefrom(lua_State *L)
243 lua_pushstring(L, udp_strerror(err)); 244 lua_pushstring(L, udp_strerror(err));
244 return 2; 245 return 2;
245 } 246 }
246 if ((err = getnameinfo((struct sockaddr *)&addr, addr_len, addrstr, 247 err = getnameinfo((struct sockaddr *)&addr, addr_len, addrstr,
247 INET6_ADDRSTRLEN, portstr, 6, NI_NUMERICHOST | NI_NUMERICSERV))) { 248 INET6_ADDRSTRLEN, portstr, 6, NI_NUMERICHOST | NI_NUMERICSERV);
249 if (err) {
248 lua_pushnil(L); 250 lua_pushnil(L);
249 lua_pushstring(L, gai_strerror(err)); 251 lua_pushstring(L, gai_strerror(err));
250 return 2; 252 return 2;
diff --git a/src/usocket.h b/src/usocket.h
index 8b3241b..45f2f99 100644
--- a/src/usocket.h
+++ b/src/usocket.h
@@ -29,11 +29,27 @@
29#include <arpa/inet.h> 29#include <arpa/inet.h>
30/* TCP options (nagle algorithm disable) */ 30/* TCP options (nagle algorithm disable) */
31#include <netinet/tcp.h> 31#include <netinet/tcp.h>
32#include <net/if.h>
32 33
33#ifndef SO_REUSEPORT 34#ifndef SO_REUSEPORT
34#define SO_REUSEPORT SO_REUSEADDR 35#define SO_REUSEPORT SO_REUSEADDR
35#endif 36#endif
36 37
38/* Some platforms use IPV6_JOIN_GROUP instead if
39 * IPV6_ADD_MEMBERSHIP. The semantics are same, though. */
40#ifndef IPV6_ADD_MEMBERSHIP
41#ifdef IPV6_JOIN_GROUP
42#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
43#endif /* IPV6_JOIN_GROUP */
44#endif /* !IPV6_ADD_MEMBERSHIP */
45
46/* Same with IPV6_DROP_MEMBERSHIP / IPV6_LEAVE_GROUP. */
47#ifndef IPV6_DROP_MEMBERSHIP
48#ifdef IPV6_LEAVE_GROUP
49#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
50#endif /* IPV6_LEAVE_GROUP */
51#endif /* !IPV6_DROP_MEMBERSHIP */
52
37typedef int t_socket; 53typedef int t_socket;
38typedef t_socket *p_socket; 54typedef t_socket *p_socket;
39typedef struct sockaddr_storage t_sockaddr_storage; 55typedef struct sockaddr_storage t_sockaddr_storage;
diff --git a/src/wsocket.h b/src/wsocket.h
index 8fbc54d..3986640 100644
--- a/src/wsocket.h
+++ b/src/wsocket.h
@@ -26,4 +26,8 @@ typedef t_socket *p_socket;
26#define SO_REUSEPORT SO_REUSEADDR 26#define SO_REUSEPORT SO_REUSEADDR
27#endif 27#endif
28 28
29#ifndef AI_NUMERICSERV
30#define AI_NUMERICSERV (0)
31#endif
32
29#endif /* WSOCKET_H */ 33#endif /* WSOCKET_H */