moonbridge
diff moonbridge.c @ 107:06d965df8a0c
Moved local/remote address extraction/formatting to I/O library
author | jbe |
---|---|
date | Wed Apr 08 23:13:09 2015 +0200 (2015-04-08) |
parents | baa30bfec659 |
children | 0daa33d9a147 |
line diff
1.1 --- a/moonbridge.c Wed Apr 08 20:38:18 2015 +0200 1.2 +++ b/moonbridge.c Wed Apr 08 23:13:09 2015 +0200 1.3 @@ -33,7 +33,6 @@ 1.4 #include <sys/socket.h> 1.5 #include <sys/un.h> 1.6 #include <netinet/in.h> 1.7 -#include <arpa/inet.h> 1.8 #include <poll.h> 1.9 #include <signal.h> 1.10 #include <sys/wait.h> 1.11 @@ -843,7 +842,7 @@ 1.12 } 1.13 if (controlmsg == MOONBR_COMMAND_TERMINATE) break; 1.14 listener = moonbr_child_receive_pointer(MOONBR_FD_CONTROL); 1.15 - if (fd) moonbr_io_pushhandle(L, fd, controlmsg == MOONBR_SOCKETTYPE_NETWORK); 1.16 + if (fd) moonbr_io_pushhandle(L, fd); 1.17 lua_rawgetp(L, LUA_REGISTRYINDEX, moonbr_luakey_connect_func(pool)); 1.18 if (!fd) { 1.19 lua_newtable(L); 1.20 @@ -854,69 +853,6 @@ 1.21 lua_setfield(L, -2, "interval"); 1.22 } else { 1.23 lua_pushvalue(L, -2); 1.24 - if (listener->proto == MOONBR_PROTO_TCP6) { 1.25 - struct sockaddr_in6 addr; 1.26 - char addrstrbuf[INET6_ADDRSTRLEN]; 1.27 - const char *addrstr; 1.28 - socklen_t addr_len = sizeof(struct sockaddr_in6); 1.29 - if (getsockname(fd, (struct sockaddr *)&addr, &addr_len)) { 1.30 - moonbr_child_log_errno("Could not get local IP address/port"); 1.31 - } else { 1.32 - addrstr = inet_ntop(AF_INET6, addr.sin6_addr.s6_addr, addrstrbuf, sizeof(addrstrbuf)); 1.33 - if (!addrstr) { 1.34 - moonbr_child_log_errno("Could not format local IP address"); 1.35 - } else { 1.36 - lua_pushstring(L, addrstr); 1.37 - lua_setfield(L, -2, "local_ip6"); 1.38 - } 1.39 - lua_pushinteger(L, ntohs(addr.sin6_port)); 1.40 - lua_setfield(L, -2, "local_tcpport"); 1.41 - } 1.42 - if (getpeername(fd, (struct sockaddr *)&addr, &addr_len)) { 1.43 - moonbr_child_log_errno("Could not get remote IP address/port"); 1.44 - } else { 1.45 - addrstr = inet_ntop(AF_INET6, addr.sin6_addr.s6_addr, addrstrbuf, sizeof(addrstrbuf)); 1.46 - if (!addrstr) { 1.47 - moonbr_child_log_errno("Could not format remote IP address"); 1.48 - } else { 1.49 - lua_pushstring(L, addrstr); 1.50 - lua_setfield(L, -2, "remote_ip6"); 1.51 - } 1.52 - lua_pushinteger(L, ntohs(addr.sin6_port)); 1.53 - lua_setfield(L, -2, "remote_tcpport"); 1.54 - } 1.55 - } else if (listener->proto == MOONBR_PROTO_TCP4) { 1.56 - struct sockaddr_in addr; 1.57 - char addrstrbuf[INET_ADDRSTRLEN]; 1.58 - const char *addrstr; 1.59 - socklen_t addr_len = sizeof(struct sockaddr_in); 1.60 - if (getsockname(fd, (struct sockaddr *)&addr, &addr_len)) { 1.61 - moonbr_child_log_errno("Could not get local IP address/port"); 1.62 - } else { 1.63 - addrstr = inet_ntop(AF_INET, &addr.sin_addr.s_addr, addrstrbuf, sizeof(addrstrbuf)); 1.64 - if (!addrstr) { 1.65 - moonbr_child_log_errno("Could not format local IP address"); 1.66 - } else { 1.67 - lua_pushstring(L, addrstr); 1.68 - lua_setfield(L, -2, "local_ip4"); 1.69 - } 1.70 - lua_pushinteger(L, ntohs(addr.sin_port)); 1.71 - lua_setfield(L, -2, "local_tcpport"); 1.72 - } 1.73 - if (getpeername(fd, (struct sockaddr *)&addr, &addr_len)) { 1.74 - moonbr_child_log_errno("Could not get remote IP address/port"); 1.75 - } else { 1.76 - addrstr = inet_ntop(AF_INET, &addr.sin_addr.s_addr, addrstrbuf, sizeof(addrstrbuf)); 1.77 - if (!addrstr) { 1.78 - moonbr_child_log_errno("Could not format remote IP address"); 1.79 - } else { 1.80 - lua_pushstring(L, addrstr); 1.81 - lua_setfield(L, -2, "remote_ip4"); 1.82 - } 1.83 - lua_pushinteger(L, ntohs(addr.sin_port)); 1.84 - lua_setfield(L, -2, "remote_tcpport"); 1.85 - } 1.86 - } 1.87 } 1.88 if (lua_pcall(L, 1, 1, 1)) { 1.89 fprintf(stderr, "Error in \"connect\" function: %s\n", lua_tostring(L, -1));