summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libnet/src/libnet_checksum.c2
-rw-r--r--lua/Makefile1
-rw-r--r--lua/net.c28
-rw-r--r--lua/test-igmp.lua47
4 files changed, 75 insertions, 3 deletions
diff --git a/libnet/src/libnet_checksum.c b/libnet/src/libnet_checksum.c
index 098b1f3..e3e3600 100644
--- a/libnet/src/libnet_checksum.c
+++ b/libnet/src/libnet_checksum.c
@@ -179,7 +179,7 @@ libnet_do_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len)
*
* iphdr is the pointer to it's encapsulating IP header
* protocol describes the type of "q", expressed as an IPPROTO_ value
- * len is the h_len from "q"
+ * h_len is the h_len from "q"
*/
int
libnet_inet_checksum(libnet_t *l, uint8_t *iphdr, int protocol, int h_len, const uint8_t *beg, const uint8_t * end)
diff --git a/lua/Makefile b/lua/Makefile
index a793210..d37eb81 100644
--- a/lua/Makefile
+++ b/lua/Makefile
@@ -22,7 +22,6 @@ install: $(BINDING)
../libnet/install-sh -t $(SODIR) $(BINDING)
CWARNS = -Wall \
- -pedantic \
-Wcast-align \
-Wnested-externs \
-Wpointer-arith \
diff --git a/lua/net.c b/lua/net.c
index 5c67e05..9b14897 100644
--- a/lua/net.c
+++ b/lua/net.c
@@ -32,7 +32,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
#include <time.h>
-#include <dumbnet.h>
+#include <dnet.h>
#include "libnet_decode.h"
#include <libnet.h>
@@ -558,6 +558,31 @@ static int lnet_data (lua_State *L)
}
/*-
+-- ptag = net:igmp{type=NUM, code=NUM, ip=IP, payload=STR, ptag=int}
+
+Build IGMP packet inside net context.
+
+ptag is optional, defaults to creating a new protocol block
+*/
+static int lnet_igmp (lua_State *L)
+{
+ libnet_t* ud = checkudata(L);
+ int type = v_arg_integer(L, 2, "type");
+ int code = v_arg_integer(L, 2, "code");
+ const char* ip = v_arg_string(L, 2, "ip");
+ uint32_t ip_n = check_ip_pton(L, ip, "ip");
+ uint32_t payloadsz = 0;
+ const uint8_t* payload = checkpayload(L, 2, &payloadsz);
+ int cksum = 0;
+ int ptag = lnet_arg_ptag(L, ud, 2, LIBNET_PBLOCK_IGMP_H);
+
+ ptag = libnet_build_igmp(type, code, cksum, ip_n, payload, payloadsz, ud, ptag);
+ check_error(L, ud, ptag);
+ lua_pushinteger(L, ptag);
+ return 1;
+}
+
+/*-
-- ptag = net:udp{src=NUM, dst=NUM, len=NUM, payload=STR, ptag=int}
Build UDP packet inside net context.
@@ -1364,6 +1389,7 @@ static const luaL_reg net_methods[] =
{"fd", lnet_getfd},
{"device", lnet_getdevice},
{"data", lnet_data},
+ {"igmp", lnet_igmp},
{"udp", lnet_udp},
{"get_udp", lnet_get_udp},
{"tcp", lnet_tcp},
diff --git a/lua/test-igmp.lua b/lua/test-igmp.lua
new file mode 100644
index 0000000..cb8e810
--- /dev/null
+++ b/lua/test-igmp.lua
@@ -0,0 +1,47 @@
+dofile"setup.lua"
+
+test("+igmp", function()
+ local n = net.init()
+ local igmpt = {type=3, code=5, ip="1.2.3.4"}
+ local ipt = {src="1.2.3.4", dst="5.6.7.8", protocol=2}
+ local etht = {src="01:02:03:01:02:03", dst="04:05:06:04:05:06"}
+ local pkt = "0405060405060102030102030800".. -- eth
+ "4500001c0000000040026acd0102030405060708".. -- ip
+ "0305f6f604030201" -- igmp
+
+ print" w/no-payload"
+
+ local gtag = n:igmp(igmpt)
+ local itag = n:ipv4(ipt)
+ local etag = n:eth(etht)
+ local b = n:block()
+
+ dump(n)
+
+ print("want", pkt)
+ print("have", h(b))
+
+ assert(pkt == h(b), h(b))
+
+ print"ok"
+
+ print" w/payload"
+
+ igmpt.payload = "\0\0\0"
+ igmpt.ptag = gtag
+
+ local gtag = n:igmp(igmpt)
+ local b = n:block()
+
+ dump(n)
+
+ print("want", pkt)
+ print("have", h(b))
+
+ assert(pkt.."000000" == h(b), h(b))
+
+ print"ok"
+
+ n:destroy()
+end)
+