ldns documentation

- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

Functions
net.c File Reference

Go to the source code of this file.

## Functions
ldns_status | ldns_send (ldns_pkt **result_packet, ldns_resolver *r, const ldns_pkt *query_pkt)
| Sends ptk to the nameserver at the resolver object. 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...
int | ldns_tcp_connect (const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout)
| Create a tcp socket to the specified address. 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. 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 *answer_size)
| Sends a buffer to an ip using tcp and return the respons as a ldns_pkt. More...
int | ldns_udp_connect (const struct sockaddr_storage *to, struct timeval timeout __attribute__((unused)))
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. More...
ldns_status | ldns_udp_send (uint8_t **result, ldns_buffer *qbin, const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout, size_t *answer_size)
| Sends a buffer to an ip using udp and return the respons as a ldns_pkt. More...
ldns_status | ldns_send_buffer (ldns_pkt **result, 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...
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_udp_read_wire (int sockfd, size_t *size, struct sockaddr_storage *from, socklen_t *fromlen)
| Gives back a raw packet from the wire and reads the header data from the given socket. 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...
ldns_rdf * | ldns_sockaddr_storage2rdf (struct sockaddr_storage *sock, uint16_t *port)
| returns an rdf with the sockaddr info. More...
ldns_status | ldns_axfr_start (ldns_resolver *resolver, ldns_rdf *domain, ldns_rr_class class)
| Prepares the resolver for an axfr query The query is sent and the answers can be read with ldns_axfr_next. More...

## Function Documentation

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] | pkt | packet received from the nameserver
  [in] | r | the resolver to use
  [in] | query_pkt | the query to send

Returns
  status

Definition at line 35 of file net.c.

References ldns_buffer_free(), ldns_buffer_new(), LDNS_FREE, LDNS_MALLOC, LDNS_MIN_BUFLEN, ldns_pkt2buffer_wire(), ldns_pkt_tsig(), ldns_rdf_data(), ldns_rdf_get_type(), ldns_rdf_size(), LDNS_RDF_TYPE_A, LDNS_RDF_TYPE_AAAA, ldns_rr_rdf(), ldns_send_buffer(), LDNS_STATUS_ERR, and LDNS_STATUS_OK.

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] | rd | the ldns_rdf to operate on
  [in] | port | what port to use. 0 means; use default (53)
  [out] | size | what 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 101 of file net.c.

References FD_SET_T, and LDNS_PORT.

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

Create a tcp socket to the specified address.

Parameters

  [in] | to | ip and family
  [in] | tolen | length of to
  [in] | timeout | timeout for the connect attempt

Returns
  a socket descriptor

Definition at line 267 of file net.c.

References ldns_tcp_send_query().

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.

Parameters

  [in] | qbin | the ldns_buffer to be send
  [in] | to | the ip addr to send to
  [in] | tolen | length of the ip addr
  [in] | timeout | the timeout value for the connect attempt

Returns
  the socket used

Definition at line 300 of file net.c.

References LDNS_FREE, LDNS_STATUS_ERR, LDNS_STATUS_MEM_ERR, LDNS_STATUS_NETWORK_ERR, LDNS_STATUS_OK, ldns_tcp_read_wire_timeout(), and LDNS_XREALLOC.

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 respons as a ldns_pkt.

Parameters

  [in] | qbin | the ldns_buffer to be send
  [in] | qbin | the ldns_buffer to be send
  [in] | to | the ip addr to send to
  [in] | tolen | length of the ip addr
  [in] | timeout | the timeout value for the network
  [out] | answersize | size of the packet
  [out] | result | packet with the answer

Returns
  status

Definition at line 348 of file net.c.

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

Definition at line 357 of file net.c.

References ldns_udp_send_query().

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.

Parameters

  [in] | qbin | the ldns_buffer to be send
  [in] | to | the ip addr to send to
  [in] | tolen | length of the ip addr
  [in] | timeout | unused, was the timeout value for the network

Returns
  the socket used

Definition at line 401 of file net.c.

References LDNS_STATUS_NETWORK_ERR, LDNS_STATUS_OK, LDNS_STATUS_SOCKET_ERROR, and ldns_udp_read_wire().

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 respons as a ldns_pkt.

Parameters

  [in] | qbin | the ldns_buffer to be send
  [in] | to | the ip addr to send to
  [in] | tolen | length of the ip addr
  [in] | timeout | the timeout value for the network
  [out] | answersize | size of the packet
  [out] | result | packet with the answer

Returns
  status

