Conversion Support Function

Functions

char * inet_ntoa (uint32_t i_addr, char *s)
 Convert IP-address from 0xbbaaddcc to "aaa.bbb.ccc.ddd". More...
 
uint32_t inet_aton (char *s)
 Converts zero terminated IP-address string from "aaa.bbb.ccc.ddd" to integer in network byte order. More...
 
static uint16_t htons (uint16_t val)
 Convert a short int from host to network byte order. More...
 
static uint16_t ntohs (uint16_t val)
 Convert a short int from network to host byte order. More...
 
static uint32_t htonl (uint32_t val)
 Convert a long int from host to network byte order. More...
 
static uint32_t ntohl (uint32_t val)
 Convert a long int from network to host byte order. More...
 
static uint32_t nstohl (uint16_t val1, uint16_t val2)
 Convert two network short int to long host int. More...
 
static uint32_t nstonl (uint16_t val1, uint16_t val2)
 Convert two network short int to long. More...
 

Detailed Description

Function Documentation

char * inet_ntoa ( uint32_t  i_addr,
char *  s 
)
Parameters
i_addr- IP address in network-byte-order
s- buffer space for conversion
Returns
pointer to converted buffer

Convert IP address from network byte order to zero terminated ASCII string.
Usually all IP addresses in a network are stored and processed in network byte order. If the IP address of a specific connection should be printed out, use this conversion function.

Warning
Make sure the destination buffer is large enough to hold 16 characters (including terminating zero).
Library:
net.lib
Prototype:
net.h
//**************************************************************************
// print DSP IP address after DHCP request
//**************************************************************************
u_int32_t ip;
char buffer[20]; // small buffer for ip-address conversion
ip = get_ip_address (0);
printf (" assigned DSP IP-address: %s\r\n", inet_ntoa (ip, buffer));
Examples:
Blocksend.c, DHCPTest.c, DNSTest.c, Echo.c, FTPServer.c, Multicast.c, NetTest.c, Send.c, SMTP.c, and Telnet.c.
uint32_t inet_aton ( char *  s)
Parameters
s- ip address string
Returns
ip address in network byte order

Convert IP address string to network byte order.
Use this function to initialize a destination IP address before UDP send or to invalidate the ARP cache.

Note
Supported class delimiters are '.' and ','.
Library:
net.lib
Prototype:
net.h
1 arp_invalid_ip_address (inet_aton("192.168.168.8"));
static inline uint16_t htons ( uint16_t  val)
inlinestatic
Parameters
val- short int to convert
Returns
converted short int

Convert a short int from host to network byte order

Prototype:
net.h
Examples:
BoardSpecific.c.
1891 {
1892  return ((uint16_t)((((val) & 0xff) << 8) | ((val) & 0xff00) >> 8));
1893 }
unsigned short uint16_t
Definition: stdint.h:45
static inline uint16_t ntohs ( uint16_t  val)
inlinestatic
Parameters
val- short int to convert
Returns
converted short int

Convert a short int from network to host byte order

Prototype:
net.h
1905 {
1906  return ((uint16_t)((((val) & 0xff) << 8) | ((val) & 0xff00) >> 8));
1907 }
unsigned short uint16_t
Definition: stdint.h:45
static inline uint32_t htonl ( uint32_t  val)
inlinestatic
Parameters
val- long int to convert
Returns
converted long int

Convert a long int from host to network byte order

Prototype:
net.h
1918 {
1919  return ((uint32_t) ((((val) & 0xff) << 24 ) |
1920  (((val) & 0xff00) << 8 ) |
1921  (((val) & 0xff0000) >> 8 ) |
1922  ((val) & 0xff000000) >> 24));
1923 }
unsigned int uint32_t
Definition: stdint.h:47
static inline uint32_t ntohl ( uint32_t  val)
inlinestatic
Parameters
val- long int to convert
Returns
converted long int

Convert a long int from network to host byte order

Prototype:
net.h
1934 {
1935  return ((uint32_t) ((((val) & 0xff) << 16 ) |
1936  (((val) & 0xff00) << 16 ) |
1937  (((val) & 0xff0000) >> 16 ) |
1938  ((val) & 0xff000000) >> 16 ));
1939 }
unsigned int uint32_t
Definition: stdint.h:47
static inline uint32_t nstohl ( uint16_t  val1,
uint16_t  val2 
)
inlinestatic
Parameters
val1- high word
val2- low word
Returns
converted long int

Convert two network short int to long host int

Prototype:
net.h
1951 {
1952  return( (uint32_t) ( (((uint32_t)(val1) & 0xff) << 24 ) |
1953  (((uint32_t)(val1) & 0xff00) << 8 ) |
1954  (((uint32_t)(val2) & 0xff) << 8 ) |
1955  (((uint32_t)(val2) & 0xff00) >> 8 ) ) );
1956 }
unsigned int uint32_t
Definition: stdint.h:47
static inline uint32_t nstonl ( uint16_t  val1,
uint16_t  val2 
)
inlinestatic
Parameters
val1- high word
val2- low word
Returns
converted long int

Convert two network short int to long

Prototype:
net.h
1968 {
1969  return ((uint32_t)((((uint32_t)(val1) & 0xffff) << 16 ) |
1970  ((uint32_t)(val2) & 0xffff) ));
1971 }
unsigned int uint32_t
Definition: stdint.h:47