Skip to content

File host_lookup.c

FileList > connection > host_lookup.c

Go to the source code of this file

  • #include <stdio.h>
  • #include <stdlib.h>
  • #include <math.h>
  • #include <string.h>
  • #include <limits.h>
  • #include <errno.h>
  • #include <unordered_map>
  • #include <arpa/inet.h>
  • #include <netdb.h>
  • #include <pthread.h>
  • #include "host_lookup.h"
  • #include "porting.h"
  • #include "system_parameter.h"
  • #include "environment_variable.h"
  • #include "message_catalog.h"
  • #include "memory_wrapper.hpp"

Public Types

Type Name
enum HOSTENT_INSERT_TYPE
enum HOSTS_CONF_LOAD_STATUS
enum HOST_LOOKUP_TYPE
enum LOOKUP_TYPE

Public Attributes

Type Name
return_phase __pad0__
else = /* multi line expression */

Public Static Attributes

Type Name
struct hostent * hostent_Cache
std::unordered_map< std::string, int > user_host_Map

Public Functions

Type Name
void freeaddrinfo_uhost (struct addrinfo * res)
int getaddrinfo_uhost (char * node, char * service, struct addrinfo * hints, struct addrinfo ** res)
struct hostent * gethostbyname_uhost (const char * name)
int getnameinfo_uhost (struct sockaddr * addr, socklen_t addrlen, char * host, size_t hostlen, char * serv, size_t servlen, int flags)
if (prm_get_bool_value(PRM_ID_USE_USER_HOSTS)==USE_GLIBC_HOSTS)
bool validate_uhost_conf (void)

Public Static Functions

Type Name
int add_user_host_map (const char * ipaddr, const char * hostname, int cache_idx)
bool handle_uhost_conf (int action_type)
struct hostent * host_lookup_internal (const char * hostname, struct sockaddr * saddr, LOOKUP_TYPE lookup_type)
struct hostent * hostent_alloc (const char * ipaddr, const char * hostname)
int is_valid_fqdn (const char * fqdn)
bool is_valid_ipv4 (const char * ip_addr)
int is_valid_label (const char * label)
int load_hosts_file (void)
void strcpy_ucase (char * dst, size_t len, const char * src)

Macros

