From 5eefc73b572e591bd127b8c2873f0fa9522dc0b9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 May 2013 16:50:28 +0800 Subject: [PATCH] Remove warnings. Move windows specific code. --- src/inet.c | 11 ++++++----- src/options.c | 28 +++++++--------------------- src/udp.c | 12 +++++++----- src/usocket.h | 16 ++++++++++++++++ src/wsocket.h | 4 ++++ 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) lua_pushstring(L, socket_strerror(errno)); return 2; } - if ((err = getnameinfo((struct sockaddr *) &peer, peer_len, + err = getnameinfo((struct sockaddr *) &peer, peer_len, name, INET6_ADDRSTRLEN, - port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV))) { + port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); + if (err) { lua_pushnil(L); lua_pushstring(L, gai_strerror(err)); return 2; @@ -280,9 +281,9 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family) lua_pushstring(L, socket_strerror(errno)); return 2; } - if ((err=getnameinfo((struct sockaddr *)&peer, peer_len, - name, INET6_ADDRSTRLEN, - port, 6, NI_NUMERICHOST | NI_NUMERICSERV))) { + err=getnameinfo((struct sockaddr *)&peer, peer_len, + name, INET6_ADDRSTRLEN, port, 6, NI_NUMERICHOST | NI_NUMERICSERV); + if (err) { lua_pushnil(L); lua_pushstring(L, gai_strerror(err)); 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 @@ * LuaSocket toolkit \*=========================================================================*/ #include -#include -#include -#include #include "lauxlib.h" @@ -13,20 +10,6 @@ #include "options.h" #include "inet.h" -/* Some platforms use IPV6_JOIN_GROUP instead if - * IPV6_ADD_MEMBERSHIP. The semantics are same, though. */ -#ifndef IPV6_ADD_MEMBERSHIP -#ifdef IPV6_JOIN_GROUP -#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP -#endif /* IPV6_JOIN_GROUP */ -#endif /* !IPV6_ADD_MEMBERSHIP */ - -/* Same with IPV6_DROP_MEMBERSHIP / IPV6_LEAVE_GROUP. */ -#ifndef IPV6_DROP_MEMBERSHIP -#ifdef IPV6_LEAVE_GROUP -#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP -#endif /* IPV6_LEAVE_GROUP */ -#endif /* !IPV6_DROP_MEMBERSHIP */ /*=========================================================================*\ * Internal functions prototypes @@ -296,19 +279,22 @@ static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name) lua_pushstring(L, "interface"); lua_gettable(L, 3); /* By default we listen to interface on default route - * (sigh). However, interface= can override it. We support either - * number, or name for it. */ + * (sigh). However, interface= can override it. We should + * support either number, or name for it. Waiting for + * windows port of if_nametoindex */ if (!lua_isnil(L, -1)) { if (lua_isnumber(L, -1)) { - val.ipv6mr_interface = lua_tonumber(L, -1); + val.ipv6mr_interface = (unsigned int) lua_tonumber(L, -1); +#if 0 } else if (lua_isstring(L, -1)) { if (!(val.ipv6mr_interface = if_nametoindex(lua_tostring(L, -1)))) { lua_pushnil(L); lua_pushstring(L, "nonexistent interface"); return 2; } +#endif } else - luaL_argerror(L, -1, "number/string 'interface' field expected"); + luaL_argerror(L, -1, "number 'interface' field expected"); } return opt_set(L, ps, level, name, (char *) &val, sizeof(val)); } 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) { aihint.ai_family = udp->family; aihint.ai_socktype = SOCK_DGRAM; aihint.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; - if ((err = getaddrinfo(ip, port, &aihint, &ai))) { + err = getaddrinfo(ip, port, &aihint, &ai); + if (err) { lua_pushnil(L); - lua_pushstring(L, udp_strerror(err)); + lua_pushstring(L, gai_strerror(err)); return 2; } timeout_markstart(tm); err = socket_sendto(&udp->sock, data, count, &sent, ai->ai_addr, - ai->ai_addrlen, tm); + (socklen_t) ai->ai_addrlen, tm); freeaddrinfo(ai); if (err != IO_DONE) { lua_pushnil(L); @@ -243,8 +244,9 @@ static int meth_receivefrom(lua_State *L) lua_pushstring(L, udp_strerror(err)); return 2; } - if ((err = getnameinfo((struct sockaddr *)&addr, addr_len, addrstr, - INET6_ADDRSTRLEN, portstr, 6, NI_NUMERICHOST | NI_NUMERICSERV))) { + err = getnameinfo((struct sockaddr *)&addr, addr_len, addrstr, + INET6_ADDRSTRLEN, portstr, 6, NI_NUMERICHOST | NI_NUMERICSERV); + if (err) { lua_pushnil(L); lua_pushstring(L, gai_strerror(err)); 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 @@ #include /* TCP options (nagle algorithm disable) */ #include +#include #ifndef SO_REUSEPORT #define SO_REUSEPORT SO_REUSEADDR #endif +/* Some platforms use IPV6_JOIN_GROUP instead if + * IPV6_ADD_MEMBERSHIP. The semantics are same, though. */ +#ifndef IPV6_ADD_MEMBERSHIP +#ifdef IPV6_JOIN_GROUP +#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP +#endif /* IPV6_JOIN_GROUP */ +#endif /* !IPV6_ADD_MEMBERSHIP */ + +/* Same with IPV6_DROP_MEMBERSHIP / IPV6_LEAVE_GROUP. */ +#ifndef IPV6_DROP_MEMBERSHIP +#ifdef IPV6_LEAVE_GROUP +#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP +#endif /* IPV6_LEAVE_GROUP */ +#endif /* !IPV6_DROP_MEMBERSHIP */ + typedef int t_socket; typedef t_socket *p_socket; typedef 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; #define SO_REUSEPORT SO_REUSEADDR #endif +#ifndef AI_NUMERICSERV +#define AI_NUMERICSERV (0) +#endif + #endif /* WSOCKET_H */