KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Utilities

Miscellaneous networking utilities More...

Files

file  inet.h
 Definitions for internet operations.
 

Functions

uint32_t htonl (uint32_t value)
 Convert a 32-bit value from host byte order to network byte order.
 
uint32_t ntohl (uint32_t value)
 Convert a 32-bit value from network byte order to host byte order.
 
uint16_t htons (uint16_t value)
 Convert a 16-bit value from host byte order to network byte order.
 
uint16_t ntohs (uint16_t value)
 Convert a 16-bit value from network byte order to host byte order.
 
in_addr_t inet_addr (const char *cp)
 Convert a string representation of an IPv4 address to an in_addr_t.
 
int inet_aton (const char *cp, struct in_addr *pin)
 Convert a string representation of an IPv4 address to a struct in_addr.
 
int inet_pton (int af, const char *src, void *dst)
 Convert a string representation of an IP address to its binary representation.
 
const char * inet_ntop (int af, const void *src, char *dst, socklen_t size)
 Convert a binary representation of an IP address to a string.
 
char * inet_ntoa (struct in_addr addr)
 Convert a binary representation of an IPv4 address to a string.
 

Detailed Description

Miscellaneous networking utilities

Function Documentation

◆ htonl()

uint32_t htonl ( uint32_t value)

Convert a 32-bit value from host byte order to network byte order.

Parameters
valueThe value to convert.
Returns
value converted to network byte order.

◆ htons()

uint16_t htons ( uint16_t value)

Convert a 16-bit value from host byte order to network byte order.

Parameters
valueThe value to convert.
Returns
value converted to network byte order.

◆ inet_addr()

in_addr_t inet_addr ( const char * cp)

Convert a string representation of an IPv4 address to an in_addr_t.

This function converts a "dotted-decimal" string representation of an IPv4 address to an in_addr_t for use in a struct in_addr. This function supports all POSIX-required formats for the representation of the address.

Parameters
cpA string representation of an IPv4 address.
Returns
The binary representation of the requested IPv4 address. (in_addr_t)(-1) is returned on error.

◆ inet_aton()

int inet_aton ( const char * cp,
struct in_addr * pin )

Convert a string representation of an IPv4 address to a struct in_addr.

This function, much like inet_addr, converts a string representation of an IPv4 address to a binary representation. This function, however, is non-standard (but seems to appear a lot of places). This function is a little nicer to work with than inet_addr simply because of the fact that the error return from inet_addr happens to actually correspond to a real IPv4 address (255.255.255.255). This version actually distinguishes between that address and invalid addresses.

Parameters
cpA string representation of an IPv4 address.
pinThe destination for the conversion.
Return values
0An invalid IPv4 address was given.
1Upon successful conversion.

◆ inet_ntoa()

char * inet_ntoa ( struct in_addr addr)

Convert a binary representation of an IPv4 address to a string.

This function does the exact opposite of the inet_addr function, converting a binary form of an address to a string. This function, unlike inet_ntop is non-reentrant (not thread-safe), and will always only support IPv4 addresses. It is suggested to use inet_ntop in any new code.

Parameters
addrThe address to convert.
Returns
A string representation of addr (in dotted-decimal form).

◆ inet_ntop()

const char * inet_ntop ( int af,
const void * src,
char * dst,
socklen_t size )

Convert a binary representation of an IP address to a string.

This function does the exact opposite of the inet_pton function, converting a binary form of an address to a string. This function, unlike inet_ntoa, is reentrant, and is the function that you should generally use if you need to convert a binary representation of an IP address to a string.

Parameters
afThe address family that src is in. The only supported values are AF_INET and AF_INET6.
srcA binary representation of an IP address.
dstStorage for the resulting string. This string should be at least 16-bytes long for IPv4, and 46 bytes for IPv6.
sizeThe length of dst.
Return values
NULLUpon failed conversion.
dstUpon successful conversion.
Error Conditions:
EAFNOSUPPORT - the specified address family is unsupported
ENOSPC - the size given is insufficient

◆ inet_pton()

int inet_pton ( int af,
const char * src,
void * dst )

Convert a string representation of an IP address to its binary representation.

This function, like inet_addr, converts a string representation of an IP address to its binary representation. This function, unlike inet_aton, is actually standard (in POSIX 2008), and operates very similarly. The only differences between this function and inet_aton are that this function does not support hexadecimal or octal representations and that this function has the ability to support IPv6. This is the function that you should actually use to convert addresses from strings to binary in new code, rather than inet_addr or inet_aton.

Parameters
afThe address family that src is an address in. The only supported values are AF_INET and AF_INET6.
srcA string representation of the address.
dstStorage for the result. For AF_INET, this must be at least 32-bits in size (the function treats it as a struct in_addr). For AF_INET6, this must be at least 128-bits in size (the function treats it as a struct in6_addr).
Return values
-1af is unsupported.
0An invalid address was given.
1Upon successful conversion.
Error Conditions:
EAFNOSUPPORT - the specified address family is unsupported

◆ ntohl()

uint32_t ntohl ( uint32_t value)

Convert a 32-bit value from network byte order to host byte order.

Parameters
valueThe value to convert.
Returns
value converted to host byte order.

◆ ntohs()

uint16_t ntohs ( uint16_t value)

Convert a 16-bit value from network byte order to host byte order.

Parameters
valueThe value to convert.
Returns
value converted to host byte order.