void
usage(FILE *f, char *progname)
{
- fprintf(f, "Synopsis: %s lua-file\n", progname);
- fprintf(f, " Useless bunch of other options\n");
+ fprintf(f, "Synopsis: %s lua-script\n", progname);
+ fprintf(f, " No options are defined (yet)\n");
}
void
/*
============
- EXAMPLES
+ CONVERSION
============
*/
+static int
+l_pkt2string(lua_State *L)
+{
+ ldns_buffer *b;
+ luaL_Buffer lua_b;
+ ldns_pkt *p = (ldns_pkt *)lua_touserdata(L, 1);
+
+ b = ldns_buffer_new(LDNS_MAX_PACKETLEN);
+ luaL_buffinit(L,&lua_b);
+
+ if (ldns_pkt2buffer_wire(b, p) != LDNS_STATUS_OK) {
+ ldns_buffer_free(b);
+ return 0;
+ }
+ printf("how is this comming along %d\n", ldns_buffer_capacity(b));
+
+ /* this is a memcpy??? */
+ luaL_addlstring(&lua_b,
+ ldns_buffer_begin(b),
+ ldns_buffer_capacity(b)
+ );
+ /* I hope so */
+ ldns_buffer_free(b);
+
+ luaL_pushresult(&lua_b);
+ return 1;
+}
+
+/*
+============
+ EXAMPLES
+============
+*/
-/* Example test function which doesn't call ldns stuff yet */
static int
l_average(lua_State *L)
{
lua_register(L, "l_pkt_get_rr", l_pkt_get_rr);
lua_register(L, "l_pkt_set_rr", l_pkt_set_rr);
lua_register(L, "l_pkt_rr_count", l_pkt_rr_count);
+ /* CONVERSIONs */
+ lua_register(L, "l_pkt2string", l_pkt2string);
}
int
lua_baselibopen(L);
luaopen_math(L);
luaopen_io(L);
+ luaopen_string(L);
register_ldns_functions();
LDNS_SECTION_ANY_NOQUESTION = 5
-- dofile (filename)
--- swap 2 rrs in a pkt --
+-- transpose 2 rrs in a pkt --
function lua_transpose_rr(pkt, n1, n2)
print("[info] [RR] transpose", n1, n2)
local rr_n1 = l_pkt_get_rr(pkt, n1)
local total = l_pkt_rr_count(pkt) - 1
local rn1 = math.random(0, total)
local rn2 = math.random(0, total)
- lua_swap_rr(pkt, rn1, rn2)
+ lua_transpose_rr(pkt, rn1, rn2)
end
--- substiture, add, remove
+-- substitute, add, remove
+
+-- add an rr to the end of a pkt --
+function lua_add_rr(pkt, r)
+ print("[info] [RR] add", "end")
+ -- special case of insert ...
+end
+
+-- remove an rr from the end of a pkt --
+function lua_remove_rr(pkt, n)
+ print("[info] [RR] remove", "end")
+end
+
+-- convert a ldns_buffer to a string in lua
+function lua_buf_to_string(buf)
+end
---------------------------------
--- these are more higher level --
+-- higher level --
---------------------------------
-- reverse all the rrs in a pkt --
function lua_reverse_pkt(pkt)
local total = l_pkt_rr_count(pkt) - 1
for i=0, (total / 2) do
- lua_swap_rr(pkt, i, total - i)
+ lua_transpose_rr(pkt, i, total - i)
end
end