* bug273: fix so EDNS rdata is included in pkt to wire conversion.
* bug274: fix use of c++ keyword 'class' for RR class in the code.
* bug275: fix memory leak of packet edns rdata.
+ * Fix timeout procedure for TCP and AXFR on Solaris.
1.6.1 2009-09-14
* --enable-gost : use the GOST algorithm (experimental).
* \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
+ *
+ * \param[in] sockfd the socket to read from
+ * \param[out] size the number of bytes that are read
+ * \param[in] timeout the time allowed between packets.
+ * \return the data read
+ */
+uint8_t *ldns_tcp_read_wire_timeout(int sockfd, size_t *size, struct timeval timeout);
+
/**
+ * *DEPRECATED* please use ldns_tcp_read_wire_timeout, that checks for timeouts.
* 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
*
return wire;
}
+uint8_t *
+ldns_tcp_read_wire_timeout(int sockfd, size_t *size, struct timeval timeout)
+{
+ uint8_t *wire;
+ uint16_t wire_size;
+ ssize_t bytes = 0;
+
+ wire = LDNS_XMALLOC(uint8_t, 2);
+ if (!wire) {
+ *size = 0;
+ return NULL;
+ }
+
+ while (bytes < 2) {
+ if(!ldns_sock_wait(sockfd, timeout, 0)) {
+ *size = 0;
+ LDNS_FREE(wire);
+ return NULL;
+ }
+ bytes = recv(sockfd, (void*)wire, 2, 0);
+ if (bytes == -1 || bytes == 0) {
+ *size = 0;
+ LDNS_FREE(wire);
+ return NULL;
+ }
+ }
+
+ wire_size = ldns_read_uint16(wire);
+
+ LDNS_FREE(wire);
+ wire = LDNS_XMALLOC(uint8_t, wire_size);
+ bytes = 0;
+
+ while (bytes < (ssize_t) wire_size) {
+ if(!ldns_sock_wait(sockfd, timeout, 0)) {
+ *size = 0;
+ LDNS_FREE(wire);
+ return NULL;
+ }
+ bytes += recv(sockfd, (void*) (wire + bytes),
+ (size_t) (wire_size - bytes), 0);
+ if (bytes == -1 || bytes == 0) {
+ LDNS_FREE(wire);
+ *size = 0;
+ return NULL;
+ }
+ }
+
+ *size = (size_t) bytes;
+ return wire;
+}
+
uint8_t *
ldns_tcp_read_wire(int sockfd, size_t *size)
{
return LDNS_STATUS_ERR;
}
- if(!ldns_sock_wait(sockfd, timeout, 0)) {
- close(sockfd);
- return LDNS_STATUS_NETWORK_ERR;
- }
-
- answer = ldns_tcp_read_wire(sockfd, answer_size);
+ answer = ldns_tcp_read_wire_timeout(sockfd, answer_size, timeout);
close(sockfd);
if (*answer_size == 0) {