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