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.20. AutoIP Service - autoip client #
NAME
AutoIP Service – autoip
SYNOPSIS
#include <tcpinit.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h >
- int get_autoip(struct tcpinit *etherinit);
// For dual TCP stack:
int get_autoip (unsigned char *mac, char *if_name);
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 or AutoIP service for IP address retrieval.
The autoip service generates an IPv4 address following the information from net interface and uses the standard ARP protocol to check if such IP already present on net. Generally there is two ways of using an AutoIP: standalone or together with DHCP client.
More precisely, the autoip 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 tcpinit structure for use with tcpd. It implements the standard autoip functions in the library and returns control to the calling thread when complete.
SPECIFIC OPTIONS (Compile time)
Option | Default | Description | Values | Placement |
---|---|---|---|---|
IP_ADDR_OF_HOST | inet_addr(“169.254.107.135”) | IP address of host to which test UDP packets will be sent (should be the same segment). | String | Demo |
TRY_DHCP | 0 | If set to “1” – allows first try to obtain IP from DHCP and if it was unsuccessful, use AutoIP. | Dec: 0 | 1 | Demo |
Net_test | 0 | If set to “1” – allows to use standart, or user defined network segment, for IP address obtaining. Useful for tests. | Dec: 0 | 1 | Library |
TEMP_IP | 0xA9FE0000 | Defines most significant two octets of IP address (network segment). May be used only for tests. | Hex., 4 bytes | Library |
RFC3927 | 0 | If set to “1” – defines full compliance of component to the RFC3927 Standard. Adds additional ARP sendings, which are not currently needed. | Dec: 0 | 1 | Library |
EXAMPLE
This is the example of the various setup parameters for the tcpd.
#define ETH_ADDR ETH_BASE #define ETH_INT_VECT INT_ETH #define ETH_INT_LEVEL 0x80 static char tcpbuf[1024*8]; struct tcpinit etherinit = { sizeof(struct tcpinit), /* message size */ 0, /* default gateway */ ETH_ADDR, /* address of ethernet chip */ ETH_INT_VECT, /* interrupt vector */ 0, /* internet address */ {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 is the example of the various setup parameters for the dual TCP stack.
/************************************************************************* * Subroutine : tcp_shell * Purpose : Task shell for starting device specific tcpserver ************************************************************************/ 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] = 0x66; // 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 set IP by AutoIP.
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); } // Set automatic IP xprintf("Using AutoIP...\n"); if(get_autoip(ðerinit) != 0) { xprintf("AutoIP could not get params!\n"); while (1) sleep(1); } xprintf("Get AutoIP params:\n"); xprintf(" Client IP: %d.%d.%d.%d\n", ((unsigned char *)& etherinit.tcp_IP_address)[0], ((unsigned char *)& etherinit.tcp_IP_address)[1], ((unsigned char *)& etherinit.tcp_IP_address)[2], ((unsigned char *)& etherinit.tcp_IP_address)[3]);
This partial example shows the process of setting IP by AutoIP for dual TCP stack.
#if TRY_DHCP // Try to get our IP and default GW xprintf("Using DHCP...\n"); dhcp_sts = dhcp_get_params (tcpinit.eth_mac, "eth0", &dhcp_param); if (dhcp_sts == -1) { xprintf("DHCP could not get params! errno = %d\n", errno); } #endif /* TRY_DHCP */ if (dhcp_sts == -1) { xprintf("Using AutoIP...\n"); if(get_autoip(tcpinit.eth_mac, "eth0") != 0) { xprintf("AutoIP could not get params!\n"); while (1) sleep(1); } }
NOTES
There is a demo available for the Unison and DSPnano AutoIP Service which can be found in installdir/demos.