MySQL 9.0.0
Source Code Documentation
item_inetfunc.cc File Reference
#include "sql/item_inetfunc.h"
#include "my_config.h"
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include "my_byteorder.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/udf_registration_types.h"
#include "mysqld_error.h"
#include "sql/current_thd.h"
#include "sql/derror.h"
#include "sql/enum_query_type.h"
#include "sql/item.h"
#include "sql/sql_error.h"
#include "sql_string.h"
#include <netinet/in.h>

Functions

static bool str_to_ipv4 (const char *str, int str_length, in_addr *ipv4_address)
 Tries to convert given string to binary IPv4-address representation. More...
 
static bool str_to_ipv6 (const char *str, int str_length, in6_addr *ipv6_address)
 Tries to convert given string to binary IPv6-address representation. More...
 
static void ipv4_to_str (const in_addr *ipv4, char *str)
 Converts IPv4-binary-address to a string. More...
 
static void ipv6_to_str (const in6_addr *ipv6, char *str)
 Converts IPv6-binary-address to a string. More...
 

Variables

static const int IN_ADDR_SIZE = sizeof(in_addr)
 
static const int IN6_ADDR_SIZE = sizeof(in6_addr)
 
static const int IN6_ADDR_NUM_WORDS = IN6_ADDR_SIZE / 2
 
static const char HEX_DIGITS [] = "0123456789abcdef"
 

Function Documentation

◆ ipv4_to_str()

static void ipv4_to_str ( const in_addr ipv4,
char *  str 
)
static

Converts IPv4-binary-address to a string.

This function is a portable alternative to inet_ntop(AF_INET).

Parameters
[in]ipv4IPv4-address data (byte array)
[out]strA buffer to store string representation of IPv4-address. It must be at least of INET_ADDRSTRLEN.
Note
The problem with inet_ntop() is that it is available starting from Windows Vista, but the minimum supported version is Windows 2000.

◆ ipv6_to_str()

static void ipv6_to_str ( const in6_addr *  ipv6,
char *  str 
)
static

Converts IPv6-binary-address to a string.

This function is a portable alternative to inet_ntop(AF_INET6).

Parameters
[in]ipv6IPv6-address data (byte array)
[out]strA buffer to store string representation of IPv6-address. It must be at least of INET6_ADDRSTRLEN.
Note
The problem with inet_ntop() is that it is available starting from Windows Vista, but out the minimum supported version is Windows 2000.

◆ str_to_ipv4()

static bool str_to_ipv4 ( const char *  str,
int  str_length,
in_addr ipv4_address 
)
static

Tries to convert given string to binary IPv4-address representation.

This is a portable alternative to inet_pton(AF_INET).

Parameters
strString to convert.
str_lengthString length.
[out]ipv4_addressBuffer to store IPv4-address.
Returns
Completion status.
Return values
falseGiven string does not represent an IPv4-address.
trueThe string has been converted successfully.
Note
The problem with inet_pton() is that it treats leading zeros in IPv4-part differently on different platforms.

◆ str_to_ipv6()

static bool str_to_ipv6 ( const char *  str,
int  str_length,
in6_addr *  ipv6_address 
)
static

Tries to convert given string to binary IPv6-address representation.

This is a portable alternative to inet_pton(AF_INET6).

Parameters
strString to convert.
str_lengthString length.
[out]ipv6_addressBuffer to store IPv6-address.
Returns
Completion status.
Return values
falseGiven string does not represent an IPv6-address.
trueThe string has been converted successfully.
Note
The problem with inet_pton() is that it treats leading zeros in IPv4-part differently on different platforms.

Variable Documentation

◆ HEX_DIGITS

const char HEX_DIGITS[] = "0123456789abcdef"
static

◆ IN6_ADDR_NUM_WORDS

const int IN6_ADDR_NUM_WORDS = IN6_ADDR_SIZE / 2
static

◆ IN6_ADDR_SIZE

const int IN6_ADDR_SIZE = sizeof(in6_addr)
static

◆ IN_ADDR_SIZE

const int IN_ADDR_SIZE = sizeof(in_addr)
static