]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
somehow somewhere,the lua stuff crashes while plain ldns does not
authorMiek Gieben <miekg@NLnetLabs.nl>
Thu, 11 Aug 2005 13:43:06 +0000 (13:43 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Thu, 11 Aug 2005 13:43:06 +0000 (13:43 +0000)
Last updates for ldns networking, except for the lua-net-bug fix

buffer.c
ldns/buffer.h
lua/lua-rns.c
lua/rns.lua
net.c
wire2host.c

index a34e344a23f84a24edf82ab52b2d36498ef17f64..ca97f2d371bcd4f1a6eef0016c5533430b7b8bd1 100644 (file)
--- a/buffer.c
+++ b/buffer.c
@@ -47,7 +47,7 @@ ldns_buffer_new_frm_data(ldns_buffer *buffer, void *data, size_t size)
        buffer->_limit = buffer->_capacity = size;
        buffer->_data = LDNS_XMALLOC(uint8_t, size);
        memcpy(buffer->_data, data, size);
-       buffer->_fixed = 1;
+       buffer->_fixed = 0;
        buffer->_status = LDNS_STATUS_OK;
        
        ldns_buffer_invariant(buffer);
index f2f34cd53d222da55c9a18f1a20f342159ecd336..51a368dc8c56d4f54d935b12914cba6144e30337 100644 (file)
@@ -79,8 +79,8 @@ ldns_buffer_invariant(ldns_buffer *buffer)
 ldns_buffer *ldns_buffer_new(size_t capacity);
 
 /**
- * creates a buffer with the specified data.  The data is not copied
- * and no memory allocations are done.  The buffer is fixed and cannot
+ * creates a buffer with the specified data.  The data IS copied
+ * and MEMORY allocations are done.  The buffer is not fixed and can
  * be resized using buffer_reserve().
  *
  * \param[in] buffer pointer to the buffer to put the data in
index 04efdb3c10ea7a2d3c8cdb9a3648000fc5125258..40e6f16c641ed15a7dc5fb3c20096eaf62a30679 100644 (file)
@@ -305,14 +305,6 @@ l_write_wire_udp(lua_State *L)
        }
 }
 
-
-/***
- * read "something" from the wire and try to return 
- * a packet of it
- * I rather have this as a string that lua/rns can transform
- * We'll see what pops up in writting the other bits and see how
- * this will be effected
- */
 static int
 l_read_wire_udp(lua_State *L)
 {
@@ -323,13 +315,18 @@ l_read_wire_udp(lua_State *L)
        ldns_buffer *pktbuf;
 
        pktbuf_raw = ldns_udp_read_wire(sockfd, &size);
+
        if (!pktbuf_raw) {
+               printf("[debug] nothing allright\n");
                return 0;
        }
        ldns_buffer_new_frm_data(pktbuf, pktbuf_raw, size);
+
        LDNS_FREE(pktbuf_raw);
        
        /* push our buffer onto the stack */
+       printf("[debug] I've read %d bytes\n", size);
+       printf("[debug] buffer cap %d bytes\n", ldns_buffer_capacity(pktbuf));
        lua_pushlightuserdata(L, pktbuf);
        return 1;
 }
@@ -386,9 +383,15 @@ l_buf2pkt(lua_State *L)
        ldns_buffer *b = (ldns_buffer *)lua_touserdata(L, 1);
        ldns_pkt *p;
 
+       if (!b) {
+               return 0;
+       }
+
        if (ldns_buffer2pkt_wire(&p, b) != LDNS_STATUS_OK) {
+               printf("[debug] conversion buf2pkt sour\n");
                return 0;
        }
+       printf("[debug] conversion buf2pkt ok\n");
        
        lua_pushlightuserdata(L, p);
        return 1;
@@ -400,12 +403,19 @@ l_pkt2buf(lua_State *L)
        ldns_pkt *p = (ldns_pkt *)lua_touserdata(L, 1);
        ldns_buffer *b;
 
+       if (!p) {
+               return 0;
+       }
+
        /* resize! XXX */
        b = ldns_buffer_new(LDNS_MAX_PACKETLEN);
-
        if (ldns_pkt2buffer_wire(b, p) != LDNS_STATUS_OK) {
                return 0;
        }
+       /* resize to current usage */
+       printf("[debug] usage buffer %d\n", ldns_buffer_position(b));
+       ldns_buffer_reserve(b, (size_t)
+                       ldns_buffer_position(b));
        lua_pushlightuserdata(L, b);
        return 1;
 }
