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
54 int ldns_udp_bgsend(ldns_buffer
*qbin
, const struct sockaddr_storage
*to
, socklen_t tolen
, struct timeval timeout
);
57 * Send an tcp query and don't wait for an answer but return
59 * \param[in] qbin the ldns_buffer to be send
60 * \param[in] to the ip addr to send to
61 * \param[in] tolen length of the ip addr
62 * \param[in] timeout the timeout value for the connect attempt
63 * \return the socket used
65 int ldns_tcp_bgsend(ldns_buffer
*qbin
, const struct sockaddr_storage
*to
, socklen_t tolen
, struct timeval timeout
);
68 * Sends a buffer to an ip using tcp and return the respons as a ldns_pkt
69 * \param[in] qbin the ldns_buffer to be send
70 * \param[in] qbin the ldns_buffer to be send
71 * \param[in] to the ip addr to send to
72 * \param[in] tolen length of the ip addr
73 * \param[in] timeout the timeout value for the network
74 * \param[out] answersize size of the packet
75 * \param[out] result packet with the answer
78 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
);
81 * Sends ptk to the nameserver at the resolver object. Returns the data
84 * \param[out] pkt packet received from the nameserver
85 * \param[in] r the resolver to use
86 * \param[in] query_pkt the query to send
89 ldns_status
ldns_send(ldns_pkt
**pkt
, ldns_resolver
*r
, const ldns_pkt
*query_pkt
);
92 * Sends and ldns_buffer (presumably containing a packet to the nameserver at the resolver object. Returns the data
95 * \param[out] pkt packet received from the nameserver
96 * \param[in] r the resolver to use
97 * \param[in] qb the buffer to send
98 * \param[in] tsig_mac the tsig MAC to authenticate the response with (NULL to do no TSIG authentication)
101 ldns_status
ldns_send_buffer(ldns_pkt
**pkt
, ldns_resolver
*r
, ldns_buffer
*qb
, ldns_rdf
*tsig_mac
);
104 * Create a tcp socket to the specified address
105 * \param[in] to ip and family
106 * \param[in] tolen length of to
107 * \param[in] timeout timeout for the connect attempt
108 * \return a socket descriptor
110 int ldns_tcp_connect(const struct sockaddr_storage
*to
, socklen_t tolen
, struct timeval timeout
);
113 * Create a udp socket to the specified address
114 * \param[in] to ip and family
115 * \param[in] timeout *unused*, was timeout for the socket
116 * \return a socket descriptor
118 int ldns_udp_connect(const struct sockaddr_storage
*to
, struct timeval timeout
);
121 * send a query via tcp to a server. Don't want for the answer
123 * \param[in] qbin the buffer to send
124 * \param[in] sockfd the socket to use
125 * \param[in] to which ip to send it
126 * \param[in] tolen socketlen
127 * \return number of bytes sent
129 ssize_t
ldns_tcp_send_query(ldns_buffer
*qbin
, int sockfd
, const struct sockaddr_storage
*to
, socklen_t tolen
);
132 * send a query via udp to a server. Don;t want for the answer
134 * \param[in] qbin the buffer to send
135 * \param[in] sockfd the socket to use
136 * \param[in] to which ip to send it
137 * \param[in] tolen socketlen
138 * \return number of bytes sent
140 ssize_t
ldns_udp_send_query(ldns_buffer
*qbin
, int sockfd
, const struct sockaddr_storage
*to
, socklen_t tolen
);
143 * Gives back a raw packet from the wire and reads the header data from the given
144 * socket. Allocates the data (of size size) itself, so don't forget to free
146 * \param[in] sockfd the socket to read from
147 * \param[out] size the number of bytes that are read
148 * \param[in] timeout the time allowed between packets.
149 * \return the data read
151 uint8_t *ldns_tcp_read_wire_timeout(int sockfd
, size_t *size
, struct timeval timeout
);
154 * This routine may block. Use ldns_tcp_read_wire_timeout, it checks timeouts.
155 * Gives back a raw packet from the wire and reads the header data from the given
156 * socket. Allocates the data (of size size) itself, so don't forget to free
158 * \param[in] sockfd the socket to read from
159 * \param[out] size the number of bytes that are read
160 * \return the data read
162 uint8_t *ldns_tcp_read_wire(int sockfd
, size_t *size
);
165 * Gives back a raw packet from the wire and reads the header data from the given
166 * socket. Allocates the data (of size size) itself, so don't forget to free
168 * \param[in] sockfd the socket to read from
169 * \param[in] fr the address of the client (if applicable)
170 * \param[in] *frlen the lenght of the client's addr (if applicable)
171 * \param[out] size the number of bytes that are read
172 * \return the data read
174 uint8_t *ldns_udp_read_wire(int sockfd
, size_t *size
, struct sockaddr_storage
*fr
, socklen_t
*frlen
);
177 * returns the native sockaddr representation from the rdf.
178 * \param[in] rd the ldns_rdf to operate on
179 * \param[in] port what port to use. 0 means; use default (53)
180 * \param[out] size what is the size of the sockaddr_storage
181 * \return struct sockaddr* the address in the format so other
182 * functions can use it (sendto)
184 struct sockaddr_storage
* ldns_rdf2native_sockaddr_storage(const ldns_rdf
*rd
, uint16_t port
, size_t *size
);
187 * returns an rdf with the sockaddr info. works for ip4 and ip6
188 * \param[in] sock the struct sockaddr_storage to convert
189 * \param[in] port what port was used. When NULL this is not set
190 * \return ldns_rdf* wth the address
192 ldns_rdf
* ldns_sockaddr_storage2rdf(struct sockaddr_storage
*sock
, uint16_t *port
);
195 * Prepares the resolver for an axfr query
196 * The query is sent and the answers can be read with ldns_axfr_next
197 * \param[in] resolver the resolver to use
198 * \param[in] domain the domain to exfr
199 * \param[in] c the class to use
200 * \return ldns_status the status of the transfer
202 ldns_status
ldns_axfr_start(ldns_resolver
*resolver
, ldns_rdf
*domain
, ldns_rr_class c
);
208 #endif /* LDNS_NET_H */