Definition at line 455 of file net.c.

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] | pkt | packet received from the nameserver
  [in] | r | the resolver to use
  [in] | qb | the buffer to send
  [in] | tsig_mac | the tsig MAC to authenticate the response with (NULL to do no TSIG authentication)

Returns
  status

Definition at line 464 of file net.c.

References LDNS_FREE, ldns_pkt_set_answerfrom(), ldns_pkt_set_querytime(), ldns_pkt_set_size(), ldns_pkt_set_timestamp(), ldns_pkt_tsig_verify(), ldns_rdf2native_sockaddr_storage(), ldns_rdf_clone(), LDNS_RESOLV_INET, LDNS_RESOLV_INET6, LDNS_RESOLV_RTT_INF, ldns_resolver_fail(), ldns_resolver_ip6(), ldns_resolver_nameserver_count(), ldns_resolver_nameservers(), ldns_resolver_nameservers_randomize(), ldns_resolver_port(), ldns_resolver_random(), ldns_resolver_retrans(), ldns_resolver_retry(), ldns_resolver_rtt(), ldns_resolver_set_nameserver_rtt(), ldns_resolver_source(), ldns_resolver_timeout(), ldns_resolver_tsig_keydata(), ldns_resolver_tsig_keyname(), ldns_resolver_usevc(), LDNS_STATUS_CRYPTO_TSIG_BOGUS, LDNS_STATUS_ERR, LDNS_STATUS_OK, LDNS_STATUS_RES_NO_NS, and ldns_wire2pkt().

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] | qbin | the buffer to send
  [in] | sockfd | the socket to use
  [in] | to | which ip to send it
  [in] | tolen | socketlen

Returns
  number of bytes sent

Definition at line 648 of file net.c.

References LDNS_FREE, and LDNS_XMALLOC.

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] | qbin | the buffer to send
  [in] | sockfd | the socket to use
  [in] | to | which ip to send it
  [in] | tolen | socketlen

Returns
  number of bytes sent

Definition at line 673 of file net.c.

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] | sockfd | the socket to read from
  [in] | fr | the address of the client (if applicable)
  [in] | *frlen | the lenght of the client's addr (if applicable)
  [out] | size | the number of bytes that are read

Returns
  the data read

Definition at line 691 of file net.c.

References LDNS_FREE, LDNS_MAX_PACKETLEN, LDNS_XMALLOC, and LDNS_XREALLOC.

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] | sockfd | the socket to read from
  [out] | size | the number of bytes that are read
  [in] | timeout | the time allowed between packets.

Returns
  the data read

Definition at line 721 of file net.c.

References LDNS_FREE, and LDNS_XMALLOC.

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] | sockfd | the socket to read from
  [out] | size | the number of bytes that are read

Returns
  the data read

Definition at line 780 of file net.c.

References LDNS_FREE, and LDNS_XMALLOC.

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

returns an rdf with the sockaddr info.

works for ip4 and ip6

Parameters

  [in] | sock | the struct sockaddr_storage to convert
  [in] | port | what port was used. When NULL this is not set

Returns
  ldns_rdf* wth the address

Definition at line 830 of file net.c.

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

ldns_status ldns_axfr_start | ( | ldns_resolver * | resolver,
|  | 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] | resolver | the resolver to use
  [in] | domain | the domain to exfr
  [in] | c | the class to use

Returns
  ldns_status the status of the transfer

Definition at line 865 of file net.c.

References ldns_struct_resolver::_axfr_soa_count, ldns_struct_resolver::_nameservers, ldns_struct_resolver::_socket, ldns_buffer_free(), ldns_buffer_new(), LDNS_FREE, LDNS_MAX_PACKETLEN, ldns_pkt2buffer_wire(), ldns_pkt_free(), ldns_pkt_query_new(), ldns_pkt_tsig_sign(), ldns_rdf2native_sockaddr_storage(), ldns_rdf_clone(), ldns_resolver_nameserver_count(), ldns_resolver_port(), ldns_resolver_source(), ldns_resolver_timeout(), ldns_resolver_tsig_algorithm(), ldns_resolver_tsig_keydata(), ldns_resolver_tsig_keyname(), LDNS_RR_TYPE_AXFR, LDNS_STATUS_ADDRESS_ERR, LDNS_STATUS_CRYPTO_TSIG_ERR, LDNS_STATUS_ERR, LDNS_STATUS_MEM_ERR, LDNS_STATUS_NETWORK_ERR, LDNS_STATUS_OK, and ldns_tcp_send_query().