Unison Help
- 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.22.SNTP Client #
NAME
SNTP Client – sntpc
SYNOPSIS
#include <tcpinit.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h >
#include <sntp.h >
- int sntp_gettime(const char *srv_addr, struct timespec *ts);
// For dual TCP stack:
int sntp_gettime(const char *srv_addr, struct timespec *ts, int ip_ver);
DESCRIPTION
The SNTP Client gets time from NTP server.
Parameters:
- srv_addr – pointer to the string with NTP server IPv4 address.
- ts – pointer to timespec structure in which will be stored gotten time. If ts == NULL, time will be directly set as system time.
- ip_ver – version of IP protocol (4 or 6).
Return values:
- 0 – time successfully got from NTP server.
- -1 – error, see errno for detail.
SPECIFIC OPTIONS (Compile time)
| Option | Default | Description | Values |
|---|---|---|---|
| SNTPC_IP6_ENABLE | 0 | Enable SNTP request by using ipv6. | Dec: 0 | 1 |
| USE_DUAL_TCP_STACK | — | Specifies whether SNTP works with old TCP stack or dual TCP stack. For dual TCP stack – must be defined. | — |
EXAMPLE
This partial example shows the get time to user structure and set it as system time:
//get time to user structure
sntp_gettime("192.168.16.227", &ts);
xprintf("Get sntp time: %lu.%.9lu\n", (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec);
//get time and set it as system time
sntp_gettime("192.168.16.227", NULL);
clock_gettime(CLOCK_REALTIME, &ts);
xprintf("Get system time: %lu.%.9lu\n", (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec);
This partial example shows how to get time to user structure under dual TCP stack:
xprintf("\nipv4 interface\n");
//get time to user structure
sntp_gettime("192.168.16.227", &ts, 4);
xprintf("Get sntp time: %lu.%.9lu\n", (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec);
//get time and set it as system time
sntp_gettime("192.168.16.227", NULL, 4);
clock_gettime(CLOCK_REALTIME, &ts);
xprintf("Get system time: %lu.%.9lu\n", (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec);
#ifdef SNTPC_IP6_ENABLE
xprintf("\nipv6 interface\n");
//get time to user structure
sntp_gettime("fe80::1e6f:65ff:fe8f:5295", &ts, 6);
xprintf("Get sntp time: %lu.%.9lu\n", (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec);
//get time and set it as system time
sntp_gettime("fe80::1e6f:65ff:fe8f:5295", NULL, 6);
clock_gettime(CLOCK_REALTIME, &ts);
xprintf("Get system time: %lu.%.9lu\n", (unsigned long)ts.tv_sec, (unsigned long)ts.tv_nsec);
#endif
NOTES
There is a demo available for the Unison and DSPnano sntp client which is found in installdir/demos.
