NCBI C++ ToolKit
Classes | Functions
ncbi_ipv6.h File Reference
#include <connect/connect_export.h>
#include <stddef.h>
+ Include dependency graph for ncbi_ipv6.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Go to the SVN repository for this file.

Classes

struct  TNCBI_IPv6Addr
 

Functions

int NcbiIsEmptyIPv6 (const TNCBI_IPv6Addr *addr)
 Return non-zero if the address is empty (either as IPv6 or IPv4); return zero otherwise. More...
 
int NcbiIsIPv4 (const TNCBI_IPv6Addr *addr)
 Return non-zero(true) if the address is a true IPv4 address (a mapped IPv4 address); return zero(false) otherwise. More...
 
int NcbiIsIPv4Ex (const TNCBI_IPv6Addr *addr, int compat)
 Return non-zero(true) if the address is either a mapped IPv4 address or (optionally) an IPv4-compatible IPv6 address; return zero(false) otherwise. More...
 
unsigned int NcbiIPv6ToIPv4 (const TNCBI_IPv6Addr *addr, size_t pfxlen)
 Extract and return a network byte order IPv4 embedded address from an IPv6 address, using the specified prefix length (RFC6052). More...
 
int NcbiIPv4ToIPv6 (TNCBI_IPv6Addr *addr, unsigned int ipv4, size_t pfxlen)
 Embed a passed network byte order IPv4 address into an IPv6 address using the specified prefix length (RFC6052). More...
 
const char * NcbiStringToIPv4 (unsigned int *addr, const char *str, size_t len)
 Convert into a network byte order IPv4 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str" from a full-quad decimal notation. More...
 
const char * NcbiStringToIPv6 (TNCBI_IPv6Addr *addr, const char *str, size_t len)
 Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str" from a hexadecimal colon-separated notation (including full-quad trailing IPv4). More...
 
const char * NcbiIPToAddr (TNCBI_IPv6Addr *addr, const char *str, size_t len)
 Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str" from either a full-quad decimal IPv4 or a hexadecimal colon-separated IPv6. More...
 
const char * NcbiDNSIPToAddr (TNCBI_IPv6Addr *addr, const char *str, size_t len)
 Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str", which can be either an .in-addr.arpa- or an .in6.arpa-domain names. More...
 
const char * NcbiStringToAddr (TNCBI_IPv6Addr *addr, const char *str, size_t len)
 Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str", which can be either of a full-quad decimal IPv4, a hexadecimal colon-separated IPv6, an .in-addr.arpa- or an .in6.arpa-domain names. More...
 
char * NcbiIPv4ToString (char *buf, size_t bufsize, unsigned int addr)
 Convert a network byte order IPv4 into a full-quad text form and store the result in the "buf" of size "bufsize". More...
 
char * NcbiIPv6ToString (char *buf, size_t bufsize, const TNCBI_IPv6Addr *addr)
 Convert an IPv6 address into a hex colon-separated text form and store the result in the "buf" of size "bufsize". More...
 
char * NcbiAddrToString (char *buf, size_t bufsize, const TNCBI_IPv6Addr *addr)
 Convert an IPv6 address into either a full-quad text IPv4 (for IPv4-mapped IPv6 addresses) or a hex colon-separated text form (for all other), and store the result in the "buf" of size "bufsize". More...
 
const char * NcbiAddrToDNS (char *buf, size_t bufsize, const TNCBI_IPv6Addr *addr)
 Convert an IPv6 address into either .in-addr.arpa domain (for IPv4-mapped IPv6 addresses) or .ip6.arpa domain (for all other), and store the result in the "buf" of size "bufsize". More...
 
int NcbiIsInIPv6Network (const TNCBI_IPv6Addr *base, unsigned int bits, const TNCBI_IPv6Addr *addr)
 Return non-zero(true) if "addr" belongs to the network specified as CIDR "base/bits"; return a zero(false) otherwise. More...
 
int NcbiIPv6Subnet (TNCBI_IPv6Addr *addr, unsigned int bits)
 Retain first "bits" in a given "addr", resetting all remaining bits to 0. More...
 
int NcbiIPv6Suffix (TNCBI_IPv6Addr *addr, unsigned int bits)
 Retain last "bits" in a given "addr", resetting all remaining bits to 0. More...
 

Function Documentation

◆ NcbiAddrToDNS()

const char* NcbiAddrToDNS ( char *  buf,
size_t  bufsize,
const TNCBI_IPv6Addr addr 
)

Convert an IPv6 address into either .in-addr.arpa domain (for IPv4-mapped IPv6 addresses) or .ip6.arpa domain (for all other), and store the result in the "buf" of size "bufsize".

