[Reconnoiter-devel] [reconnoiter commit] r1530 - trunk/src/modules

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Fri Jan 21 15:44:08 EST 2011


Author: jesus
Date: 2011-01-21 15:44:07 -0500 (Fri, 21 Jan 2011)
New Revision: 1530

Modified:
   trunk/src/modules/lua_noit.c
Log:
allow noit.socket to take an address from which address family can be inferred.  Before we passed an optional argument of 'inet' or 'inet6' which continue to work.  Now you can pass '::1' or another valid IPv6 address and AF_INET6 will be selected.

Modified: trunk/src/modules/lua_noit.c
===================================================================
--- trunk/src/modules/lua_noit.c	2011-01-12 07:06:15 UTC (rev 1529)
+++ trunk/src/modules/lua_noit.c	2011-01-21 20:44:07 UTC (rev 1530)
@@ -1091,12 +1091,18 @@
 nl_socket(lua_State *L) {
   int n = lua_gettop(L);
   uint8_t family = AF_INET;
+  union {
+    struct in_addr addr4;
+    struct in6_addr addr6;
+  } a;
 
   if(n > 0 && lua_isstring(L,1)) {
     const char *fam = lua_tostring(L,1);
     if(!strcmp(fam, "inet")) family = AF_INET;
     else if(!strcmp(fam, "inet6")) family = AF_INET6;
-    else luaL_error(L, "noit.socket unknown family %s", fam);
+    else if(inet_pton(AF_INET, fam, &a) == 1) family = AF_INET;
+    else if(inet_pton(AF_INET6, fam, &a) == 1) family = AF_INET6;
+    else luaL_error(L, "noit.socket family for %s unknown", fam);
   }
 
   if(n <= 1) return nl_socket_internal(L, family, SOCK_STREAM);



More information about the Reconnoiter-devel mailing list