From Fedora Project Wiki
(Created page with "== Domain Name System === Resolving using <code>getaddrinfo()</code> in applications The <code>getaddrinfo()</code> function is a dualstack-friendly API to name resolution. ...")
 
No edit summary
Line 1: Line 1:
== Domain Name System
== Domain Name System ==


=== Resolving using <code>getaddrinfo()</code> in applications
=== Resolving using <code>getaddrinfo()</code> in applications ===


The <code>getaddrinfo()</code> function is a dualstack-friendly API to name
The <code>getaddrinfo()</code> function is a dualstack-friendly API to name
Line 11: Line 11:


<pre>
<pre>
const char *node = "www.fedoraproject.org";
const char *service = "http";
struct addrinfo hints = {
    .ai_family = AF_UNSPEC,
    .ai_socktype = SOCK_DGRAM,
    .ai_flags = 0,
    .ai_protocol = 0,
    .ai_canonname = NULL,
    .ai_addr = NULL,
    .ai_next = NULL
};
struct addrinfo *result;
int error;
int error;
struct addrinfo hints;
struct addrinfo *result;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = 0;
hints.ai_protocol = 0;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;


error = getaddrinfo(node, service, &hints, &result)
error = getaddrinfo(node, service, &hints, &result)
</pre>
</pre>

Revision as of 20:03, 21 November 2012

Domain Name System

Resolving using getaddrinfo() in applications

The getaddrinfo() function is a dualstack-friendly API to name resolution. It is used by applications to translate host and service names to a linked list of struct addrinfo objects.

And example of getaddrinfo() call:

const char *node = "www.fedoraproject.org";
const char *service = "http";
struct addrinfo hints = {
    .ai_family = AF_UNSPEC,
    .ai_socktype = SOCK_DGRAM,
    .ai_flags = 0,
    .ai_protocol = 0,
    .ai_canonname = NULL,
    .ai_addr = NULL,
    .ai_next = NULL
};
struct addrinfo *result;
int error;

error = getaddrinfo(node, service, &hints, &result)