Return non-zero string address past the stored result, or 0 when the conversion failed for buffer being too small. In either case, if "buf" is non-NULL and "bufsize" is at least one, "buf" gets '\0'-terminated: in case of an error (NULL return) this results in an empty string at "buf", and in case of a non-NULL return value the returned pointer points to the terminating '\0' byte.

See also
NcbiAddrToString, NcbiDNSIPToAddr

Definition at line 507 of file ncbi_ipv6.c.

References buf, bufsize, int, kIPv4DNS, kIPv6DNS, len, n, SIPDNSsfx::sfx, tmp, and x_NcbiIsIPv4().

◆ NcbiAddrToString()

char* NcbiAddrToString ( char *  buf,
size_t  bufsize,
const TNCBI_IPv6Addr addr 
)

Convert an IPv6 address into either a full-quad text IPv4 (for IPv4-mapped IPv6 addresses) or a hex colon-separated text form (for all other), and store the result in the "buf" of size "bufsize".

Return non-zero string address past the stored result, or 0 when the conversion failed for buffer being too small. In either case, if "buf" is non-NULL and "bufsize" is at least one, "buf" gets '\0'-terminated: in case of an error (NULL return) this results in an empty string at "buf", and in case of a non-NULL return value the returned pointer points to the terminating '\0' byte.

See also
NcbiStringToAddr, NcbiAddrToDNS, SOCK_ntoa, SOCK_HostPortToString

Definition at line 490 of file ncbi_ipv6.c.

References buf, bufsize, NcbiIPv6ToIPv4(), x_IPv4ToString(), x_IPv6ToString(), and x_NcbiIsIPv4().

Referenced by SERV_WriteInfo(), x_HostOfInfo(), x_SetHostPort(), and x_UpdateHost().

◆ NcbiDNSIPToAddr()

const char* NcbiDNSIPToAddr ( TNCBI_IPv6Addr addr,
const char *  str,
size_t  len 
)

Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str", which can be either an .in-addr.arpa- or an .in6.arpa-domain names.

Return a non-zero string pointer to the first non-converted character; return 0 if no conversion can be made.

See also
NcbiAddrToDNS, NcbiStringToAddr

Definition at line 697 of file ncbi_ipv6.c.

References assert, eNcbiIP_Dns, len, s_StringToAddr(), and str().

Referenced by NcbiParseIPRange().

◆ NcbiIPToAddr()

const char* NcbiIPToAddr ( TNCBI_IPv6Addr addr,
const char *  str,
size_t  len 
)

Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str" from either a full-quad decimal IPv4 or a hexadecimal colon-separated IPv6.

Return a non-zero string pointer to the first non-converted character (which is neither a [hex-]digit, nor a colon, nor a dot); return 0 if no conversion can be made.

See also
NcbiStringToIPv4, NcbiStringToIPv6, NcbiStingToAddr, NcbiAddrToString

Definition at line 679 of file ncbi_ipv6.c.

References assert, eNcbiIP_Dot, len, s_StringToAddr(), and str().

Referenced by NcbiParseIPRange(), and SERV_ReadInfoEx().

◆ NcbiIPv4ToIPv6()

int NcbiIPv4ToIPv6 ( TNCBI_IPv6Addr addr,
unsigned int  ipv4,
size_t  pfxlen 
)

Embed a passed network byte order IPv4 address into an IPv6 address using the specified prefix length (RFC6052).

Return zero when the specified prefix length is not valid, non-zero otherwise. A special case (and the most anticipated common use-case) is to use prefix length 0, which first clears the passed IPv6 address, then embeds the IPv4 address as a mapped address using the prefix length of 96.

See also
NcbiIsIPv4, NcbiIPv6ToIPv4

Definition at line 142 of file ncbi_ipv6.c.

References assert, and ncbi::grid::netcache::search::fields::size.

Referenced by dns_a(), NcbiIsLocalIP(), NcbiParseIPRange(), s_LoadLocalIPs(), s_StringToAddr(), SERV_AddrOfInfo(), SERV_ReadInfoEx(), x_StringToAddr(), x_UpdateHost(), and xx_LoadLocalIPs().

◆ NcbiIPv4ToString()

char* NcbiIPv4ToString ( char *  buf,
size_t  bufsize,
unsigned int  addr 
)

Convert a network byte order IPv4 into a full-quad text form and store the result in the "buf" of size "bufsize".

