mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 20:18:21 +01:00
Remove warnings. Move windows specific code.
This commit is contained in:
parent
a233e27865
commit
5eefc73b57
11
src/inet.c
11
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;
|
||||
|
@ -3,9 +3,6 @@
|
||||
* LuaSocket toolkit
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#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));
|
||||
}
|
||||
|
12
src/udp.c
12
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;
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user