diff options
author | Kelvie Wong <kwong@wurldtech.com> | 2011-04-18 12:12:57 -0700 |
---|---|---|
committer | Kelvie Wong <kwong@wurldtech.com> | 2011-04-18 12:12:57 -0700 |
commit | 3e705c5a16f1196f447989b14d0d86639f47c0fa (patch) | |
tree | 78b2df51fbbf6608684e3cc301a6c2c595f87518 | |
parent | 6062e32c2630eaf65e1d6dab90d5fcabf136c2c0 (diff) | |
parent | 4aac7af2c41d3381c424020824b56fdb5baa0706 (diff) | |
download | libnet-3e705c5a16f1196f447989b14d0d86639f47c0fa.tar.gz |
Merge branch 'master' of https://github.com/sam-github/libnet
-rw-r--r-- | lua/net.c | 75 |
1 files changed, 42 insertions, 33 deletions
@@ -313,7 +313,7 @@ static const char* type_string(u_int8_t type) } /*- -- net:destroy() +-- net:destroy() Manually destroy a net object, freeing it's resources (this will happen on garbage collection if not done explicitly). @@ -331,7 +331,7 @@ static int lnet_destroy (lua_State *L) } /*- -- net = net:clear() +-- net = net:clear() Clear the current packet and all it's protocol blocks. @@ -348,14 +348,15 @@ static int lnet_clear(lua_State* L) } /*- -- str = net:block([ptag]) +-- str = net:block([ptag]) Coalesce the protocol blocks into a single chunk, and return. If a ptag is provided, just return data of that pblock (no checksums will be calculated). - -FIXME - we should just have a packet function, this fails on single blocks, +*/ +/* +FIXME - we should just have a packet function, this fails on single blocks/ptags, and the :pblock() method is better, anyway. */ static int lnet_block(lua_State* L) @@ -392,7 +393,7 @@ static int lnet_block(lua_State* L) } /*- -- net:pbuf(ptag) +-- net:pbuf(ptag) */ static int lnet_pbuf(lua_State* L) { @@ -410,7 +411,7 @@ static int lnet_pbuf(lua_State* L) } /*- -- net:write() +-- net:write() Write the packet (which must previously have been built up inside the context). */ @@ -428,6 +429,14 @@ static int lnet_write(lua_State *L) return 1; } +/*- +-- size = net:write_link(link_pdu) + +Writes link_pdu raw at the link layer, you are responsible for forming +the link-layer header. + +Returns the size written on success. +*/ static int lnet_write_link (lua_State *L) { libnet_t* ud = checkudata(L); @@ -436,12 +445,13 @@ static int lnet_write_link (lua_State *L) uint32_t payloadsz = (uint32_t) payloadsz_; const uint8_t* payload = (const uint8_t*) payload_; int size = libnet_write_link(ud, payload, payloadsz); + check_error(L, ud, size); lua_pushinteger(L, size); return 1; } /*- -- net:tag_below(ptag) +-- net:tag_below(ptag) tag below ptag, or bottom tag if ptag is nil */ @@ -460,7 +470,7 @@ static int lnet_tag_below(lua_State* L) } /*- -- net:tag_above(ptag) +-- net:tag_above(ptag) tag above ptag, or top tag if ptag is nil */ @@ -493,7 +503,7 @@ static int lnet_tag_type(lua_State* L) } /*- -- net:fd() +-- net:fd() Get the fileno of the underlying file descriptor. */ @@ -505,7 +515,7 @@ static int lnet_getfd(lua_State* L) } /*- -- net:device() +-- net:device() Get the device name, maybe be nil. */ @@ -528,7 +538,7 @@ static int lnet_getdevice(lua_State* L) */ /*- -- ptag = net:data{payload=STR, ptag=int} +-- ptag = net:data{payload=STR, ptag=int} Build generic data packet inside net context. @@ -548,7 +558,7 @@ static int lnet_data (lua_State *L) } /*- -- ptag = net:udp{src=NUM, dst=NUM, len=NUM, payload=STR, ptag=int} +-- ptag = net:udp{src=NUM, dst=NUM, len=NUM, payload=STR, ptag=int} Build UDP packet inside net context. @@ -604,12 +614,12 @@ checkptype(lua_State* L, libnet_t* l, uint8_t type) } /*- -- argt = net:get_udp() +-- argt = net:get_udp() Get udp pblock argument table. -TODO - optional ptag argument? */ +/* TODO - optional ptag argument? */ static int lnet_get_udp(lua_State *L) { libnet_t* ud = checkudata(L); @@ -635,7 +645,7 @@ static int lnet_get_udp(lua_State *L) } /*- -- ptag = n:tcp{ +-- ptag = n:tcp{ -- required arguments src=port, dst=port, @@ -730,12 +740,12 @@ static int lnet_tcp (lua_State *L) } /*- -- argt = net:get_tcp() +-- argt = net:get_tcp() Get tcp pblock argument table. - -TODO - optional ptag argument? */ + +/* TODO - optional ptag argument? */ static int lnet_get_tcp (lua_State *L) { libnet_t* ud = checkudata(L); @@ -783,7 +793,7 @@ static int lnet_get_tcp (lua_State *L) /*- -- ptag = n:ipv4{ +-- ptag = n:ipv4{ -- required arguments src=ipaddr, dst=ipaddr, @@ -940,12 +950,11 @@ ptag = 1, protocol = 1, _iphl = 5, id = 0, options = "", dst = "1.1.1.1", src = } /*- -- argt = net:get_ipv4() +-- argt = net:get_ipv4() Get ipv4 pblock argument table. - -TODO - optional ptag argument? */ +/* TODO - optional ptag argument? */ static int lnet_get_ipv4 (lua_State *L) { libnet_t* ud = checkudata(L); @@ -1005,7 +1014,7 @@ static int lnet_get_ipv4 (lua_State *L) /*- -- ptag = n:eth{src=ethmac, dst=ethmac, type=int, payload=str, ptag=int} +-- ptag = n:eth{src=ethmac, dst=ethmac, type=int, payload=str, ptag=int} type is optional, defaults to IP ptag is optional, defaults to creating a new protocol block @@ -1036,7 +1045,7 @@ static int lnet_eth (lua_State *L) /*- -- argt = net:get_eth() +-- argt = net:get_eth() Get eth pblock argument table. */ @@ -1129,7 +1138,7 @@ static void pushpblock(lua_State* L, libnet_pblock_t* pblock) } /*- -- net:pblock(lua_State* L, int ptag) +-- net:pblock(lua_State* L, int ptag) Get a table with all the pblock info in it. */ @@ -1142,7 +1151,7 @@ static int lnet_pblock(lua_State* L) } /*- -- net:dump() +-- net:dump() Write summary of protocol blocks to stdout. */ @@ -1186,7 +1195,7 @@ void dump(lua_State* L) { /* TODO net.ntop() take either a number (a host u32 inet addr), or a string of bytes, and convert to presentation */ /*- -- network = net.pton(presentation) +-- network = net.pton(presentation) presentation is something like "df:33:44:12:45:54", or "1.2.3.4", or a host name @@ -1212,7 +1221,7 @@ static int lnet_pton(lua_State *L) } /*- -- n = net.htons(h) +-- n = net.htons(h) Return a network byte order encoding of number, h. */ @@ -1232,7 +1241,7 @@ static int lnet_htons(lua_State *L) } /*- -- sum = net.checksum(string, ...) +-- sum = net.checksum(string, ...) Checksum the series of strings passed in. */ @@ -1257,9 +1266,9 @@ static int lnet_chksum(lua_State *L) } /*- -- remaining = net.nanosleep(seconds) +-- remaining = net.nanosleep(seconds) -Seconds can be decimal (resolution is nanoseconds, theoretically). +Seconds can be smaller than 1 (resolution is nanoseconds, theoretically). Return is number of seconds not slept, or nil and an error message on failure. remaining = assert(net.nanosleep(seconds)) @@ -1306,7 +1315,7 @@ static int lnet_gettimeofday(lua_State *L) } /*- -- net.init(injection, device) +-- net.init(injection, device) injection is one of "link", "raw", ... device is "eth0", ... |