Return non-zero string address past the stored result, or 0 when the conversion failed for buffer being too small. In either case, if "buf" is non-NULL and "bufsize" is at least one, "buf" gets '\0'-terminated: in case of an error (NULL return) this results in an empty string at "buf", and in case of a non-NULL return value the returned pointer points to the terminating '\0' byte.

See also
NcbiStringToIPv4, SOCK_ntoa, SOCK_HostPortToString

Definition at line 463 of file ncbi_ipv6.c.

References buf, bufsize, and x_IPv4ToString().

◆ NcbiIPv6Subnet()

int NcbiIPv6Subnet ( TNCBI_IPv6Addr addr,
unsigned int  bits 
)

Retain first "bits" in a given "addr", resetting all remaining bits to 0.

Return non-zero(true) if the resultant "addr" is non-empty; return a zero(false) otherwise.

Note
"addr" remains unmodified for "bits" larger than 127, so this call becomes functionally (but less efficiently) equivalent to negation of NcbiIsEmptyIPv6().
See also
NcbiIsEmptyIPv6, NcbiIsInIPv6Network, NcbiIPv6Suffix

Definition at line 737 of file ncbi_ipv6.c.

References mask, and n.

◆ NcbiIPv6Suffix()

int NcbiIPv6Suffix ( TNCBI_IPv6Addr addr,
unsigned int  bits 
)

Retain last "bits" in a given "addr", resetting all remaining bits to 0.

Return non-zero(true) if the resultant "addr" is non-empty; return a zero(false) otherwise.

Note
"addr" remains unmodified for "bits" larger than 127, so this call becomes functionally (but less efficiently) equivalent to negation of NcbiIsEmptyIPv6().
See also
NcbiIsEmptyIPv6, NcbiIPv6Subnet

Definition at line 763 of file ncbi_ipv6.c.

References mask, and n.

◆ NcbiIPv6ToIPv4()

unsigned int NcbiIPv6ToIPv4 ( const TNCBI_IPv6Addr addr,
size_t  pfxlen 
)

Extract and return a network byte order IPv4 embedded address from an IPv6 address, using the specified prefix length (RFC6052).

Return INADDR_NONE (-1 = 255.255.255.255) when the specified prefix length is not valid. A special case (and the most anticipated common use-case) is to use prefix length 0, which checks that the passed IPv6 address is actually a mapped or compatible IPv4 address, then extracts it using the prefix length of 96. Return 0 if the extraction cannot be made (not an IPv4 mapped/compatible address).

See also
NcbiIsIPv4, NcbiIPv4ToIPv6

Definition at line 101 of file ncbi_ipv6.c.

References assert, ncbi::grid::netcache::search::fields::size, and x_NcbiIsIPv4().

Referenced by dns_a(), NcbiAddrToString(), NcbiDumpIPRange(), NcbiGetCgiClientIPEx(), NcbiGetCgiClientIPv6Ex(), NcbiIsEmptyIPv6(), NcbiIsInIPRange(), NcbiParseIPRange(), NcbiTrueIPRange(), s_SearchForwardedFor(), SERV_ReadInfoEx(), and x_UpdateHost().

◆ NcbiIPv6ToString()

char* NcbiIPv6ToString ( char *  buf,
size_t  bufsize,
const TNCBI_IPv6Addr addr 
)

Convert an IPv6 address into a hex colon-separated text form and store the result in the "buf" of size "bufsize".

Return non-zero string address past the stored result, or 0 when the conversion failed for buffer being too small. In either case, if "buf" is non-NULL and "bufsize" is at least one, "buf" gets '\0'-terminated: in case of an error (NULL return) this results in an empty string at "buf", and in case of a non-NULL return value the returned pointer points to the terminating '\0' byte.

See also
NcbiStringToIPv6, NcbiStringToAddr, NcbiAddrToString

Definition at line 476 of file ncbi_ipv6.c.

References buf, bufsize, and x_IPv6ToString().

Referenced by dns_a(), and NcbiDumpIPRange().

◆ NcbiIsEmptyIPv6()

int NcbiIsEmptyIPv6 ( const TNCBI_IPv6Addr addr)

Return non-zero if the address is empty (either as IPv6 or IPv4); return zero otherwise.

See also
NcbiIsIPv4

Definition at line 80 of file ncbi_ipv6.c.

References memcchr, NcbiIPv6ToIPv4(), and x_NcbiIsIPv4().

Referenced by dns_a(), NcbiGetCgiClientIPv6Ex(), NcbiIsLocalIPEx(), NcbiParseIPRange(), NcbiTrueIPRange(), s_SearchForwardedFor(), SERV_AddrOfInfo(), SERV_EqualInfo(), SERV_GetServers(), x_UpdateHost(), and xx_LoadLocalIPs().

