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.1.1.IPv4 only server #
NAME
IPv4 only 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 only tcp and udp server or tcpd provides IPv4 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 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.
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 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.
SPECIFIC OPTIONS (Compile time)
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):
Option | Default | Description | Values |
---|---|---|---|
TCP_PROTOCOL | 1 | Support of TCP protocol | Dec: 0 | 1 |
PPP_INTERFACE | 1 | Support of PPP protocol | Dec: 0 | 1 |
IPFILTER | 1 | Support of NAT technology | Dec: 0 | 1 |
GATEWAY | 1 | Support of packet forwarding and redirect | Dec: 0 | 1 |
MULTI_INTERFACE | 0 | Support of multiple physical network interfaces | Dec: 0 | 1 |
Tcpd initialization
The tcpd initiatization structure can be found in the file <tcpinit.h>:
// // tcpd initialization structure // struct tcpinit { uint_16 tcp_msgsize; /* size of message */ uint_32 tcp_default_gateway; /* default gateway */ int tcp_devport; /* device address */ int tcp_vector; /* device vector */ uint_32 tcp_IP_address; /* internet address */ unsigned char tcp_ether_address[6]; /* ethernet address */ unsigned char tcp_padding[2]; /* padding */ int tcp_level; /* device int level */ int tcp_unit; /* unit number */ char *tcp_pool_start; /* buffer address */ uint tcp_pool_size; /* buffer size */ char tcp_devname[8]; /* device name */ };
Structure fields description:
- tcp_msgsize – size of tcpinit structure
- tcp_default_gateway – default gateway IP-address in hex representation
- tcp_devport – network device hardware address, depend on ethernet hardware and target chip architecture
- tcp_vector – network device interrupt vector or number, depend on ethernet hardware and target chip architecture
- tcp_IP_address – target IP-address in hex representation
- tcp_ether_address – ethernet MAC address
- tcp_padding – padding for memory alignment
- tcp_level – network device interrupt priority, depend on ethernet hardware and target chip architecture
- tcp_unit – network interface number
- tcp_pool_start – start address for tcp-server memory
- tcp_pool_size – length of tcp-server memory buffer
- tcp_devname – network device name, i.e. “lo”, “eth”, …
EXAMPLE
This is an example of the various setup parameters for the tcpd – in this case using SPI communication with a enc28J60.
#define GW_IP_ADDR 0xf010a8c0 //"192.168.16.240" #define ETH_ADDR 0x100000 //enc28J60 chip address #define ETH_INT_VECT 0 //Interrupt #0 #define ETH_INT_LEVEL 3 //Interrupt priority static char tcpbuf[1024*8]; struct tcpinit etherinit = { sizeof(struct tcpinit), /* message size */ GW_IP_ADDR, /* default gateway */ ETH_ADDR, /* address of ethernet chip */ ETH_INT_VECT, /* interrupt vector */ 0xc710a8c0, /* internet address *///"192.168.16.199" {0x00,0x11,0x22,0x33,0x44,0x55}, /* ethernet address */ {0,0}, /* padding */ ETH_INT_LEVEL, /* interrupt level */ 0, /* unit number */ tcpbuf, /* buffer pointer */ sizeof(tcpbuf), /* size of buffer */ {'l','e',0}, /* interface name */ };
This partial example shows the creation and registration of the tcpd using tcp_shell.
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, 2048); 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) { tcpd((char *)ðerinit, 0); }
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