From: Miek Gieben Date: Wed, 24 Aug 2005 08:13:57 +0000 (+0000) Subject: naming/syntax X-Git-Tag: release-1.0.0~253 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6c4834649ced6128ef083eec3aad94e14097d09a;p=thirdparty%2Fldns.git naming/syntax --- diff --git a/lua/rns-lib.lua b/lua/rns-lib.lua index e3f7ae00..6f5de2e4 100644 --- a/lua/rns-lib.lua +++ b/lua/rns-lib.lua @@ -42,41 +42,44 @@ function lua_debug(...) end -- transpose 2 rrs in a pkt -- -function lua_transpose_rr(pkt, n1, n2) +function lua_record_transpose(pkt, n1, n2) print("[info] [RR] transpose", n1, n2) local rr_n1 = packet.get_rr(pkt, n1) local rr_n2 = packet.set_rr(pkt, rr_n1, n2) local rr_tm = packet.set_rr(pkt, rr_n2, n1) - l_rr_free(rm_tm) + record.free(rm_tm) end -function lua_transpose_rr_random(pkt) +-- _R := random +function lua_record_transpose_R(pkt) local total = packet.rrcount(pkt) - 1 local rn1 = math.random(0, total) local rn2 = math.random(0, total) - lua_transpose_rr(pkt, rn1, rn2) + lua_transpose_record(pkt, rn1, rn2) end -- substitute, add, remove -function lua_insert_rr(pkt, r, n) +function lua_record_insert(pkt, r, n) print("[info] [RR] insert after", n) - packet.insert_rr(pkt, r, n) + packet.insert_record(pkt, r, n) end -- add an rr to the end of a pkt -- -function lua_insert_end_rr(pkt, r) - local n = packet.rr_count(pkt) - 1 +-- _E := end +function lua_record_insert_E(pkt, r) + local n = packet.rrcount(pkt) - 1 print(n) - lua_insert_rr(pkt, r, n) + lua_insert_record(pkt, r, n) end -- remove an rr from the end of a pkt -- -function lua_remove_rr(pkt, n) +--pop?? +function lua_record_remove_E(pkt, n) print("[info] [RR] remove", "end") end -- increment the ancount -function lua_ancount_incr(pkt, n) +function lua_packet_ancount_incr(pkt, n) print("[info] [PKT] ancount incr", n) an = packet.ancount(pkt) n = an + n @@ -88,13 +91,30 @@ end --------------------------------- -- reverse all the rrs in a pkt -- -function lua_reverse_pkt(pkt) +function lua_packet_reverse(pkt) local total = packet.rrcount(pkt) - 1 for i=0, (total / 2) do lua_transpose_rr(pkt, i, total - i) end end +-- write a buffer to a socket +function lua_udp_write(socket, buffer_wire, sock_from) + -- convert the sockaddr_storage to something we + -- can work with + + -- checks + if socket == 0 then return -1 end + if buffer_wire == nil then return -1 end + if sock_from == nil then return -1 end + + rdf_listen, port_listen = rdf.sockaddr_to_rdf(sock_from) + + bytes = udp.write(socket, buffer_wire, rdf_listen, port_listen) + return bytes +end + + -- initialize the pseudo random number generator -- frm: http://lua-users.org/wiki/MathLibraryTutorial function lua_rand_init() @@ -103,5 +123,4 @@ function lua_rand_init() math.random() math.random() end - lua_rand_init() diff --git a/lua/rns.lua b/lua/rns.lua index 020404b1..0727df1b 100644 --- a/lua/rns.lua +++ b/lua/rns.lua @@ -36,14 +36,16 @@ else -- set the id on the outgoing packet packet.set_id(pkt, id) - lua_ancount_incr(pkt, 100) + lua_packet_ancount_incr(pkt, 2) wirebuf2 = packet.to_buf(pkt) - rdf_listen, port_listen = rdf.sockaddr_to_rdf(sockaddr_from) - - bytes = udp.write(socket, wirebuf2, rdf_listen, port_listen) -- this works - lua_debug("wrote bytes", bytes) - packet.print(pkt) + bytes = lua_udp_write(socket, wirebuf2, sockaddr_from) + if bytes == -1 then + lua_debug("write error") + else + lua_debug("wrote bytes", bytes) + packet.print(pkt) + end end diff --git a/lua/test.lua b/lua/test.lua index 6f7cbf45..f2bc9bc8 100644 --- a/lua/test.lua +++ b/lua/test.lua @@ -2,32 +2,31 @@ dofile("rns-lib.lua") -- Now the scary ldns_* stuff -my_rr2 = l_rr_new_frm_str("www.miek.nl") -my_rr = l_rr_new_frm_str("www.miek.nl IN A 192.168.1.2") -my_rr4 = l_rr_new_frm_str("www.atoom.net. IN A 192.168.1.2") +my_rr2 = record.new_frm_str("www.miek.nl") +my_rr = record.new_frm_str("www.miek.nl IN A 192.168.1.2") +my_rr4 = record.new_frm_str("www.atoom.net. IN A 192.168.1.2") -l_rr_print(my_rr) -l_rr_print(my_rr2) -l_rr_print(my_rr4) +record.print(my_rr) +record.print(my_rr2) +record.print(my_rr4) ---my_pkt = l_pkt_new() -my_pkt = pkt.new(); +my_pkt = packet.new(); -my_pkt = l_pkt_push_rr(my_pkt, LDNS_SECTION_ANSWER, my_rr) +my_pkt = packet.push_rr(my_pkt, LDNS_SECTION_ANSWER, my_rr) -l_pkt_print(my_pkt) +packet.print(my_pkt) -my_pkt = l_pkt_push_rr(my_pkt, LDNS_SECTION_ANSWER, my_rr2) +my_pkt = packet.push_rr(my_pkt, LDNS_SECTION_ANSWER, my_rr2) -my_rr3 = l_pkt_get_rr(my_pkt, 0); -l_rr_print(my_rr3) -my_rr3 = l_pkt_get_rr(my_pkt, 1); -l_rr_print(my_rr3) +my_rr3 = packet.get_rr(my_pkt, 0); +record.print(my_rr3) +my_rr3 = packet.get_rr(my_pkt, 1); +record.print(my_rr3) -l_pkt_print(my_pkt) -my_rr5 = l_pkt_set_rr(my_pkt, my_rr4, 1) -l_rr_print(my_rr5) +packet.print(my_pkt) +my_rr5 = packet.set_rr(my_pkt, my_rr4, 1) +record.print(my_rr5) -l_pkt_set_id(my_pkt, 1505) +packet.set_id(my_pkt, 1505) -l_pkt_print(my_pkt) +packet.print(my_pkt) diff --git a/lua/test2.lua b/lua/test2.lua index c2ca5ad8..fc804956 100644 --- a/lua/test2.lua +++ b/lua/test2.lua @@ -1,4 +1,4 @@ -- source the lib file with the function dofile("rns-lib.lua") -my_pkt = pkt.new(); +my_pkt = packet.new();