diff options
author | Waqas Hussain <waqas20@gmail.com> | 2009-10-31 04:58:23 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2009-10-31 04:58:23 +0500 |
commit | 5b2d9e2f8788a38521ed9fe6fbf12cba21b2bcef (patch) | |
tree | 54e747d8ebf9c5dea98936ce6b0cd3ad5c40ab5b /util-src/windows.c | |
parent | 2b25602115bfc936f7d4646c50613df768177388 (diff) | |
download | prosody-5b2d9e2f8788a38521ed9fe6fbf12cba21b2bcef.tar.gz prosody-5b2d9e2f8788a38521ed9fe6fbf12cba21b2bcef.zip |
util.windows: Initial commit. Adds support for querying the windows DNS API for nameservers.
Diffstat (limited to 'util-src/windows.c')
-rw-r--r-- | util-src/windows.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/util-src/windows.c b/util-src/windows.c new file mode 100644 index 00000000..7fb96312 --- /dev/null +++ b/util-src/windows.c @@ -0,0 +1,45 @@ +
+#include <stdio.h>
+#include <windows.h>
+#include <windns.h>
+
+#include "lua.h"
+#include "lauxlib.h"
+
+static int Lget_nameservers(lua_State *L) {
+ char stack_buffer[1024]; // stack allocated buffer
+ IP4_ARRAY* ips = (IP4_ARRAY*) stack_buffer;
+ DWORD len = sizeof(stack_buffer);
+ DNS_STATUS status;
+
+ status = DnsQueryConfig(DnsConfigDnsServerList, FALSE, NULL, NULL, ips, &len);
+ if (status == 0) {
+ DWORD i;
+ lua_createtable(L, ips->AddrCount, 0);
+ for (i = 0; i < ips->AddrCount; i++) {
+ DWORD ip = ips->AddrArray[i];
+ char ip_str[16] = "";
+ sprintf_s(ip_str, sizeof(ip_str), "%d.%d.%d.%d", (ip >> 0) & 255, (ip >> 8) & 255, (ip >> 16) & 255, (ip >> 24) & 255);
+ lua_pushstring(L, ip_str);
+ lua_rawseti(L, -2, i+1);
+ }
+ return 1;
+ } else {
+ luaL_error(L, "DnsQueryConfig returned %d", status);
+ return 0; // unreachable, but prevents a compiler warning
+ }
+}
+
+static const luaL_Reg Reg[] =
+{
+ { "get_nameservers", Lget_nameservers },
+ { NULL, NULL }
+};
+
+LUALIB_API int luaopen_util_windows(lua_State *L) {
+ luaL_register(L, "windows", Reg);
+ lua_pushliteral(L, "version"); /** version */
+ lua_pushliteral(L, "-3.14");
+ lua_settable(L,-3);
+ return 1;
+}
|