◆ NcbiIsInIPv6Network()

int NcbiIsInIPv6Network ( const TNCBI_IPv6Addr base,
unsigned int  bits,
const TNCBI_IPv6Addr addr 
)

Return non-zero(true) if "addr" belongs to the network specified as CIDR "base/bits"; return a zero(false) otherwise.

Note
"base" is not checked to contain all zero bits beyond "bits" (as it should), but if it does not then the return value will always be a zero(false).
See also
NcbiIPv6Subnet

Definition at line 706 of file ncbi_ipv6.c.

References mask, n, and TNCBI_IPv6Addr::octet.

Referenced by NcbiIsInIPRange().

◆ NcbiIsIPv4()

int NcbiIsIPv4 ( const TNCBI_IPv6Addr addr)

Return non-zero(true) if the address is a true IPv4 address (a mapped IPv4 address); return zero(false) otherwise.

See also
NcbiIsIPv4Ex, NcbiIPv4ToIPv6, NcbiIPv6ToIPv4

Definition at line 89 of file ncbi_ipv6.c.

References x_NcbiIsIPv4().

Referenced by NcbiDumpIPRange(), NcbiIsInIPRange(), NcbiParseIPRange(), NcbiTrueIPRange(), SERV_GetServers(), SERV_ReadInfoEx(), SERV_WriteInfo(), and x_SetHostPort().

◆ NcbiIsIPv4Ex()

int NcbiIsIPv4Ex ( const TNCBI_IPv6Addr addr,
int  compat 
)

Return non-zero(true) if the address is either a mapped IPv4 address or (optionally) an IPv4-compatible IPv6 address; return zero(false) otherwise.

Parameters
compatnon-zero causes IPv4-compatible IPv6 addresses to pass the test
Note
NcbiIsIPv4Ex(, 0) is equivalent to NcbiIsIPv4()
See also
NcbiIsIPv4, NcbiIPv4ToIPv6, NcbiIPv6ToIPv4

Definition at line 95 of file ncbi_ipv6.c.

References x_NcbiIsIPv4().

◆ NcbiStringToAddr()

const char* NcbiStringToAddr ( TNCBI_IPv6Addr addr,
const char *  str,
size_t  len 
)

Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str", which can be either of a full-quad decimal IPv4, a hexadecimal colon-separated IPv6, an .in-addr.arpa- or an .in6.arpa-domain names.

Return a non-zero string pointer to the first non-converted character (which is neither a [hex-]digit, nor a colon, nor a dot); return 0 if no conversion can be made.

See also
NcbiAddrToString, NcbiAddrToDNS

Definition at line 688 of file ncbi_ipv6.c.

References assert, eNcbiIP_Dns, eNcbiIP_Dot, len, s_StringToAddr(), and str().

Referenced by x_StringToAddr().

◆ NcbiStringToIPv4()

const char* NcbiStringToIPv4 ( unsigned int addr,
const char *  str,
size_t  len 
)

Convert into a network byte order IPv4 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str" from a full-quad decimal notation.

Return a non-zero string pointer to the first non-converted character (which is neither a digit nor a dot); return 0 if conversion failed and no IPv4 address had been found.

Note
Unlike SOCK_gethostbyname[Ex], this call can handle correctly both "0.0.0.0" and "255.255.255.255".
See also
NcbiIPToAddr, NcbiIPv4ToIPv6, NcbiStringToAddr, SOCK_StringToHostPort, SOCK_gethostbyname[Ex]

Definition at line 346 of file ncbi_ipv6.c.

References isspace(), len, n, str(), and x_StringToIPv4().

Referenced by NcbiParseIPRange(), and x_CheckDomain().

◆ NcbiStringToIPv6()

const char* NcbiStringToIPv6 ( TNCBI_IPv6Addr addr,
const char *  str,
size_t  len 
)

Convert into an IPv6 address, the first "len" (or "strlen(str)" if "len" is 0) bytes of "str" from a hexadecimal colon-separated notation (including full-quad trailing IPv4).

Return a non-zero string pointer to the first non-converted character (which is neither a hex-digit, nor a colon, nor a dot); return 0 if conversion failed and no IPv6 address had been found.

See also
NcbiIPToAddr, NcbiStringToAddr

Definition at line 365 of file ncbi_ipv6.c.

References isspace(), len, n, str(), and x_StringToIPv6().

Modified on Fri Sep 20 14:57:25 2024 by modify_doxy.py rev. 669887