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.1.2. IPv4/IPv6 server #
NAME
IPv4/IPv6 TCP and UDP Server – tcpd
SYNOPSIS
#include <tcpinit.h>
#include <sys/socket.h>
#include <netinet/in.h>
- pthread_create(&pid, &attr, &tcp_shell, 0);
DESCRIPTION
The IPv4/IPv6 tcp and udp server or tcpd provides IPv4/IPv6 TCP, UDP and IP protocols support with low level drivers for specific chip support packages. It is a fast and easy to use TCP/UDP solution which requires a simple setup structure at creation time to get it up and running. It offers static IP addresses in IPv4 format or a DHCP client for IP address retrieval. It offers static routing tables, multiple interfaces and great small packet performance on processors with less than 32K of RAM. IPv6 protocol uses automaticaly configured link-local IP address based on host MAC.
The tcpd is an extensively modified version of the zero copy BSD implementation. It has been reduced in size and provides standard BSD socket services including support for select. It has been in the field in various incarnations for over 20 years.
The tcpd is initialized using the structure defined in tcpinit.h. It is passed to the tcpd from tcp_shell which starts the actual server passing in the parameter. The structure works this way for historical reasons – it could easily be restructured to take the parameter in the pthread_create call and start the server directly. For future reasons relating to parallelization of the tcpd, this change was not made.
The tcpd has several compile time options to reduce server size and several initialization options to reduce system size. Through recompilation, a udp only solution may be created reducing total system size to under 11K bytes. Initialization options which are geared to reducing the buffer sizes are tunable to trade off performance and size. Multiple interfaces are compile time options.
The tcpd has some commands supports specific ioctl().
The tcpd also has several add on features that many will be interested in. These features include:
- dhcp client
- dhcp server
- ppp
- NAT with PAT
More details can be found in the appropriate server and services man pages for these add on servers and services.
Compile time options
The tcpd compile time options can be found in the file <tcpdconfig.h> from server directory. All options can be defined as 0 (OFF) or 1 (ON):
IPv4 options
-
- IPv4_ENABLE:
–
0
-
- : support IPv4 protocol;
-
- –
1
-
- : not support IPv4 protocol.
-
- PPP_INTERFACE:
–
0
-
- : not support PPP protocol;
-
- –
1
-
- : support PPP protocol.
-
- NAT:
–
0
-
- : not support NAT technology;
-
- –
1
-
- : support NAT technology.
-
- IP4_FORWARD:
–
0
-
- : not support IPv4 packet forward;
-
- –
1
-
- : support IPv4 packet forward.
-
- IP_SOOPT:
–
0
-
- : not support IPv4 socket option;
-
- –
1
-
- : support IPv4 socket option.
-
- IGMP_PROTOCOL:
–
0
-
- : not support IGMP for IPv4;
-
- –
1
-
- : support IGMP for IPv4.
IPv6 options
-
- IPv6_ENABLE:
–
0
-
- : support IPv6 protocol;
-
- –
1
-
- : not support IPv6 protocol.
-
- DAD_TRANSMIT:
–
0
-
- : not support Duplicated Address Detection;
-
- –
1
-
- : support Duplicated Address Detection.
-
- IP6_FORWARD:
–
0
-
- : not support IPv6 packet forward;
-
- –
1
-
- : support IPv6 packet forward.
-
- IP6_SOOPT:
–
0
-
- : not support IPv6 socket option;
-
- –
1
-
- : support IPv6 socket option.
-
- MLD6_SUPPORT:
–
0
-
- : not support Multicast Listener Discovery;
-
- –
1
-
- : support Multicast Listener Discovery.
-
- ICMP6_TO_SOCKET:
–
0
-
- : allow read icmp6 data from socket;
-
- –
1
-
- : do not allow read icmp6 data from socket.
-
- ICMP6_RTSOL:
–
0
-
- : not support Receive Router Solicitation Message;
-
- –
1
-
- : support Receive Router Solicitation Message.
-
- ICMP6_RTADV:
–
0
-
- : not support Receive Router Advertisement Message;
-
- –
1
-
- : support Receive Router Advertisement Message.
-
- ICMP6_REDIRECT:
–
0
-
- : not support redirect messages;
-
- –
1
-
- : support redirect messages.
-
- IN6_CONTROL:
–
0
-
- : not support IPv6 interfaces ioctl() control;
-
- –
1
-
- : support IPv6 interfaces ioctl() control.
-
- IN6_DETACH:
–
0
-
- : not support IPv6 interfaces detach;
-
- –
1
-
- : support IPv6 interfaces detach.
-
- IP6_MTUDISC:
–
0
-
- : not support MTU discovery for IPv6;
-
- –
1
-
- : support MTU discovery for IPv6.
-
- IP6_FRAG:
–
0
-
- : not support IPv6 packets fragmentation;
-
- –
1
-
- : support IPv6 packets fragmentation.
Physical interfaces options
-
- ETHER_ENABLE:
–
0
-
- : support Ethernet protocol;
-
- –
1
-
- : not support Ethernet protocol.
-
- LOWPAN_ENABLE:
–
0
-
- : support LoWPAN protocol;
-
- –
1
-
- : not support LoWPAN protocol.
-
- WIFI_ENABLE:
–
0
-
- : support Wi-Fi protocol;
-
- –
1
-
- : not support Wi-Fi protocol.
Common options
-
- TCPN_INTERFACE:
–
0
-
- : support only one physical network interface;
-
- –
1
-
- : support multiple physical network interfaces.
-
- TCP_PROTOCOL:
–
0
-
- : not support TCP protocol;
-
- –
1
-
- : support TCP protocol.
-
- TCP_DEBUG:
–
0
-
- : support tcp socket trace with SO_DEBUG;
-
- –
1
-
- : not support tcp socket trace with SO_DEBUG.
-
- SOCK_CONTROL:
–
0
-
- : disable extended socket control options;
-
- –
1
-
- : enable extended socket control options.
-
- IP_MULTICAST:
–
0
-
- : not support multicast;
-
- –
1
-
- : support multicast.
-
- IF_DETACH:
–
0
-
- : not support interface detach;
-
- –
1
-
- : support interface detach.
-
- IP_AUTOPORT_CTL:
–
0
-
- : enable advanced automatic bind port control for IPv4;
-
- –
1
-
- : disavle advanced automatic bind port control for IPv4.
-
- PKTS_RATE_LIMIT:
–
0
-
- : not support packets rate limitation;
-
- –
1
-
- : support packets rate limitation.
tcp-server statistics
-
- IP_STATISTICS
- ICMP_STATISTICS
- IN6_STATISTICS
- IP6_STATISTICS
- ICMP6_STATISTICS
- ROUTE_STATISTICS
- UDP_STATISTICS
- TCP_STATISTICS
- MBUF_STATISTICS
- IGMP_STATISTICS
–
0
-
- : not support statistic counters;
-
- –
1
-
- : support statistic counters.
Tcpd initialization
The tcpd initiatization structure can be found in the file <tcpinit.h>:
// // tcpd initialization structure // struct tcpinit { char * tcp_pool_start; /* buffer address */ uint tcp_pool_size; /* buffer size */ uint_8 dev_type; /* device type */ uint_8 dev_unit; /* device number */ int dev_addr; /* device address */ int dev_vector; /* device vector */ int dev_level; /* device int level */ union { struct eth_settings eth; struct ieee802154_settings ieee802154; } dev; struct IP_settings IPv4; /* IPv4 settings */ char *IPv4_default_gateway; /* IPv4 default gateway */ struct IP_settings IPv6; /* IPv6 settings */ char *IPv6_default_gateway; /* IPv6 default gateway */ };
Structure fields description:
- tcp_pool_start – start address for tcp-server memory
- tcp_pool_size – length of tcp-server memory buffer
- dev_type – device type, i.e. DEV_ETHERNET, DEV_IEEE802154, DEV_IEEE80211
- dev_unit – device number
- dev_addr – device address
- dev_vector – device vector
- dev_level – device interrupt level
- struct eth_settings eth – ethernet settings
- struct ieee802154_settings ieee802154 – IEEE 802.15.4 settings
- struct IP_settings IPv4 – IPv4 settings
- IPv4_default_gateway – IPv4 default gateway
- struct IP_settings IPv6 – IPv6 settings
- IPv6_default_gateway – IPv6 default gateway
EXAMPLE
This partial example shows the setup, creation and registration of the tcpd using tcp_shell.
#define ETH_ADDR 0x01 // phy address #define ETH_INT_VECT ETH_IRQn // interrupt vector #define ETH_INT_LEVEL (1<<4) | 1 // interrupt priority THREAD Main() { pthread_t pid; pthread_attr_t attr; struct sched_param myNewPriority; ... pthread_attr_init(&attr); myNewPriority.sched_priority = 5; pthread_attr_setschedparam(&attr, &myNewPriority); pthread_attr_setstacksize(&attr, 2560); if(pthread_create(&pid, &attr, &tcp_shell, 0)!=0) { xprintf("pthread_create = %d\n", errno); pthread_exit(0); } if(dir_register("/dev/tcpd", pid, TYPE_SERVER)==0) { xprintf("dir_register = %d\n", errno); pthread_exit(0); } ... } THREAD tcp_shell(void *arg) { // clear init structure memset(&tcpinit, 0, sizeof(tcpinit)); // memory tcpinit.tcp_pool_start = tcpbuf; tcpinit.tcp_pool_size = sizeof(tcpbuf); // device tcpinit.dev_type = DEV_ETHERNET; tcpinit.dev_unit = 0; tcpinit.dev_addr = ETH_ADDR; tcpinit.dev_vector = ETH_INT_VECT; tcpinit.dev_level = ETH_INT_LEVEL; tcpinit.eth_mac[0] = 0x00; tcpinit.eth_mac[1] = 0x11; tcpinit.eth_mac[2] = 0x22; tcpinit.eth_mac[3] = 0x33; tcpinit.eth_mac[4] = 0x44; tcpinit.eth_mac[5] = 0x55; // IPv4 tcpinit.IPv4.IP_address = "192.168.16.199"; tcpinit.IPv4.IP_mask = "255.255.255.0"; tcpinit.IPv4_default_gateway = "192.168.16.1"; // IPv6 tcpinit.IPv6.IP_address = "2001:0db9::99"; tcpinit.IPv6.IP_prefix = 32; tcpinit.IPv6_default_gateway = "2001:0db9::1"; tcpd(&tcpinit); return 0; //just to avoid warning }
NOTES
There is several demos available for the Unison and DSPnano tcpd which are found in installdir/demos which provide examples of using the server with blocking and non-blocking sockets, select, and a variety of services including tftp, telnet, and more.
SEE ALSO
socket(), bind(), accept(), recv(), listen(), send(), select(), dhcp client service, dhcp server, ppp server, Network Address Translation