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
*/
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 */
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)
{