NCBI C++ ToolKit
|
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... | |
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.
Definition at line 507 of file ncbi_ipv6.c.
References buf, bufsize, int, kIPv4DNS, kIPv6DNS, len, n, SIPDNSsfx::sfx, tmp, and x_NcbiIsIPv4().
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.
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().
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.
Definition at line 697 of file ncbi_ipv6.c.
References assert, eNcbiIP_Dns, len, s_StringToAddr(), and str().
Referenced by NcbiParseIPRange().
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.
Definition at line 679 of file ncbi_ipv6.c.
References assert, eNcbiIP_Dot, len, s_StringToAddr(), and str().
Referenced by NcbiParseIPRange(), and SERV_ReadInfoEx().
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.
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().
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.
Definition at line 463 of file ncbi_ipv6.c.
References buf, bufsize, and x_IPv4ToString().
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.
Definition at line 737 of file ncbi_ipv6.c.
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.
Definition at line 763 of file ncbi_ipv6.c.
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).
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().
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.
Definition at line 476 of file ncbi_ipv6.c.
References buf, bufsize, and x_IPv6ToString().
Referenced by dns_a(), and NcbiDumpIPRange().
int NcbiIsEmptyIPv6 | ( | const TNCBI_IPv6Addr * | addr | ) |
Return non-zero if the address is empty (either as IPv6 or IPv4); return zero otherwise.
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().
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.
Definition at line 706 of file ncbi_ipv6.c.
References mask, n, and TNCBI_IPv6Addr::octet.
Referenced by NcbiIsInIPRange().
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.
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().
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.
compat | non-zero causes IPv4-compatible IPv6 addresses to pass the test |
Definition at line 95 of file ncbi_ipv6.c.
References x_NcbiIsIPv4().
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.
Definition at line 688 of file ncbi_ipv6.c.
References assert, eNcbiIP_Dns, eNcbiIP_Dot, len, s_StringToAddr(), and str().
Referenced by x_StringToAddr().
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.
Definition at line 346 of file ncbi_ipv6.c.
References isspace(), len, n, str(), and x_StringToIPv4().
Referenced by NcbiParseIPRange(), and x_CheckDomain().
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.
Definition at line 365 of file ncbi_ipv6.c.
References isspace(), len, n, str(), and x_StringToIPv6().