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.2. DHCP Client Service - dhcp client #
NAME
DHCP Client Service – dhcp
SYNOPSIS
#include <tcpinit.h>
#include <sys/socket.h>
#include < netinet/in.h>
#include < arpa/inet.h >
- int dhcp_get_params (struct tcpinit *init, _dhcp_params * param);
// For dual TCP stack:
- int dhcp_get_params (unsigned char *mac, char *if_name, _dhcp_params *param);
DESCRIPTION
The tcp and udp server or tcpd provides IPv4/IPv6 TCP, UDP and IP protocol 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 unless provisioned with the DHCP client service for IP address retrieval.
The dhcp client service uses the standard dhcp protocol to lease an IPv4 address from a IPv4 dhcp server. Typically, these servers are included in routers and are configured for IPv4 subnets to provide local network IP addresses. Both the client and the server are easily setup.
More precisely, the dhcp client service is actually a library that is called and does not run as a separate thread. This library uses the calling thread’s context and sets up the etherinit structure for use with tcpd. It implements the standard dhcp client protocol in the library and returns control to the calling thread when complete.
SPECIFIC OPTIONS
These options applicable not only for dual stack, but as well for old stack:
Option | Default | Description | Placement |
---|---|---|---|
IP_ADDR_OF_HOST | inet_addr(“192.168.16.5“) | IP address of host to which test UDP packets will be sent | demo |
WAIT_ANSWER_INTERVAL_US | 200000 | Time interval in microseconds for waiting of DHCP-server answer | library |
EXAMPLE
This is an example of the various setup parameters for the tcpd – in this case using SPI communication with a 28J60:
#define GW_IP_ADDR 0xf010a8c0 //"192.168.16.240" #define ENC_ADDR 0x100000 #define ENC_INT_VECT 0 //Interrupt 0 #define ENC_INT_LEVEL 3 static char tcpbuf[1024*8]; struct tcpinit etherinit = { sizeof(struct tcpinit), /* message size */ GW_IP_ADDR, /* default gateway */ ENC_ADDR, /* address of enc28j60 chip */ ENC_INT_VECT, /* interrupt vector */ 0, /* internet address */ {0x00,0x11,0x22,0x33,0x44,0x55}, /* ethernet address */ {0,0}, /* padding */ ENC_INT_LEVEL, /* interrupt level */ 0, /* unit number */ tcpbuf, /* buffer pointer */ sizeof(tcpbuf), /* size of buffer */ {'l','e',0}, /* interface name */ };
This is an example of the setup parameters for the tcpd under dual stack:
#define ENC_ADDR 0x100000 #define ENC_INT_VECT 0 //Interrupt 0 #define ENC_INT_LEVEL 3 static char tcpbuf[1024*16] __attribute__ ((aligned (2048))); struct tcpinit tcpinit; 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 = ENC_ADDR; tcpinit.dev_vector = ENC_INT_VECT; tcpinit.dev_level = ENC_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 = NULL; tcpinit.IPv4.IP_mask = NULL; tcpinit.IPv4_default_gateway = NULL; tcpd(&tcpinit); return 0; //just to avoid warning }
This partial example shows the creation and registration of the tcpd using tcp_shell followed with the lease of an IP address and discovery of the default gateway.
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); } // Try to get our IP and default GW if (dhcp_get_params (ðerinit, &dhcp_param) == -1) { xprintf("DHCP could not get params! errno = %d\n", errno); while (1) sleep(1); } xprintf("Get DHCP params:\n"); xprintf(" Client IP: %d.%d.%d.%d\n", ((unsigned char *)ðerinit.tcp_IP_address)[0], ((unsigned char *)ðerinit.tcp_IP_address)[1], ((unsigned char *)ðerinit.tcp_IP_address)[2], ((unsigned char *)ðerinit.tcp_IP_address)[3]); xprintf(" Default GW IP: %d.%d.%d.%d\n", ((unsigned char *)ðerinit.tcp_default_gateway)[0], ((unsigned char *)ðerinit.tcp_default_gateway)[1], ((unsigned char *)ðerinit.tcp_default_gateway)[2], ((unsigned char *)ðerinit.tcp_default_gateway)[3]);
The example for dual stack:
... // Try to get our IP and default GW if (dhcp_get_params (tcpinit.eth_mac, "eth0", &dhcp_param) == -1) { xprintf("DHCP could not get params! errno = %d\n", errno); while (1) sleep(1); } ...
NOTES
There is a demo available for the Unison and DSPnano dhcp client server which is found in installdir/demos.