From: Miek Gieben Date: Tue, 9 Aug 2005 13:33:14 +0000 (+0000) Subject: added recv upd to recv w/o sending a pkt X-Git-Tag: release-1.0.0~339 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a12659b58fa70acb601310cf558cf9d58ed90191;p=thirdparty%2Fldns.git added recv upd to recv w/o sending a pkt --- diff --git a/ldns/net.h b/ldns/net.h index 6152ac24..202ea919 100644 --- a/ldns/net.h +++ b/ldns/net.h @@ -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 d31e4445..3dbf7e55 100644 --- 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) {