]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
adding some udp equivs for the tcp send/receive stuff. Good for lua, good for making...
authorMiek Gieben <miekg@NLnetLabs.nl>
Tue, 9 Aug 2005 13:42:08 +0000 (13:42 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Tue, 9 Aug 2005 13:42:08 +0000 (13:42 +0000)
ldns/net.h
lua/rns-lib.lua
net.c

index 202ea919d56f61c08ebeecb099224f9893232a47..4741571faf08ba82d1b01ffb5781639784c37d03 100644 (file)
@@ -63,8 +63,27 @@ ldns_status ldns_send(ldns_pkt **pkt, ldns_resolver *r, ldns_pkt *query_pkt);
  */
 int ldns_tcp_connect(const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
 
+/**
+ * send a query via tcp to a server. Don;t want for the answer
+ *
+ * \param[in] qbin the buffer to send
+ * \param[in] sockfd the socket to use
+ * \param[in] to which ip to send it
+ * \param[in] tolen socketlen
+ * \return number of bytes sent
+ */
 ssize_t ldns_tcp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen);
 
+/**
+ * send a query via udp to a server. Don;t want for the answer
+ *
+ * \param[in] qbin the buffer to send
+ * \param[in] sockfd the socket to use
+ * \param[in] to which ip to send it
+ * \param[in] tolen socketlen
+ * \return number of bytes sent
+ */
+ssize_t ldns_udp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen);
 /**
  * Gives back a raw packet from the wire and reads the header data from the given
  * socket. Allocates the data (of size size) itself, so don't forget to free
index e7266efb376c75fb68288fd37a7f56e2c999297b..581f8bfc283152129da8cb70ef5eecf539aef672 100644 (file)
@@ -6,7 +6,12 @@ LDNS_SECTION_ADDITIONAL        = 3
 LDNS_SECTION_ANY               = 4
 LDNS_SECTION_ANY_NOQUESTION    = 5
 
--- dofile (filename)
+-- read a pkt from the wire
+function lua_recv_pkt()
+       
+end
+
+
 -- transpose 2 rrs in a pkt --
 function lua_transpose_rr(pkt, n1, n2)
        print("[info] [RR] transpose", n1, n2)
diff --git a/net.c b/net.c
index 3dbf7e552cd6afacec4a21272e9a42fa9e72b6ca..f66ea12fa2332fc9e546b91975fd3791e1d9487c 100644 (file)
--- a/net.c
+++ b/net.c
@@ -315,6 +315,36 @@ ldns_tcp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage
        return bytes;
 }
 
+ssize_t
+ldns_udp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen)
+{
+       uint8_t *sendbuf;
+       ssize_t bytes;
+
+       /* add length of packet */
+       sendbuf = LDNS_XMALLOC(uint8_t, ldns_buffer_position(qbin) + 2);
+       ldns_write_uint16(sendbuf, ldns_buffer_position(qbin));
+       memcpy(sendbuf+2, ldns_buffer_export(qbin), ldns_buffer_position(qbin));
+
+       bytes = sendto(sockfd, sendbuf,
+                       ldns_buffer_position(qbin)+2, 0, (struct sockaddr *)to, tolen);
+
+        LDNS_FREE(sendbuf);
+
+       if (bytes == -1) {
+               dprintf("%s", "error with sending\n");
+               close(sockfd);
+               return 0;
+       }
+       if ((size_t) bytes != ldns_buffer_position(qbin)+2) {
+               dprintf("%s", "amount of sent bytes mismatch\n");
+               close(sockfd);
+               return 0;
+       }
+       
+       return bytes;
+}
+
 uint8_t *
 ldns_udp_read_wire(int sockfd, size_t *size)
 {