--- /dev/null
+-- source the lib file with the function
+dofile("rns-lib.lua")
+
+-- echo whatever is received
+
+pkt = packet.new()
+
+rdf_ip = rdf.new_frm_str(LDNS_RDF_TYPE_A, "127.0.0.1")
+socket = udp.server_open(rdf_ip, 5353)
+if socket == nil then
+ os.exit(EXIT_FAILURE)
+end
+
+rdf_ip_nameserver = rdf.new_frm_str(LDNS_RDF_TYPE_A, "213.154.224.39")
+
+while true do
+ -- read from the socket, this blocks...
+ wirebuf, sockaddr_from = udp.read(socket)
+
+ -- wrap this in new functions
+ if wirebuf == nil then
+ lua_debug("nothing received")
+ else
+ -- somebody is writing
+ wirepkt = buffer.to_pkt(wirebuf)
+ packet.print(wirepkt)
+
+ wirebuf2 = packet.to_buf(wirepkt)
+
+ -- send it to /our/ nameserver
+ socket_nameserver = udp.open(rdf_ip_nameserver, 53)
+ if socket_nameserver == nil then
+ os.exit(EXIT_FAILURE)
+ end
+
+ nameserver_bytes = udp.write(socket_nameserver, wirebuf2, rdf_ip_nameserver, 53)
+ if nameserver_bytes == nil then
+ lua_debug("ns write error")
+ end
+
+ nameserver_buf, sockaddr_from_nameserver = udp.read(socket_nameserver)
+ udp.close(socket_nameserver)
+
+ nameserver_pkt = buffer.to_pkt(nameserver_buf)
+ lua_debug("received from the nameserver")
+ packet.print(nameserver_pkt)
+if true then
+
+ -- next we must send it to our recursive nameserver
+ -- and pick up the result
+ -- then we modify the result somewhat and sent it back
+ -- to the client
+
+ -- write back to the client
+ -- This is fishy
+ nsbuf2 = packet.to_buf(nameserver_pkt)
+ bytes = lua_udp_write(socket, nsbuf2, sockaddr_from)
+else
+ bytes = lua_udp_write(socket, wirebuf2, sockaddr_from)
+end
+ if bytes == nil then
+ lua_debug("write error")
+ else
+ lua_debug("wrote bytes", bytes)
+ packet.print(pkt)
+ end
+
+ end
+end
+udp.close(socket)
uint16_t t = (uint16_t)lua_tonumber(L, 1);
char *str = strdup((char*)luaL_checkstring(L, 2));
+ if (!str) {
+ return 0;
+ }
+
ldns_rdf *new_rdf = ldns_rdf_new_frm_str((ldns_rdf_type)t, str);
if (new_rdf) {
{
/* we always print to stdout */
ldns_rdf *toprint = (ldns_rdf*)lua_touserdata(L, 1); /* pop from the stack */
+ if (!toprint) {
+ return 0;
+ }
ldns_rdf_print(stdout, toprint);
return 0;
}
l_rdf_free(lua_State *L)
{
ldns_rdf *tofree = (ldns_rdf*)lua_touserdata(L, 1); /* pop from the stack */
+ if (!tofree) {
+ return 0;
+ }
ldns_rdf_free(tofree);
return 0;
}
char *str = strdup((char*)luaL_checkstring(L, 1));
uint16_t ttl = (uint16_t)lua_tonumber(L, 2);
ldns_rdf *orig = (ldns_rdf*)lua_touserdata(L, 2);
+
+ if (!str || !orig) {
+ return 0;
+ }
ldns_rr *new_rr = ldns_rr_new_frm_str(str, ttl, orig);
{
/* we always print to stdout */
ldns_rr *toprint = (ldns_rr*)lua_touserdata(L, 1); /* pop from the stack */
+ if (!toprint) {
+ return 0;
+ }
+
ldns_rr_print(stdout, toprint);
return 0;
}
l_rr_free(lua_State *L)
{
ldns_rr *tofree = (ldns_rr*)lua_touserdata(L, 1); /* pop from the stack */
+ if (!tofree) {
+ return 0;
+ }
ldns_rr_free(tofree);
return 0;
}
ldns_pkt_section s = (ldns_pkt_section)lua_tonumber(L, 2); /* the section where to put it */
ldns_rr *rr = (ldns_rr*)lua_touserdata(L, 3); /* the rr to put */
+ if (!pkt || !rr) {
+ return 0;
+ }
+
if (ldns_pkt_push_rr(pkt, s, rr)) {
lua_pushlightuserdata(L, pkt);
return 1;
ldns_rr *rr = (ldns_rr*)lua_touserdata(L, 2);
uint16_t n = (uint16_t)lua_tonumber(L, 3);
+ if (!p || !rr) {
+ return 0;
+ }
+
if(ldns_pkt_insert_rr(p, rr, n)) {
lua_pushlightuserdata(L, p);
return 1;
uint16_t n = (uint16_t) lua_tonumber(L, 2);
ldns_rr *r;
+ if (!p) {
+ return 0;
+ }
+
r = ldns_pkt_get_rr(p, n);
if (r) {
lua_pushlightuserdata(L, r);
uint16_t n = (uint16_t)lua_tonumber(L, 3);
ldns_rr *r;
+ if (!p || !rr) {
+ return 0;
+ }
+
r = ldns_pkt_set_rr(p, rr, n);
if (r) {
lua_pushlightuserdata(L, r);
{
/* we always print to stdout */
ldns_pkt *toprint = (ldns_pkt*)lua_touserdata(L, 1); /* pop from the stack */
+ if (!toprint) {
+ return 0;
+ }
ldns_pkt_print(stdout, toprint);
return 0;
}
size_t socklen;
int sockfd;
+ if (!ip || port == 0) {
+ return 0;
+ }
+
/* use default timeout - maybe this gets to be configureable */
timeout.tv_sec = LDNS_DEFAULT_TIMEOUT_SEC;
timeout.tv_usec = LDNS_DEFAULT_TIMEOUT_USEC;
{
int sockfd = (int)lua_tonumber(L, 1);
+ if (sockfd == 0) {
+ return 0;
+ }
+
close(sockfd);
}
ldns_buffer *pktbuf;
struct sockaddr_storage *from;
socklen_t from_len;
+
+ if (sockfd == 0) {
+ return 0;
+ }
from = LDNS_MALLOC(struct sockaddr_storage);
if (!from) {
l_pkt_qdcount(lua_State *L)
{
ldns_pkt *p = (ldns_pkt*)lua_touserdata(L, 1);
+ if (!p) {
+ return 0;
+ }
lua_pushnumber(L, (lua_Number)ldns_pkt_qdcount(p));
return 1;
}
l_pkt_ancount(lua_State *L)
{
ldns_pkt *p = (ldns_pkt*)lua_touserdata(L, 1);
+ if (!p) {
+ return 0;
+ }
lua_pushnumber(L, (lua_Number)ldns_pkt_ancount(p));
return 1;
}
l_pkt_nscount(lua_State *L)
{
ldns_pkt *p = (ldns_pkt*)lua_touserdata(L, 1);
+ if (!p) {
+ return 0;
+ }
lua_pushnumber(L, (lua_Number)ldns_pkt_nscount(p));
return 1;
}
l_pkt_arcount(lua_State *L)
{
ldns_pkt *p = (ldns_pkt*)lua_touserdata(L, 1);
+ if (!p) {
+ return 0;
+ }
lua_pushnumber(L, (lua_Number)ldns_pkt_arcount(p));
return 1;
}
{
ldns_pkt *p = (ldns_pkt*)lua_touserdata(L, 1);
uint16_t count = (uint16_t)lua_tonumber(L, 2);
+ if (!p) {
+ return 0;
+ }
(void)ldns_pkt_set_ancount(p, count);
return 0;
}
l_pkt_id(lua_State *L)
{
ldns_pkt *p = (ldns_pkt*)lua_touserdata(L, 1);
+ if (!p) {
+ return 0;
+ }
lua_pushnumber(L, (lua_Number)ldns_pkt_id(p));
return 1;
}
{
ldns_pkt *p = (ldns_pkt*)lua_touserdata(L, 1);
uint16_t id = (uint16_t)lua_tonumber(L, 2);
+ if (!p) {
+ return 0;
+ }
ldns_pkt_set_id(p, id);
return 0;
}
luaL_Buffer lua_b;
ldns_pkt *p = (ldns_pkt *)lua_touserdata(L, 1);
+ if (!p) {
+ return 0;
+ }
+
b = ldns_buffer_new(LDNS_MAX_PACKETLEN);
luaL_buffinit(L,&lua_b);
ldns_rdf *addr;
sock = lua_touserdata(L, 1);
+ if (!sock) {
+ return 0;
+ }
addr = ldns_sockaddr_storage2rdf(sock, &port);
if (addr) {