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@
23 #define LDNS_DEFAULT_TIMEOUT_SEC 5
24 #define LDNS_DEFAULT_TIMEOUT_USEC 0
29 * Contains functions to send and receive packets over a network.
33 * Sends a buffer to an ip using udp and return the respons as a ldns_pkt
34 * \param[in] qbin the ldns_buffer to be send
35 * \param[in] to the ip addr to send to
36 * \param[in] tolen length of the ip addr
37 * \param[in] timeout the timeout value for the network
38 * \param[out] answersize size of the packet
39 * \param[out] result packet with the answer
42 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);
45 * Send an udp query and don't wait for an answer but return
47 * \param[in] qbin the ldns_buffer to be send
48 * \param[in] to the ip addr to send to
49 * \param[in] tolen length of the ip addr
50 * \param[in] timeout *unused*, was the timeout value for the network
51 * \return the socket used
53 int ldns_udp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
56 * Send an tcp query and don't wait for an answer but return
58 * \param[in] qbin the ldns_buffer to be send
59 * \param[in] to the ip addr to send to
60 * \param[in] tolen length of the ip addr
61 * \param[in] timeout the timeout value for the connect attempt
62 * \return the socket used
64 int ldns_tcp_bgsend(ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
67 * Sends a buffer to an ip using tcp and return the respons as a ldns_pkt
68 * \param[in] qbin the ldns_buffer to be send
69 * \param[in] qbin the ldns_buffer to be send
70 * \param[in] to the ip addr to send to
71 * \param[in] tolen length of the ip addr
72 * \param[in] timeout the timeout value for the network
73 * \param[out] answersize size of the packet
74 * \param[out] result packet with the answer
77 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);
80 * Sends ptk to the nameserver at the resolver object. Returns the data
83 * \param[out] pkt packet received from the nameserver
84 * \param[in] r the resolver to use
85 * \param[in] query_pkt the query to send
88 ldns_status ldns_send(ldns_pkt **pkt, ldns_resolver *r, const ldns_pkt *query_pkt);
91 * Sends and ldns_buffer (presumably containing a packet to the nameserver at the resolver object. Returns the data
94 * \param[out] pkt packet received from the nameserver
95 * \param[in] r the resolver to use
96 * \param[in] qb the buffer to send
97 * \param[in] tsig_mac the tsig MAC to authenticate the response with (NULL to do no TSIG authentication)
100 ldns_status ldns_send_buffer(ldns_pkt **pkt, ldns_resolver *r, ldns_buffer *qb, ldns_rdf *tsig_mac);
103 * Create a tcp socket to the specified address
104 * \param[in] to ip and family
105 * \param[in] tolen length of to
106 * \param[in] timeout timeout for the connect attempt
107 * \return a socket descriptor
109 int ldns_tcp_connect(const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
112 * Create a udp socket to the specified address
113 * \param[in] to ip and family
114 * \param[in] timeout *unused*, was timeout for the socket
115 * \return a socket descriptor
117 int ldns_udp_connect(const struct sockaddr_storage *to, struct timeval timeout);
120 * send a query via tcp to a server. Don't want for the answer
122 * \param[in] qbin the buffer to send
123 * \param[in] sockfd the socket to use
124 * \param[in] to which ip to send it
125 * \param[in] tolen socketlen
126 * \return number of bytes sent
128 ssize_t ldns_tcp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen);
131 * send a query via udp to a server. Don;t want for the answer
133 * \param[in] qbin the buffer to send
134 * \param[in] sockfd the socket to use
135 * \param[in] to which ip to send it
136 * \param[in] tolen socketlen
137 * \return number of bytes sent
139 ssize_t ldns_udp_send_query(ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen);
142 * Gives back a raw packet from the wire and reads the header data from the given
143 * socket. Allocates the data (of size size) itself, so don't forget to free
145 * \param[in] sockfd the socket to read from
146 * \param[out] size the number of bytes that are read
147 * \param[in] timeout the time allowed between packets.
148 * \return the data read
150 uint8_t *ldns_tcp_read_wire_timeout(int sockfd, size_t *size, struct timeval timeout);
153 * This routine may block. Use ldns_tcp_read_wire_timeout, it checks timeouts.
154 * Gives back a raw packet from the wire and reads the header data from the given
155 * socket. Allocates the data (of size size) itself, so don't forget to free
157 * \param[in] sockfd the socket to read from
158 * \param[out] size the number of bytes that are read
159 * \return the data read
161 uint8_t *ldns_tcp_read_wire(int sockfd, size_t *size);
164 * Gives back a raw packet from the wire and reads the header data from the given
165 * socket. Allocates the data (of size size) itself, so don't forget to free
167 * \param[in] sockfd the socket to read from
168 * \param[in] fr the address of the client (if applicable)
169 * \param[in] *frlen the lenght of the client's addr (if applicable)
170 * \param[out] size the number of bytes that are read
171 * \return the data read
173 uint8_t *ldns_udp_read_wire(int sockfd, size_t *size, struct sockaddr_storage *fr, socklen_t *frlen);
176 * returns the native sockaddr representation from the rdf.
177 * \param[in] rd the ldns_rdf to operate on
178 * \param[in] port what port to use. 0 means; use default (53)
179 * \param[out] size what is the size of the sockaddr_storage
180 * \return struct sockaddr* the address in the format so other
181 * functions can use it (sendto)
183 struct sockaddr_storage * ldns_rdf2native_sockaddr_storage(const ldns_rdf *rd, uint16_t port, size_t *size);
186 * returns an rdf with the sockaddr info. works for ip4 and ip6
187 * \param[in] sock the struct sockaddr_storage to convert
188 * \param[in] port what port was used. When NULL this is not set
189 * \return ldns_rdf* wth the address
191 ldns_rdf * ldns_sockaddr_storage2rdf(struct sockaddr_storage *sock, uint16_t *port);
194 * Prepares the resolver for an axfr query
195 * The query is sent and the answers can be read with ldns_axfr_next
196 * \param[in] resolver the resolver to use
197 * \param[in] domain the domain to exfr
198 * \param[in] c the class to use
199 * \return ldns_status the status of the transfer
201 ldns_status ldns_axfr_start(ldns_resolver *resolver, ldns_rdf *domain, ldns_rr_class c);
207 #endif /* LDNS_NET_H */