net.h File Reference

Contains functions to send and receive packets over a network. More...

Go to the source code of this file.

Macros

#define LDNS_DEFAULT_TIMEOUT_SEC   5
 
#define LDNS_DEFAULT_TIMEOUT_USEC   0
 

Functions

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)
 Sends a buffer to an ip using udp and return the response as a ldns_pkt. More...
 
int ldns_udp_bgsend2 (ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout)
 Send an udp query and don't wait for an answer but return the socket. More...
 
int ldns_udp_bgsend (ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout)
 Send an udp query and don't wait for an answer but return the socket This function has the flaw that it returns 0 on failure, but 0 could be a valid socket. More...
 
int ldns_tcp_bgsend2 (ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout)
 Send an tcp query and don't wait for an answer but return the socket. More...
 
int ldns_tcp_bgsend (ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout)
 Send an tcp query and don't wait for an answer but return the socket This function has the flaw that it returns 0 on failure, but 0 could be a valid socket. More...
 
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)
 Sends a buffer to an ip using tcp and return the response as a ldns_pkt. More...
 
ldns_status ldns_send (ldns_pkt **pkt, ldns_resolver *r, const ldns_pkt *query_pkt)
 Sends ptk to the nameserver at the resolver object. More...
 
ldns_status ldns_send_buffer (ldns_pkt **pkt, ldns_resolver *r, ldns_buffer *qb, ldns_rdf *tsig_mac)
 Sends and ldns_buffer (presumably containing a packet to the nameserver at the resolver object. More...
 
int ldns_tcp_connect2 (const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout)
 Create a tcp socket to the specified address. More...
 
int ldns_tcp_connect (const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout)
 Create a tcp socket to the specified address This function has the flaw that it returns 0 on failure, but 0 could be a valid socket. More...
 
int ldns_udp_connect2 (const struct sockaddr_storage *to, struct timeval timeout)
 Create a udp socket to the specified address. More...
 
int ldns_udp_connect (const struct sockaddr_storage *to, struct timeval timeout)
 Create a udp socket to the specified address This function has the flaw that it returns 0 on failure, but 0 could be a valid socket. More...
 
ssize_t ldns_tcp_send_query (ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen)
 send a query via tcp to a server. More...
 
ssize_t ldns_udp_send_query (ldns_buffer *qbin, int sockfd, const struct sockaddr_storage *to, socklen_t tolen)
 send a query via udp to a server. More...
 
uint8_t * ldns_tcp_read_wire_timeout (int sockfd, size_t *size, struct timeval timeout)
 Gives back a raw packet from the wire and reads the header data from the given socket. More...
 
uint8_t * ldns_tcp_read_wire (int sockfd, size_t *size)
 This routine may block. More...
 
uint8_t * ldns_udp_read_wire (int sockfd, size_t *size, struct sockaddr_storage *fr, socklen_t *frlen)
 Gives back a raw packet from the wire and reads the header data from the given socket. More...
 
struct sockaddr_storage * ldns_rdf2native_sockaddr_storage (const ldns_rdf *rd, uint16_t port, size_t *size)
 returns the native sockaddr representation from the rdf. More...
 
ldns_rdfldns_sockaddr_storage2rdf (const struct sockaddr_storage *sock, uint16_t *port)
 returns an rdf with the sockaddr info. More...
 
ldns_status ldns_axfr_start (ldns_resolver *resolver, const ldns_rdf *domain, ldns_rr_class c)
 Prepares the resolver for an axfr query The query is sent and the answers can be read with ldns_axfr_next. More...
 

Detailed Description

Contains functions to send and receive packets over a network.

Definition in file net.h.

Macro Definition Documentation

◆ LDNS_DEFAULT_TIMEOUT_SEC

#define LDNS_DEFAULT_TIMEOUT_SEC   5

Definition at line 23 of file net.h.

◆ LDNS_DEFAULT_TIMEOUT_USEC

#define LDNS_DEFAULT_TIMEOUT_USEC   0

Definition at line 24 of file net.h.

Function Documentation

◆ ldns_udp_send()

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 
)

Sends a buffer to an ip using udp and return the response as a ldns_pkt.

Parameters
[in]qbinthe ldns_buffer to be send
[in]tothe ip addr to send to
[in]tolenlength of the ip addr
[in]timeoutthe timeout value for the network
[out]answersizesize of the packet
[out]resultpacket with the answer
Returns
status

Definition at line 483 of file net.c.

◆ ldns_udp_bgsend2()

int ldns_udp_bgsend2 ( ldns_buffer qbin,
const struct sockaddr_storage *  to,
socklen_t  tolen,
struct timeval  timeout 
)

Send an udp query and don't wait for an answer but return the socket.

Parameters
[in]qbinthe ldns_buffer to be send
[in]tothe ip addr to send to
[in]tolenlength of the ip addr
[in]timeoutunused, was the timeout value for the network
Returns
the socket used or -1 on failure

