Skip to content

Commit

Permalink
Remove warnings. Move windows specific code.
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonehab committed May 30, 2013
1 parent a233e27 commit 5eefc73
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 31 deletions.
11 changes: 6 additions & 5 deletions src/inet.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 7 additions & 21 deletions src/options.c
Expand Up @@ -3,30 +3,13 @@
* LuaSocket toolkit
\*=========================================================================*/
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>

#include "lauxlib.h"

#include "auxiliar.h"
#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
Expand Down Expand Up @@ -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));
}
Expand Down
12 changes: 7 additions & 5 deletions src/udp.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/usocket.h
Expand Up @@ -29,11 +29,27 @@
#include <arpa/inet.h>
/* TCP options (nagle algorithm disable) */
#include <netinet/tcp.h>
#include <net/if.h>

#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;
Expand Down
4 changes: 4 additions & 0 deletions src/wsocket.h
Expand Up @@ -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 */

0 comments on commit 5eefc73

Please sign in to comment.