index 8dfe3e2a10124c671fd71a3c8869fe42d0bd5c6c..e5f43fd88a6e7ca8d306e55b7d7a488e28538e2b 100644 (file)
@@ -45,18 +45,19 @@ l_pkt_print(pkt)
 rdf_ip = l_rdf_new_frm_str(LDNS_RDF_TYPE_A, "127.0.0.1")
 -- connect and bind to a server udp socket
 socket = l_server_socket_udp(rdf_ip, 5353)
+--
 -- read from the socket
 wirebuf = l_read_wire_udp(socket)
-lua_debug("what I read")
-print(wirebuf)
+--lua_debug("what I read")
 -- close the socket
 l_server_socket_close_udp(socket)
 -- convert the packet
 
-if not wirebuf == nil then
-       lua_debug("I shouldn't be here")
-       wirepkt = l_buf2pkt(wirebuf)
-       -- print the packet
-       l_pkt_print(wirepkt)
-end
-lua_debug("Then end")
+
+--if not wirebuf == nil then
+--     lua_debug("I shouldn't be here")
+--     wirepkt = l_buf2pkt(wirebuf)
+--     -- print the packet
+--     l_pkt_print(wirepkt)
+--end
+lua_debug("The end")
diff --git a/net.c b/net.c
index e656e90d03a0785547f1309a4d69d31b9ccc916b..2c69e6e611c385755e4f9a804f59275983c0faaa 100644 (file)
--- a/net.c
+++ b/net.c
@@ -332,6 +332,10 @@ ldns_udp_read_wire(int sockfd, size_t *size)
        ssize_t wire_size;
 
        wire = LDNS_XMALLOC(uint8_t, LDNS_MAX_PACKETLEN);
+       if (!wire) {
+               *size = 0;
+               return NULL;
+       }
 
        wire_size = recv(sockfd, wire, LDNS_MAX_PACKETLEN, 0);
        /* recvfrom here .. */
@@ -340,13 +344,13 @@ ldns_udp_read_wire(int sockfd, size_t *size)
                if (errno == EAGAIN) {
                        dprintf("%s", "socket timeout\n");
                }
+               *size = 0;
                perror("error receiving udp packet");
                return NULL;
        }
 
        *size = (size_t)wire_size;
        wire = LDNS_XREALLOC(wire, uint8_t, (size_t)wire_size);
-
        return wire;
 }
 
@@ -358,6 +362,11 @@ ldns_tcp_read_wire(int sockfd, size_t *size)
        ssize_t bytes = 0;
 
        wire = LDNS_XMALLOC(uint8_t, 2);
+       if (!wire) {
+               *size = 0;
+               return NULL;
+       }
+       
        while (bytes < 2) {
                bytes = recv(sockfd, wire, 2, 0);
                if (bytes == -1) {
@@ -365,6 +374,7 @@ ldns_tcp_read_wire(int sockfd, size_t *size)
                                dprintf("%s", "socket timeout\n");
                        }
                        perror("error receiving tcp packet");
+                       *size = 0;
                        return NULL;
                }
        }
@@ -383,6 +393,7 @@ ldns_tcp_read_wire(int sockfd, size_t *size)
                        }
                        perror("error receiving tcp packet");
                        LDNS_FREE(wire);
+                       *size = 0;
                        return NULL;
                }
        }
index 2adec1e15068c86236986d8c63149c08263454de..ce3df4c1ecf1d9c84a1e3a0df1b0ea38da52da84 100644 (file)
@@ -344,7 +344,6 @@ ldns_buffer2pkt_wire(ldns_pkt **packet, ldns_buffer *buffer)
 
 }
 
-
 ldns_status
 ldns_wire2pkt(ldns_pkt **packet_p, const uint8_t *wire, size_t max)
 {