Unison Help
![](https://rowebots.com/wp-content/plugins/documentor/skins/default/images/search.png)
- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
7.17. DNS Client #
NAME
DNS Client
SYNOPSIS
int set_dns_server_address (char* ipv4_addr, char* ipv6_addr, char *mac);
int getnameinfo (const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
int getaddrinfo (const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res);
void freeaddrinfo (struct addrinfo *ai);
DESCRIPTION
The DNS client component serves for obtaining the domain name of host, having his IP address and vise versa. There are several functions which doing main actions. Their list is represented below.
Functions description:
-
- set_dns_server_address – sets DNS server addresses (IPv4/IPv6).
Parameters:
-
-
- ipv4_addr – pointer to IPv4 address of DNS server.
- ipv6_addr – pointer to IPv6 address of DNS server.
- mac – pointer to MAC address of client interface.
-
-
- getnameinfo – gets the host name using IP address of this host.
Parameters:
-
-
- sa – pointer to struct sockaddr, where the IP address and port number of host placed.
- salen – length of struct sockaddr.
- host – pointer to space for host name storing.
- hostlen – length of host name string.
- serv – pointer to service name string.
- servlen – length of service name string.
- flags – flags that modify behavior of this function (currently not support):
-
- NI_NAMEREQD
- If set, then an error is returned if the hostname cannot be determined.
- NI_DGRAM
- If set, then the service is a datagram (UDP) based rather than stream (TCP) based. This is required for the few ports (512-514) that have different services for UDP and TCP.
- NI_NOFQDN
- If set, return only the hostname part of the fully qualified domain name for local hosts.
- NI_NUMERICHOST
- If set, then the numeric form of the hostname is returned. (When not set, this will still happen in case the node’s name cannot be determined.)
- NI_NUMERICSERV
- If set, then the numeric form of the service address is returned. (When not set, this will still happen in case the service’s name cannot be determined.)
-
- getaddrinfo – gets the IP address using the name of the host.
Parameters:
-
-
- nodename – pointer to the name of internet node, for example “www.google.com”.
- servname – pointer to service name string.
- hints – pointer to an addrinfo structure that specifies criteria for selecting the socket address structures returned in the list pointed to by res.
- res – pointer to the resulting addrinfo structure with the information about host.
-
struct addrinfo { int ai_flags; /* input flags */ int ai_family; /* protocol family for socket */ int ai_socktype; /* socket type */ int ai_protocol; /* protocol for socket */ socklen_t ai_addrlen; /* length of socket-address */ struct sockaddr *ai_addr; /* socket-address for socket */ char *ai_canonname; /* canonical name for service location (iff req) */ struct addrinfo *ai_next; /* pointer to next in list */ };
-
- freeaddrinfo – frees memory space used for host address information. This function used together with getaddrinfo.
Parameters:
-
- ai – pointer to the space of resulting addrinfo structure, which has to be freed.
EXAMPLE
struct sockaddr_in sa; struct sockaddr_in6 sa6; const struct sockaddr_in *sa_ptr = NULL; const struct sockaddr_in6 *sa_ptr6 = NULL; socklen_t salen, salen6; char *host = NULL; ... xprintf("\n\n\nStart DNS\n"); memset(&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = inet_addr("173.194.70.102");// set ipv4 adress for request salen = sa.sin_len = sizeof (struct sockaddr_in) ; sa_ptr = &sa; memset(&sa6, 0, sizeof(sa6)); sa6.sin6_family = AF_INET6; inet_pton(AF_INET6, "2a00:1450:400d:805::1001", &(sa6.sin6_addr));// set ipv6 adress for request sa6.sin6_scope_id = __IPV6_ADDR_SCOPE_LINKLOCAL; salen6 = sa6.sin6_len = sizeof (struct sockaddr_in6); sa_ptr6 = &sa6; /* * MANDATORY function !!! * Set DNS ip adress */ if (set_dns_server_address(IP_ADDR_OF_SERVER_V4 ,IP_ADDR_OF_SERVER_V6, (char *)tcpinit.eth_mac)== -1) xprintf ("set_dns_server_address ERROR\n"); /***************** getnameinfo *******************/ xprintf("\nTest getnameinfo\n"); host = (char*)malloc(MAX_NAME_LEN); if (host == NULL) { xprintf("dns err: memory allocation\n\r"); return NULL; } memset(host, 0, MAX_NAME_LEN); getnameinfo((const struct sockaddr* )sa_ptr, salen, // input parameters Ip adress and len host, MAX_NAME_LEN, // output host name and length NULL , 0, 0 //this parameters no use and set to 0 and NULL ); xprintf("\n"); xprintf("host with IPv4 adress 173.194.70.102 have name: %s\n", host); free (host); host = (char*)malloc(MAX_NAME_LEN); if (host == NULL) { xprintf("dns err: memory allocation\n\r"); return NULL; } memset(host, 0, MAX_NAME_LEN); getnameinfo((const struct sockaddr* )sa_ptr6, salen6, host, MAX_NAME_LEN, NULL , 0, 0); xprintf("\n"); xprintf("host with IPv6 adress 2a00:1450:400d:805::1001 have name: %s\n", host); free (host); /***************** getaddrinfo and freeaddrinfo *******************/ xprintf("\n"); xprintf("\nTest getaddrinfo and freeaddrinfo \n"); /*if you want work with both DNS servers */ xprintf("\n\n"); xprintf("Read Ipv4 and Ip6 adress from google.com , if server don't have adress return nothing \n"); memset(&hints, 0, sizeof(struct addrinfo)); getaddrinfo("google.com", NULL, NULL, &res); print_ip_adress (res); freeaddrinfo(res); xprintf("\nEnd read\n"); ... /*if you want work only with ipv4 DNS server set hints to AF_INET */ xprintf("\n\n"); xprintf("Read Ip4 adress from www.google.com , if server don't have adress return nothing \n\n"); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET; getaddrinfo("www.google.com", NULL, &hints, &res); print_ip_adress (res); freeaddrinfo(res); xprintf("\nEnd read\n");
NOTES
There is a demo available for the Unison and DSPnano DNS Client which can be found in installdir/demos.