projects
/
prosody.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
util.ip: remove unused one-letter loop variables [luacheck]
[prosody.git]
/
util-src
/
net.c
diff --git
a/util-src/net.c
b/util-src/net.c
index 9e57854c84b13369cc4da04976f61ed9d4ae02b4..3ccc7618e95dfbb1292f7f25e7b14a52cc1bc6cd 100644
(file)
--- a/
util-src/net.c
+++ b/
util-src/net.c
@@
-14,38
+14,37
@@
#include <errno.h>
#ifndef _WIN32
#include <errno.h>
#ifndef _WIN32
-
#include <sys/ioctl.h>
-
#include <sys/types.h>
-
#include <sys/socket.h>
-
#include <net/if.h>
-
#include <ifaddrs.h>
-
#include <arpa/inet.h>
-
#include <netinet/in.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <ifaddrs.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
#endif
#include <lua.h>
#include <lauxlib.h>
#endif
#include <lua.h>
#include <lauxlib.h>
-#if (LUA_VERSION_NUM == 50
2
)
-#define luaL_
register(L, N, R) luaL_setfuncs(L, R, 0
)
+#if (LUA_VERSION_NUM == 50
1
)
+#define luaL_
setfuncs(L, R, N) luaL_register(L, NULL, R
)
#endif
/* Enumerate all locally configured IP addresses */
#endif
/* Enumerate all locally configured IP addresses */
-const char
* const type_strings[] = {
+const char* const type_strings[] = {
"both",
"ipv4",
"ipv6",
NULL
};
"both",
"ipv4",
"ipv6",
NULL
};
-static int lc_local_addresses(lua_State *L)
-{
+static int lc_local_addresses(lua_State* L) {
#ifndef _WIN32
/* Link-local IPv4 addresses; see RFC 3927 and RFC 5735 */
const long ip4_linklocal = htonl(0xa9fe0000); /* 169.254.0.0 */
const long ip4_mask = htonl(0xffff0000);
#ifndef _WIN32
/* Link-local IPv4 addresses; see RFC 3927 and RFC 5735 */
const long ip4_linklocal = htonl(0xa9fe0000); /* 169.254.0.0 */
const long ip4_mask = htonl(0xffff0000);
- struct ifaddrs
*
addr = NULL, *a;
+ struct ifaddrs
*
addr = NULL, *a;
#endif
int n = 1;
int type = luaL_checkoption(L, 1, "both", type_strings);
#endif
int n = 1;
int type = luaL_checkoption(L, 1, "both", type_strings);
@@
-54,69
+53,84
@@
static int lc_local_addresses(lua_State *L)
const char ipv6 = (type == 0 || type == 2);
#ifndef _WIN32
const char ipv6 = (type == 0 || type == 2);
#ifndef _WIN32
- if (getifaddrs(&addr) < 0) {
+
+ if(getifaddrs(&addr) < 0) {
lua_pushnil(L);
lua_pushfstring(L, "getifaddrs failed (%d): %s", errno,
lua_pushnil(L);
lua_pushfstring(L, "getifaddrs failed (%d): %s", errno,
- strerror(errno));
+
strerror(errno));
return 2;
}
return 2;
}
+
#endif
lua_newtable(L);
#ifndef _WIN32
#endif
lua_newtable(L);
#ifndef _WIN32
- for (a = addr; a; a = a->ifa_next) {
+
+ for(a = addr; a; a = a->ifa_next) {
int family;
char ipaddr[INET6_ADDRSTRLEN];
int family;
char ipaddr[INET6_ADDRSTRLEN];
- const char
*
tmp = NULL;
+ const char
*
tmp = NULL;
- if
(a->ifa_addr == NULL || a->ifa_flags & IFF_LOOPBACK)
+ if
(a->ifa_addr == NULL || a->ifa_flags & IFF_LOOPBACK) {
continue;
continue;
+ }
family = a->ifa_addr->sa_family;
family = a->ifa_addr->sa_family;
- if (ipv4 && family == AF_INET) {
- struct sockaddr_in *sa = (struct sockaddr_in *)a->ifa_addr;
- if (!link_local &&((sa->sin_addr.s_addr & ip4_mask) == ip4_linklocal))
+ if(ipv4 && family == AF_INET) {
+ struct sockaddr_in* sa = (struct sockaddr_in*)a->ifa_addr;
+
+ if(!link_local && ((sa->sin_addr.s_addr & ip4_mask) == ip4_linklocal)) {
continue;
continue;
+ }
+
tmp = inet_ntop(family, &sa->sin_addr, ipaddr, sizeof(ipaddr));
tmp = inet_ntop(family, &sa->sin_addr, ipaddr, sizeof(ipaddr));
- } else if (ipv6 && family == AF_INET6) {
- struct sockaddr_in6 *sa = (struct sockaddr_in6 *)a->ifa_addr;
- if (!link_local && IN6_IS_ADDR_LINKLOCAL(&sa->sin6_addr))
+ } else if(ipv6 && family == AF_INET6) {
+ struct sockaddr_in6* sa = (struct sockaddr_in6*)a->ifa_addr;
+
+ if(!link_local && IN6_IS_ADDR_LINKLOCAL(&sa->sin6_addr)) {
continue;
continue;
- if (IN6_IS_ADDR_V4MAPPED(&sa->sin6_addr) || IN6_IS_ADDR_V4COMPAT(&sa->sin6_addr))
+ }
+
+ if(IN6_IS_ADDR_V4MAPPED(&sa->sin6_addr) || IN6_IS_ADDR_V4COMPAT(&sa->sin6_addr)) {
continue;
continue;
+ }
+
tmp = inet_ntop(family, &sa->sin6_addr, ipaddr, sizeof(ipaddr));
}
tmp = inet_ntop(family, &sa->sin6_addr, ipaddr, sizeof(ipaddr));
}
- if
(tmp != NULL) {
+ if(tmp != NULL) {
lua_pushstring(L, tmp);
lua_rawseti(L, -2, n++);
}
lua_pushstring(L, tmp);
lua_rawseti(L, -2, n++);
}
+
/* TODO: Error reporting? */
}
freeifaddrs(addr);
#else
/* TODO: Error reporting? */
}
freeifaddrs(addr);
#else
- if (ipv4) {
+
+ if(ipv4) {
lua_pushstring(L, "0.0.0.0");
lua_rawseti(L, -2, n++);
}
lua_pushstring(L, "0.0.0.0");
lua_rawseti(L, -2, n++);
}
- if (ipv6) {
+
+ if(ipv6) {
lua_pushstring(L, "::");
lua_rawseti(L, -2, n++);
}
lua_pushstring(L, "::");
lua_rawseti(L, -2, n++);
}
+
#endif
return 1;
}
#endif
return 1;
}
-int luaopen_util_net(lua_State* L)
-{
+int luaopen_util_net(lua_State* L) {
luaL_Reg exports[] = {
{ "local_addresses", lc_local_addresses },
{ NULL, NULL }
};
lua_newtable(L);
luaL_Reg exports[] = {
{ "local_addresses", lc_local_addresses },
{ NULL, NULL }
};
lua_newtable(L);
- luaL_
register(L, NULL, exports
);
+ luaL_
setfuncs(L, exports, 0
);
return 1;
}
return 1;
}