Definition at line 437 of file net.c.

◆ ldns_udp_bgsend()

int ldns_udp_bgsend ( ldns_buffer qbin,
const struct sockaddr_storage *  to,
socklen_t  tolen,
struct timeval  timeout 
)

Send an udp query and don't wait for an answer but return the socket This function has the flaw that it returns 0 on failure, but 0 could be a valid socket.

Please use ldns_udp_bgsend2 instead of this function.

Parameters
[in]qbinthe ldns_buffer to be send
[in]tothe ip addr to send to
[in]tolenlength of the ip addr
[in]timeoutunused, was the timeout value for the network
Returns
the socket used or 0 on failure

Definition at line 428 of file net.c.

◆ ldns_tcp_bgsend2()

int ldns_tcp_bgsend2 ( ldns_buffer qbin,
const struct sockaddr_storage *  to,
socklen_t  tolen,
struct timeval  timeout 
)

Send an tcp query and don't wait for an answer but return the socket.

Parameters
[in]qbinthe ldns_buffer to be send
[in]tothe ip addr to send to
[in]tolenlength of the ip addr
[in]timeoutthe timeout value for the connect attempt
Returns
the socket used or -1 on failure

Definition at line 325 of file net.c.

◆ ldns_tcp_bgsend()

int ldns_tcp_bgsend ( ldns_buffer qbin,
const struct sockaddr_storage *  to,
socklen_t  tolen,
struct timeval  timeout 
)

Send an tcp query and don't wait for an answer but return the socket This function has the flaw that it returns 0 on failure, but 0 could be a valid socket.

Please use ldns_tcp_bgsend2 instead of this function.

Parameters
[in]qbinthe ldns_buffer to be send
[in]tothe ip addr to send to
[in]tolenlength of the ip addr
[in]timeoutthe timeout value for the connect attempt
Returns
the socket used or 0 on failure

Definition at line 316 of file net.c.

◆ ldns_tcp_send()

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 
)

Sends a buffer to an ip using tcp and return the response as a ldns_pkt.

Parameters
[out]resultpacket with the answer
[in]qbinthe ldns_buffer to be send
[in]tothe ip addr to send to
[in]tolenlength of the ip addr
[in]timeoutthe timeout value for the network
[out]answersizesize of the packet
Returns
status

Definition at line 363 of file net.c.

◆ ldns_send()

ldns_status ldns_send ( ldns_pkt **  pkt,
ldns_resolver r,
const ldns_pkt query_pkt 
)

Sends ptk to the nameserver at the resolver object.

Returns the data as a ldns_pkt

Parameters
[out]pktpacket received from the nameserver
[in]rthe resolver to use
[in]query_pktthe query to send
Returns
status

Definition at line 38 of file net.c.

References ldns_buffer_free(), ldns_buffer_new(), LDNS_MIN_BUFLEN, ldns_pkt2buffer_wire(), ldns_pkt_tsig(), ldns_rr_rdf(), ldns_send_buffer(), LDNS_STATUS_ERR, and LDNS_STATUS_OK.

◆ ldns_send_buffer()

ldns_status ldns_send_buffer ( ldns_pkt **  pkt,
ldns_resolver r,
ldns_buffer qb,
ldns_rdf tsig_mac 
)