Type Name
define ADD_ENTRY_SUCCESS 0
define CUBRID_HOSTS_CONF "cubrid\_hosts.conf"
define DUPLICATE_ENTRY 1
define ERROR_ALLOC -1
define FREE_MEM (PTR) /* multi line expression */
define HOSTNAME_LEN (256)
define IPADDR_LEN (17)
define IPv4_ADDR_LEN (4)
define LINE_BUF_SIZE (512)
define MALLOC (SIZE) [**malloc**](memory__cwrapper_8h.md#define-malloc)(SIZE)
define MAX_FQDN_LEN (255)
define MAX_LABEL_LEN (63)
define MAX_NUM_HOSTS (256)
define MAX_NUM_IPADDR_PER_HOST (1)
define MTIME_DIGITS (10)
define NUM_DIGIT (VAL) ([**size\_t**](broker__monitor_8c.md#function-timeout))([**log10**](broker__monitor_8c.md#function-timeout) ([**VAL**](broker__monitor_8c.md#function-timeout)) + 1)
define NUM_IPADDR_DOT (3)
define UHOST_CONF_LOAD 2
define UHOST_CONF_VALID_CHECK 1

Public Types Documentation

enum HOSTENT_INSERT_TYPE

enum HOSTENT_INSERT_TYPE {
    INSERT_IPADDR = 0,
    INSERT_HOSTNAME = 1
};

enum HOSTS_CONF_LOAD_STATUS

enum HOSTS_CONF_LOAD_STATUS {
    LOAD_FAIL = -1,
    LOAD_INIT,
    LOAD_SUCCESS
};

enum HOST_LOOKUP_TYPE

enum HOST_LOOKUP_TYPE {
    USE_GLIBC_HOSTS = 0,
    USE_USER_DEFINED_HOSTS = 1
};

enum LOOKUP_TYPE

enum LOOKUP_TYPE {
    HOSTNAME_TO_IPADDR = 0,
    IPADDR_TO_HOSTNAME = 1
};

Public Attributes Documentation

variable __pad0__

return_phase __pad0__;

variable else

else;

Public Static Attributes Documentation

variable hostent_Cache

struct hostent* hostent_Cache[(256)];

variable user_host_Map

std::unordered_map<std::string, int> user_host_Map;

Public Functions Documentation

function freeaddrinfo_uhost

void freeaddrinfo_uhost (
    struct  addrinfo * res
) 

function getaddrinfo_uhost

int getaddrinfo_uhost (
    char * node,
    char * service,
    struct  addrinfo * hints,
    struct  addrinfo ** res
) 

function gethostbyname_uhost

struct  hostent * gethostbyname_uhost (
    const  char * name
) 

function getnameinfo_uhost

int getnameinfo_uhost (
    struct  sockaddr * addr,
    socklen_t addrlen,
    char * host,
    size_t hostlen,
    char * serv,
    size_t servlen,
    int flags
) 

function if

if (
    prm_get_bool_value ( PRM_ID_USE_USER_HOSTS )== USE_GLIBC_HOSTS
) 

function validate_uhost_conf

bool validate_uhost_conf (
    void
) 

Public Static Functions Documentation

function add_user_host_map

static int add_user_host_map (
    const  char * ipaddr,
    const  char * hostname,
    int cache_idx
) 

Adds a valid IP and hostname to the user_host_Map and updates the cache.


function handle_uhost_conf

static bool handle_uhost_conf (
    int action_type
) 

This function processes the uhosts.conf file based on the specified action_type. It can either: * Load the IP addresses and hostnames from the configuration file into the user_host_Map. * Check the validity of the IP addresses and hostnames in the configuration file.

  • UHOST_CONF_VALID_CHECK: Validates the IP addresses and hostnames in the cubrid_uhosts.conf file.
  • UHOST_CONF_LOAD: Loads the valid IP addresses and hostnames.

function host_lookup_internal

static struct  hostent * host_lookup_internal (
    const  char * hostname,
    struct  sockaddr * saddr,
    LOOKUP_TYPE lookup_type
) 

function hostent_alloc

static struct  hostent * hostent_alloc (
    const  char * ipaddr,
    const  char * hostname
) 

function is_valid_fqdn

static int is_valid_fqdn (
    const  char * fqdn
) 

Checks if a given string is a valid Fully Qualified Domain Name (FQDN).

An FQDN must: * Not exceed 253 characters in length. * Have labels that are 1 to 63 characters long. * Contain only alphanumeric characters and hyphens. * Not start or end with a hyphen in any label. * Not be empty or NULL.


function is_valid_ipv4

static bool is_valid_ipv4 (
    const  char * ip_addr
) 

function is_valid_label

static int is_valid_label (
    const  char * label
) 

function load_hosts_file

static int load_hosts_file (
    void
) 

function strcpy_ucase

static void strcpy_ucase (
    char * dst,
    size_t len,
    const  char * src
) 

Macro Definition Documentation

define ADD_ENTRY_SUCCESS

#define ADD_ENTRY_SUCCESS `0`

define CUBRID_HOSTS_CONF

#define CUBRID_HOSTS_CONF `"cubrid_hosts.conf"`

define DUPLICATE_ENTRY

#define DUPLICATE_ENTRY `1`

define ERROR_ALLOC

#define ERROR_ALLOC `-1`

define FREE_MEM

#define FREE_MEM (
    PTR
) `/* multi line expression */`

define HOSTNAME_LEN

#define HOSTNAME_LEN `(256)`

define IPADDR_LEN

#define IPADDR_LEN `(17)`

define IPv4_ADDR_LEN

#define IPv4_ADDR_LEN `(4)`

define LINE_BUF_SIZE

#define LINE_BUF_SIZE `(512)`

define MALLOC

#define MALLOC (
    SIZE
) `malloc (SIZE)`

define MAX_FQDN_LEN

#define MAX_FQDN_LEN `(255)`

define MAX_LABEL_LEN

#define MAX_LABEL_LEN `(63)`

define MAX_NUM_HOSTS

#define MAX_NUM_HOSTS `(256)`

define MAX_NUM_IPADDR_PER_HOST

#define MAX_NUM_IPADDR_PER_HOST `(1)`

define MTIME_DIGITS

#define MTIME_DIGITS `(10)`

define NUM_DIGIT

#define NUM_DIGIT (
    VAL
) `( size_t )( log10 ( VAL ) + 1)`

define NUM_IPADDR_DOT

#define NUM_IPADDR_DOT `(3)`

define UHOST_CONF_LOAD

#define UHOST_CONF_LOAD `2`

define UHOST_CONF_VALID_CHECK

#define UHOST_CONF_VALID_CHECK `1`


The documentation for this class was generated from the following file cubrid/src/connection/host_lookup.c