MySQL  8.0.27
Source Code Documentation
hostname_cache.h File Reference
#include "my_config.h"
#include <sys/types.h>
#include <list>
#include <memory>
#include "my_hostname.h"
#include "my_inttypes.h"
#include "mysql_com.h"
#include <netinet/in.h>

Go to the source code of this file.


struct  Host_errors
class  Host_entry
 An entry in the hostname hash table cache. More...


 Size of IP address string in the hash cache. More...
#define RC_OK   0
#define RC_BLOCKED_HOST   1
#define RC_LONG_HOSTNAME   2


int ip_to_hostname (struct sockaddr_storage *ip_storage, const char *ip_string, char **hostname, uint *connect_errors)
 Resolve IP-address to host name. More...
void inc_host_errors (const char *ip_string, Host_errors *errors)
void reset_host_connect_errors (const char *ip_string)
bool hostname_cache_init (uint size)
void hostname_cache_free ()
void hostname_cache_refresh (void)
uint hostname_cache_size ()
void hostname_cache_resize (uint size)
void hostname_cache_lock ()
void hostname_cache_unlock ()
std::list< std::unique_ptr< Host_entry > >::iterator hostname_cache_begin ()
std::list< std::unique_ptr< Host_entry > >::iterator hostname_cache_end ()

Macro Definition Documentation



Size of IP address string in the hash cache.


#define RC_BLOCKED_HOST   1


#define RC_LONG_HOSTNAME   2


#define RC_OK   0

Function Documentation

◆ hostname_cache_begin()

std::list<std::unique_ptr<Host_entry> >::iterator hostname_cache_begin ( )

◆ hostname_cache_end()

std::list<std::unique_ptr<Host_entry> >::iterator hostname_cache_end ( )

◆ hostname_cache_free()

void hostname_cache_free ( )

◆ hostname_cache_init()

bool hostname_cache_init ( uint  size)

◆ hostname_cache_lock()

void hostname_cache_lock ( )

◆ hostname_cache_refresh()

void hostname_cache_refresh ( void  )

◆ hostname_cache_resize()

void hostname_cache_resize ( uint  size)

◆ hostname_cache_size()

uint hostname_cache_size ( )

◆ hostname_cache_unlock()

void hostname_cache_unlock ( )

◆ inc_host_errors()

void inc_host_errors ( const char *  ip_string,
Host_errors errors 

◆ ip_to_hostname()

int ip_to_hostname ( struct sockaddr_storage *  ip_storage,
const char *  ip_string,
char **  hostname,
uint connect_errors 

Resolve IP-address to host name.

This function does the following things:

  • resolves IP-address;
  • employs Forward Confirmed Reverse DNS technique to validate IP-address;
  • returns host name if IP-address is validated;
  • set value to out-variable connect_errors – this variable represents the number of connection errors from the specified IP-address.
  • update the host_cache statistics

NOTE: connect_errors are counted (are supported) only for the clients where IP-address can be resolved and FCrDNS check is passed.

[in]ip_storageIP address (sockaddr). Must be set.
[in]ip_stringIP address (string). Must be set.
[out]hostnameHostname if IP-address is valid.
[out]connect_errorsRepresents number of connection errors.
Error status
Return values
RC_BLOCKED_HOSTThe host is blocked.
RC_LONG_HOSTNAMEThe hostname is longer than HOSTNAME_LENGTH.

The function does not set/report MySQL server error in case of failure. It's caller's responsibility to handle failures of this function properly.

◆ reset_host_connect_errors()

void reset_host_connect_errors ( const char *  ip_string)