Sends and ldns_buffer (presumably containing a packet to the nameserver at the resolver object.

Returns the data as a ldns_pkt

Parameters
[out]pktpacket received from the nameserver
[in]rthe resolver to use
[in]qbthe buffer to send
[in]tsig_macthe tsig MAC to authenticate the response with (NULL to do no TSIG authentication)
Returns
status

Definition at line 492 of file net.c.

References ldns_resolver_nameservers(), ldns_resolver_nameservers_randomize(), ldns_resolver_random(), ldns_resolver_rtt(), ldns_resolver_source(), and LDNS_STATUS_OK.

◆ ldns_tcp_connect2()

int ldns_tcp_connect2 ( const struct sockaddr_storage *  to,
socklen_t  tolen,
struct timeval  timeout 
)

Create a tcp socket to the specified address.

Parameters
[in]toip and family
[in]tolenlength of to
[in]timeouttimeout for the connect attempt
Returns
a socket descriptor or -1 on failure

Definition at line 291 of file net.c.

◆ ldns_tcp_connect()

int ldns_tcp_connect ( const struct sockaddr_storage *  to,
socklen_t  tolen,
struct timeval  timeout 
)

Create a tcp socket to the specified address This function has the flaw that it returns 0 on failure, but 0 could be a valid socket.

Please use ldns_tcp_connect2 instead of this function.

Parameters
[in]toip and family
[in]tolenlength of to
[in]timeouttimeout for the connect attempt
Returns
a socket descriptor or 0 on failure

Definition at line 283 of file net.c.

◆ ldns_udp_connect2()

int ldns_udp_connect2 ( const struct sockaddr_storage *  to,
struct timeval  timeout 
)

Create a udp socket to the specified address.

Parameters
[in]toip and family
[in]timeoutunused, was timeout for the socket
Returns
a socket descriptor or -1 on failure

◆ ldns_udp_connect()

int ldns_udp_connect ( const struct sockaddr_storage *  to,
struct timeval  timeout 
)

Create a udp socket to the specified address This function has the flaw that it returns 0 on failure, but 0 could be a valid socket.

Please use ldns_udp_connect2 instead of this function.

Parameters
[in]toip and family
[in]timeoutunused, was timeout for the socket
Returns
a socket descriptor or 0 on failure

◆ ldns_tcp_send_query()

ssize_t ldns_tcp_send_query ( ldns_buffer qbin,
int  sockfd,
const struct sockaddr_storage *  to,
socklen_t  tolen 
)

send a query via tcp to a server.

Don't want for the answer

Parameters
[in]qbinthe buffer to send
[in]sockfdthe socket to use
[in]towhich ip to send it
[in]tolensocketlen
Returns
number of bytes sent

Definition at line 681 of file net.c.

References LDNS_XMALLOC.

◆ ldns_udp_send_query()

ssize_t ldns_udp_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

Parameters
[in]qbinthe buffer to send
[in]sockfdthe socket to use
[in]towhich ip to send it
[in]tolensocketlen
Returns
number of bytes sent

Definition at line 706 of file net.c.

◆ ldns_tcp_read_wire_timeout()

uint8_t* ldns_tcp_read_wire_timeout ( int  sockfd,
size_t *  size,
struct timeval  timeout 
)

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

Parameters
[in]sockfdthe socket to read from
[out]sizethe number of bytes that are read
[in]timeoutthe time allowed between packets.
Returns
the data read

Definition at line 751 of file net.c.

References LDNS_XMALLOC.

◆ ldns_tcp_read_wire()

uint8_t* ldns_tcp_read_wire ( int  sockfd,
size_t *  size 
)

This routine may block.

Use ldns_tcp_read_wire_timeout, it checks timeouts. 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

Parameters
[in]sockfdthe socket to read from
[out]sizethe number of bytes that are read
Returns
the data read

Definition at line 810 of file net.c.

References LDNS_FREE, and LDNS_XMALLOC.

◆ ldns_udp_read_wire()

uint8_t* ldns_udp_read_wire ( int  sockfd,
size_t *  size,
struct sockaddr_storage *  fr,
socklen_t *  frlen 
)

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

Parameters
[in]sockfdthe socket to read from
[in]frthe address of the client (if applicable)
[in]*frlenthe length of the client's addr (if applicable)
[out]sizethe number of bytes that are read
Returns
the data read

Definition at line 721 of file net.c.

References LDNS_FREE, LDNS_MAX_PACKETLEN, LDNS_XMALLOC, and LDNS_XREALLOC.

◆ ldns_rdf2native_sockaddr_storage()

struct sockaddr_storage* ldns_rdf2native_sockaddr_storage ( const ldns_rdf rd,
uint16_t  port,
size_t *  size 
)

returns the native sockaddr representation from the rdf.

Parameters
[in]rdthe ldns_rdf to operate on
[in]portwhat port to use. 0 means; use default (53)
[out]sizewhat is the size of the sockaddr_storage
Returns
struct sockaddr* the address in the format so other functions can use it (sendto)

Definition at line 104 of file net.c.

◆ ldns_sockaddr_storage2rdf()

ldns_rdf* ldns_sockaddr_storage2rdf ( const struct sockaddr_storage *  sock,
uint16_t *  port 
)

returns an rdf with the sockaddr info.

works for ip4 and ip6

Parameters
[in]sockthe struct sockaddr_storage to convert
[in]portwhat port was used. When NULL this is not set
Returns
ldns_rdf* with the address

Definition at line 860 of file net.c.

References LDNS_IP4ADDRLEN, LDNS_IP6ADDRLEN, ldns_rdf_new_frm_data(), LDNS_RDF_TYPE_A, and LDNS_RDF_TYPE_AAAA.

◆ ldns_axfr_start()

ldns_status ldns_axfr_start ( ldns_resolver resolver,
const ldns_rdf domain,
ldns_rr_class  c 
)

Prepares the resolver for an axfr query The query is sent and the answers can be read with ldns_axfr_next.

Parameters
[in]resolverthe resolver to use
[in]domainthe domain to axfr
[in]cthe class to use
Returns
ldns_status the status of the transfer

Definition at line 895 of file net.c.

References ldns_pkt_query_new(), ldns_rdf_clone(), ldns_resolver_nameserver_count(), ldns_resolver_source(), LDNS_RR_TYPE_AXFR, LDNS_STATUS_ADDRESS_ERR, and LDNS_STATUS_ERR.