]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
added recv upd to recv w/o sending a pkt
authorMiek Gieben <miekg@NLnetLabs.nl>
Tue, 9 Aug 2005 13:33:14 +0000 (13:33 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Tue, 9 Aug 2005 13:33:14 +0000 (13:33 +0000)
ldns/net.h
net.c

index 6152ac24d30e6e68908c4283c8a12d01c0013b16..202ea919d56f61c08ebeecb099224f9893232a47 100644 (file)
@@ -66,7 +66,7 @@ int ldns_tcp_connect(const struct sockaddr_storage *to, socklen_t tolen, struct
 ssize_t ldns_tcp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen);
 
 /**
- * Creates a new ldns_pkt structure and reads the header data from the given
+ * 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
  *
  * \param[in] sockfd the socket to read from
@@ -75,4 +75,14 @@ ssize_t ldns_tcp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr
  */
 uint8_t *ldns_tcp_read_wire(int sockfd, size_t *size);
 
+/**
+ * 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
+ *
+ * \param[in] sockfd the socket to read from
+ * \param[out] size the number of bytes that are read
+ * \return the data read
+ */
+uint8_t *ldns_udp_read_wire(int sockfd, size_t *size);
+
 #endif  /* !_LDNS_NET_H */
diff --git a/net.c b/net.c
index d31e444539e4e21e299611eaf2103f10f3db5562..3dbf7e552cd6afacec4a21272e9a42fa9e72b6ca 100644 (file)
--- a/net.c
+++ b/net.c
@@ -315,6 +315,29 @@ ldns_tcp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage
        return bytes;
 }
 
+uint8_t *
+ldns_udp_read_wire(int sockfd, size_t *size)
+{
+       uint8_t *wire;
+       int16_t wire_size;
+
+       wire = LDNS_XMALLOC(uint8_t, LDNS_MAX_PACKETLEN);
+
+       wire_size = recv(sockfd, wire, LDNS_MAX_PACKETLEN, 0);
+
+       if (wire_size == -1) {
+               if (errno == EAGAIN) {
+                       dprintf("%s", "socket timeout\n");
+               }
+               perror("error receiving tcp packet");
+               return NULL;
+       }
+
+       *size = (size_t) wire_size;
+
+       return wire;
+}
+
 uint8_t *
 ldns_tcp_read_wire(int sockfd, size_t *size)
 {