Comparison

util-src/net.c @ 5752:729c78581308

util.net: Fix compilation on Windows (outputs an empty list of addresses for now) (tested only in my head)
author Matthew Wild <mwild1@gmail.com>
date Mon, 15 Jul 2013 23:43:20 +0100
parent 5750:fbff8ecb6662
child 5810:99ad8d42d0c9
comparison
equal deleted inserted replaced
5750:fbff8ecb6662 5752:729c78581308
35 NULL 35 NULL
36 }; 36 };
37 37
38 static int lc_local_addresses(lua_State *L) 38 static int lc_local_addresses(lua_State *L)
39 { 39 {
40 #ifndef _WIN32
40 /* Link-local IPv4 addresses; see RFC 3927 and RFC 5735 */ 41 /* Link-local IPv4 addresses; see RFC 3927 and RFC 5735 */
41 const long ip4_linklocal = htonl(0xa9fe0000); /* 169.254.0.0 */ 42 const long ip4_linklocal = htonl(0xa9fe0000); /* 169.254.0.0 */
42 const long ip4_mask = htonl(0xffff0000); 43 const long ip4_mask = htonl(0xffff0000);
43 #ifndef _WIN32
44 struct ifaddrs *addr = NULL, *a; 44 struct ifaddrs *addr = NULL, *a;
45 int n = 1; 45 int n = 1;
46 #endif 46 #endif
47 int type = luaL_checkoption(L, 1, "both", type_strings); 47 int type = luaL_checkoption(L, 1, "both", type_strings);
48 const char link_local = lua_toboolean(L, 2); /* defaults to 0 (false) */ 48 const char link_local = lua_toboolean(L, 2); /* defaults to 0 (false) */
54 lua_pushnil(L); 54 lua_pushnil(L);
55 lua_pushfstring(L, "getifaddrs failed (%d): %s", errno, 55 lua_pushfstring(L, "getifaddrs failed (%d): %s", errno,
56 strerror(errno)); 56 strerror(errno));
57 return 2; 57 return 2;
58 } 58 }
59 59 #endif
60 lua_newtable(L); 60 lua_newtable(L);
61 61
62 #ifndef _WIN32
62 for (a = addr; a; a = a->ifa_next) { 63 for (a = addr; a; a = a->ifa_next) {
63 int family; 64 int family;
64 char ipaddr[INET6_ADDRSTRLEN]; 65 char ipaddr[INET6_ADDRSTRLEN];
65 const char *tmp = NULL; 66 const char *tmp = NULL;
66 67
89 } 90 }
90 /* TODO: Error reporting? */ 91 /* TODO: Error reporting? */
91 } 92 }
92 93
93 freeifaddrs(addr); 94 freeifaddrs(addr);
94 95 #endif
95 return 1; 96 return 1;
96 #endif
97 } 97 }
98 98
99 int luaopen_util_net(lua_State* L) 99 int luaopen_util_net(lua_State* L)
100 { 100 {
101 luaL_Reg exports[] = { 101 luaL_Reg exports[] = {