4 * DNS Resolver definitions
6 * a Net::DNS like library for C
8 * (c) NLnet Labs, 2005-2006
10 * See the file LICENSE for the license
16 #include <ldns/ldns.h>
17 #include <sys/socket.h>
19 #define LDNS_DEFAULT_TIMEOUT_SEC 2
20 #define LDNS_DEFAULT_TIMEOUT_USEC 0
25 * Contains functions to send and receive packets over a network.
29 * Sends a buffer to an ip using udp and return the respons as a ldns_pkt
30 * \param[in] qbin the ldns_buffer to be send
31 * \param[in] to the ip addr to send to
32 * \param[in] tolen length of the ip addr
33 * \param[in] timeout the timeout value for the network
34 * \param[out] answersize size of the packet
35 * \param[out] result packet with the answer
38 ldns_status ldns_udp_send(uint8_t **result, ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout, size_t *answersize);
41 * Send an udp query and don't wait for an answer but return
43 * \param[in] qbin the ldns_buffer to be send
44 * \param[in] to the ip addr to send to
45 * \param[in] tolen length of the ip addr
46 * \param[in] timeout *unused*, was the timeout value for the network
47 * \return the socket used
50 int ldns_udp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
53 * Send an tcp query and don't wait for an answer but return
55 * \param[in] qbin the ldns_buffer to be send
56 * \param[in] to the ip addr to send to
57 * \param[in] tolen length of the ip addr
58 * \param[in] timeout the timeout value for the connect attempt
59 * \return the socket used
61 int ldns_tcp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
64 * Sends a buffer to an ip using tcp and return the respons as a ldns_pkt
65 * \param[in] qbin the ldns_buffer to be send
66 * \param[in] qbin the ldns_buffer to be send
67 * \param[in] to the ip addr to send to
68 * \param[in] tolen length of the ip addr
69 * \param[in] timeout the timeout value for the network
70 * \param[out] answersize size of the packet
71 * \param[out] result packet with the answer
74 ldns_status ldns_tcp_send(uint8_t **result, ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout, size_t *answersize);
77 * Sends ptk to the nameserver at the resolver object. Returns the data
80 * \param[out] pkt packet received from the nameserver
81 * \param[in] r the resolver to use
82 * \param[in] query_pkt the query to send
85 ldns_status ldns_send(ldns_pkt **pkt, ldns_resolver *r, const ldns_pkt *query_pkt);
88 * Sends and ldns_buffer (presumably containing a packet to the nameserver at the resolver object. Returns the data
91 * \param[out] pkt packet received from the nameserver
92 * \param[in] r the resolver to use
93 * \param[in] qb the buffer to send
94 * \param[in] tsig_mac the tsig MAC to authenticate the response with (NULL to do no TSIG authentication)
97 ldns_status ldns_send_buffer(ldns_pkt **pkt, ldns_resolver *r, ldns_buffer *qb, ldns_rdf *tsig_mac);
100 * Create a tcp socket to the specified address
101 * \param[in] to ip and family
102 * \param[in] tolen length of to
103 * \param[in] timeout timeout for the connect attempt
104 * \return a socket descriptor
106 int ldns_tcp_connect(const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
109 * Create a udp socket to the specified address
110 * \param[in] to ip and family
111 * \param[in] timeout *unused*, was timeout for the socket
112 * \return a socket descriptor
114 int ldns_udp_connect(const struct sockaddr_storage *to, struct timeval timeout);
117 * send a query via tcp to a server. Don't want for the answer
119 * \param[in] qbin the buffer to send
120 * \param[in] sockfd the socket to use
121 * \param[in] to which ip to send it
122 * \param[in] tolen socketlen
123 * \return number of bytes sent
125 ssize_t ldns_tcp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen);
128 * send a query via udp to a server. Don;t want for the answer
130 * \param[in] qbin the buffer to send
131 * \param[in] sockfd the socket to use
132 * \param[in] to which ip to send it
133 * \param[in] tolen socketlen
134 * \return number of bytes sent
136 ssize_t ldns_udp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen);
139 * Gives back a raw packet from the wire and reads the header data from the given
140 * socket. Allocates the data (of size size) itself, so don't forget to free
142 * \param[in] sockfd the socket to read from
143 * \param[out] size the number of bytes that are read
144 * \param[in] timeout the time allowed between packets.
145 * \return the data read
147 uint8_t *ldns_tcp_read_wire_timeout(int sockfd, size_t *size, struct timeval timeout);
150 * This routine may block. Use ldns_tcp_read_wire_timeout, it checks timeouts.
151 * Gives back a raw packet from the wire and reads the header data from the given
152 * socket. Allocates the data (of size size) itself, so don't forget to free
154 * \param[in] sockfd the socket to read from
155 * \param[out] size the number of bytes that are read
156 * \return the data read
158 uint8_t *ldns_tcp_read_wire(int sockfd, size_t *size);
161 * Gives back a raw packet from the wire and reads the header data from the given
162 * socket. Allocates the data (of size size) itself, so don't forget to free
164 * \param[in] sockfd the socket to read from
165 * \param[in] fr the address of the client (if applicable)
166 * \param[in] *frlen the lenght of the client's addr (if applicable)
167 * \param[out] size the number of bytes that are read
168 * \return the data read
170 uint8_t *ldns_udp_read_wire(int sockfd, size_t *size, struct sockaddr_storage *fr, socklen_t *frlen);
173 * returns the native sockaddr representation from the rdf.
174 * \param[in] rd the ldns_rdf to operate on
175 * \param[in] port what port to use. 0 means; use default (53)
176 * \param[out] size what is the size of the sockaddr_storage
177 * \return struct sockaddr* the address in the format so other
178 * functions can use it (sendto)
180 struct sockaddr_storage * ldns_rdf2native_sockaddr_storage(const ldns_rdf *rd, uint16_t port, size_t *size);
183 * returns an rdf with the sockaddr info. works for ip4 and ip6
184 * \param[in] sock the struct sockaddr_storage to convert
185 * \param[in] port what port was used. When NULL this is not set
186 * \return ldns_rdf* wth the address
188 ldns_rdf * ldns_sockaddr_storage2rdf(struct sockaddr_storage *sock, uint16_t *port);
191 * Prepares the resolver for an axfr query
192 * The query is sent and the answers can be read with ldns_axfr_next
193 * \param[in] resolver the resolver to use
194 * \param[in] domain the domain to exfr
195 * \param[in] c the class to use
196 * \return ldns_status the status of the transfer
198 ldns_status ldns_axfr_start(ldns_resolver *resolver, ldns_rdf *domain, ldns_rr_class c);
200 #endif /* LDNS_NET_H */