From f5c0e92ed30ce22c14e8ddef2dabac9c501ff82c Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Sat, 9 Nov 2013 11:53:28 +0000 Subject: [PATCH] luasocket: update to 3.0-rc1 + add interface support SVN-Revision: 38696 --- lang/luasocket/Makefile | 20 +- .../patches/0001-Add-interface-support.patch | 237 ++++++++++++++++++ 2 files changed, 248 insertions(+), 9 deletions(-) create mode 100644 lang/luasocket/patches/0001-Add-interface-support.patch diff --git a/lang/luasocket/Makefile b/lang/luasocket/Makefile index 6dc88cd4d..93e7bfa5c 100644 --- a/lang/luasocket/Makefile +++ b/lang/luasocket/Makefile @@ -8,12 +8,14 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luasocket -PKG_VERSION:=2.0.2 -PKG_RELEASE:=3 +PKG_SOURCE_VERSION:=6d5e40c324c84d9c1453ae88e0ad5bdd0a631448 +PKG_VERSION:=3.0-rc1-20130909 +PKG_RELEASE:=1 -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=http://luaforge.net/frs/download.php/2664 -PKG_MD5SUM:=41445b138deb7bcfe97bff957503da8e +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 +PKG_SOURCE_URL:=https://github.com/diegonehab/luasocket.git +PKG_SOURCE_PROTO:=git +PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) include $(INCLUDE_DIR)/package.mk @@ -47,13 +49,13 @@ endef define Package/luasocket/install $(INSTALL_DIR) $(1)/usr/lib/lua $(INSTALL_DATA) $(PKG_BUILD_DIR)/src/{ltn12,mime,socket}.lua $(1)/usr/lib/lua - $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/mime.so.1.0.2 $(1)/usr/lib/lua - $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/socket.so.2.0.2 $(1)/usr/lib/lua + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/mime.so.1.0.3 $(1)/usr/lib/lua + $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/socket.so.3.0-rc1 $(1)/usr/lib/lua $(INSTALL_DIR) $(1)/usr/lib/lua/mime - ln -sf ../mime.so.1.0.2 $(1)/usr/lib/lua/mime/core.so + ln -sf ../mime.so.1.0.3 $(1)/usr/lib/lua/mime/core.so $(INSTALL_DIR) $(1)/usr/lib/lua/socket $(INSTALL_DATA) $(PKG_BUILD_DIR)/src/{ftp,http,smtp,tp,url}.lua $(1)/usr/lib/lua/socket - ln -sf ../socket.so.2.0.2 $(1)/usr/lib/lua/socket/core.so + ln -sf ../socket.so.3.0-rc1 $(1)/usr/lib/lua/socket/core.so endef $(eval $(call BuildPackage,luasocket)) diff --git a/lang/luasocket/patches/0001-Add-interface-support.patch b/lang/luasocket/patches/0001-Add-interface-support.patch new file mode 100644 index 000000000..3be42ed56 --- /dev/null +++ b/lang/luasocket/patches/0001-Add-interface-support.patch @@ -0,0 +1,237 @@ +From 96fdf07acf78ecfc9be76a8b0591f38fe6f1a875 Mon Sep 17 00:00:00 2001 +From: Steven Barth +Date: Sat, 9 Nov 2013 12:01:42 +0100 +Subject: [PATCH] Add interface resolving + +--- + src/if.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + src/if.h | 27 ++++++++++++++ + src/luasocket.c | 2 + + src/makefile | 2 + + src/options.c | 9 +++++ + 5 files changed, 153 insertions(+) + create mode 100644 src/if.c + create mode 100644 src/if.h + +diff --git a/src/if.c b/src/if.c +new file mode 100644 +index 0000000..db231aa +--- /dev/null ++++ b/src/if.c +@@ -0,0 +1,113 @@ ++/* ++ * $Id: if.c $ ++ * ++ * Author: Markus Stenberg ++ * ++ * Copyright (c) 2012 cisco Systems, Inc. ++ * ++ * Created: Tue Dec 4 14:50:34 2012 mstenber ++ * Last modified: Wed Dec 5 18:51:08 2012 mstenber ++ * Edit time: 24 min ++ * ++ */ ++ ++#include ++#include ++#include ++ ++#include "if.h" ++ ++#include "lauxlib.h" ++ ++static int if_global_indextoname(lua_State *L); ++static int if_global_nametoindex(lua_State *L); ++static int if_global_nameindex(lua_State *L); ++ ++static luaL_Reg func[] = { ++ { "indextoname", if_global_indextoname}, ++ { "nametoindex", if_global_nametoindex}, ++ { "nameindex", if_global_nameindex}, ++ { NULL, NULL} ++}; ++ ++int if_open(lua_State *L) ++{ ++ lua_pushstring(L, "iface"); ++ lua_newtable(L); ++ luaL_openlib(L, NULL, func, 0); ++ lua_settable(L, -3); ++ return 0; ++} ++ ++int if_global_indextoname(lua_State *L) ++{ ++ unsigned int ifnumber; ++ const char *name; ++ char buf[IF_NAMESIZE+1]; ++ ++ if (!lua_isnumber(L, 1)) ++ { ++ lua_pushnil(L); ++ lua_pushstring(L, "indextoname expects only number argument"); ++ return 2; ++ } ++ ifnumber = lua_tonumber(L, 1); ++ if (!(name = if_indextoname(ifnumber, buf))) ++ { ++ lua_pushnil(L); ++ lua_pushstring(L, "nonexistent interface"); ++ return 2; ++ } ++ lua_pushstring(L, name); ++ return 1; ++} ++ ++int if_global_nametoindex(lua_State *L) ++{ ++ unsigned int ifnumber; ++ if (!lua_isstring(L, 1)) ++ { ++ lua_pushnil(L); ++ lua_pushstring(L, "nametoindex expects only string argument"); ++ return 2; ++ } ++ if (!(ifnumber = if_nametoindex(lua_tostring(L, 1)))) ++ { ++ lua_pushnil(L); ++ lua_pushstring(L, "nonexistent interface"); ++ return 2; ++ } ++ lua_pushnumber(L, ifnumber); ++ return 1; ++} ++ ++int if_global_nameindex(lua_State *L) ++{ ++ struct if_nameindex *ni, *oni; ++ int i = 1; ++ oni = ni = if_nameindex(); ++ lua_newtable(L); ++ while (ni && ni->if_index && *(ni->if_name)) ++ { ++ /* at result[i], we store.. */ ++ lua_pushnumber(L, i); ++ ++ /* new table with two items - index, name*/ ++ lua_newtable(L); ++ lua_pushstring(L, "index"); ++ lua_pushnumber(L, ni->if_index); ++ lua_settable(L, -3); ++ ++ lua_pushstring(L, "name"); ++ lua_pushstring(L, ni->if_name); ++ lua_settable(L, -3); ++ ++ /* Then, actually store it */ ++ lua_settable(L, -3); ++ ++ i++; ++ ni++; ++ } ++ if_freenameindex(oni); ++ return 1; ++} +diff --git a/src/if.h b/src/if.h +new file mode 100644 +index 0000000..dc7faf8 +--- /dev/null ++++ b/src/if.h +@@ -0,0 +1,27 @@ ++/* ++ * $Id: if.h $ ++ * ++ * Author: Markus Stenberg ++ * ++ * Copyright (c) 2012 cisco Systems, Inc. ++ * ++ * Created: Tue Dec 4 14:37:24 2012 mstenber ++ * Last modified: Tue Dec 4 14:51:43 2012 mstenber ++ * Edit time: 7 min ++ * ++ */ ++ ++/* This module provides Lua wrapping for the advanced socket API ++ * defined in RFC3542, or mainly, the access to the system's interface ++ * list. It is necessary for use of recvmsg/sendmsg. ++ * ++ * TODO - Do something clever with Windows? ++ */ ++#ifndef IF_H ++#define IF_H ++ ++#include "lua.h" ++ ++int if_open(lua_State *L); ++ ++#endif /* IF_H */ +diff --git a/src/luasocket.c b/src/luasocket.c +index e6ee747..85d41a6 100644 +--- a/src/luasocket.c ++++ b/src/luasocket.c +@@ -31,6 +31,7 @@ + #include "tcp.h" + #include "udp.h" + #include "select.h" ++#include "if.h" + + /*-------------------------------------------------------------------------*\ + * Internal function prototypes +@@ -51,6 +52,7 @@ static const luaL_Reg mod[] = { + {"tcp", tcp_open}, + {"udp", udp_open}, + {"select", select_open}, ++ {"iface", if_open}, + {NULL, NULL} + }; + +diff --git a/src/makefile b/src/makefile +index 8d3521e..09d4882 100644 +--- a/src/makefile ++++ b/src/makefile +@@ -262,6 +262,7 @@ SOCKET_OBJS= \ + auxiliar.$(O) \ + options.$(O) \ + inet.$(O) \ ++ if.$(O) \ + $(SOCKET) \ + except.$(O) \ + select.$(O) \ +@@ -387,6 +388,7 @@ auxiliar.$(O): auxiliar.c auxiliar.h + buffer.$(O): buffer.c buffer.h io.h timeout.h + except.$(O): except.c except.h + inet.$(O): inet.c inet.h socket.h io.h timeout.h usocket.h ++if.$(O): if.c if.h + io.$(O): io.c io.h timeout.h + luasocket.$(O): luasocket.c luasocket.h auxiliar.h except.h \ + timeout.h buffer.h io.h inet.h socket.h usocket.h tcp.h \ +diff --git a/src/options.c b/src/options.c +index 8ac2a14..1c73e6f 100644 +--- a/src/options.c ++++ b/src/options.c +@@ -3,6 +3,9 @@ + * LuaSocket toolkit + \*=========================================================================*/ + #include ++#include ++#include ++#include + + #include "lauxlib.h" + +@@ -285,6 +288,12 @@ static int opt_ip6_setmembership(lua_State *L, p_socket ps, int level, int name) + if (!lua_isnil(L, -1)) { + if (lua_isnumber(L, -1)) { + val.ipv6mr_interface = (unsigned int) lua_tonumber(L, -1); ++ } else if (lua_isstring(L, -1)) { ++ if (!(val.ipv6mr_interface = if_nametoindex(lua_tostring(L, -1)))) { ++ lua_pushnil(L); ++ lua_pushstring(L, "nonexistent interface"); ++ return 2; ++ } + } else + luaL_argerror(L, -1, "number 'interface' field expected"); + } +-- +1.8.4.rc3 + -- 2.30.2