NCBI C++ ToolKit
Macros | Functions
ncbi_localnet.c File Reference
#include "../ncbi_ansi_ext.h"
#include "../ncbi_priv.h"
#include <connect/ncbi_socket.h>
#include <connect/ext/ncbi_localnet.h>
#include <stdlib.h>
#include <sys/types.h>
#include <netinet/in.h>
+ Include dependency graph for ncbi_localnet.c:

Go to the source code of this file.

Go to the SVN repository for this file.

Macros

#define INADDR_LOOPBACK   0x7F000001
 
#define SizeOf(a)   (sizeof(a) / sizeof((a)[0]))
 

Functions

static int x_IsPrivateIP (unsigned int addr)
 
int NcbiIsPrivateIP (unsigned int ip)
 Return non-zero (true) if the IP address (in network byte order) provided as an agrument, is a nonroutable private IP address (including loopback, multicast, and RFC1918); return zero (false) otherwise. More...
 
static int x_IsAPIPA (unsigned int addr)
 
int NcbiIsAPIPA (unsigned int ip)
 Return non-zero (true) if the IP address (in network byte order) provided as an agrument, is an Automatic Private IP Address (APIPA); return zero (false) otherwise. More...
 
static int s_IsPrivateIP (unsigned int ip)
 
static const TNCBI_IPv6Addrx_StringToAddr (TNCBI_IPv6Addr *addr, const char *str)
 
static const char * s_SearchTrackingEnv (const char *name, const char *const *tracking_env)
 
static const char * s_SearchForwardedFor (TNCBI_IPv6Addr *addr, const char *const *tracking_env)
 
TNCBI_IPv6Addr NcbiGetCgiClientIPv6Ex (ECgiClientIP flag, char *buf, size_t buf_size, const char *const *tracking_env)
 Same as NcbiGetCgiClientIPEx but IPv6-aware. More...
 
TNCBI_IPv6Addr NcbiGetCgiClientIPv6 (ECgiClientIP flag, const char *const *tracking_env)
 Same as NcbiGetCgiClientIPv6Ex(., NULL, 0, .) More...
 
unsigned int NcbiGetCgiClientIPEx (ECgiClientIP flag, char *buf, size_t buf_size, const char *const *tracking_env)
 
unsigned int NcbiGetCgiClientIP (ECgiClientIP flag, const char *const *tracking_env)
 Same as NcbiGetCgiClientIPEx(., NULL, 0, .) More...
 
int NcbiIsLocalCgiClient (const char *const *tracking_env)
 Return non-zero (true) if called from within a CGI that was invoked by an NCBI local client; zero otherwise. More...
 

Macro Definition Documentation

◆ INADDR_LOOPBACK

#define INADDR_LOOPBACK   0x7F000001

Definition at line 45 of file ncbi_localnet.c.

◆ SizeOf

#define SizeOf (   a)    (sizeof(a) / sizeof((a)[0]))

INADDR_LOOPBACK

Definition at line 51 of file ncbi_localnet.c.

Function Documentation

◆ NcbiGetCgiClientIP()

unsigned int NcbiGetCgiClientIP ( ECgiClientIP  flag,
const char *const tracking_env 
)

Same as NcbiGetCgiClientIPEx(., NULL, 0, .)

See also
NcbiGetCgiClientIPEx

Definition at line 364 of file ncbi_localnet.c.

References NcbiGetCgiClientIPEx().

◆ NcbiGetCgiClientIPEx()

unsigned int NcbiGetCgiClientIPEx ( ECgiClientIP  flag,
char *  buf,
size_t  buf_size,
const char *const tracking_env 
)

Definition at line 353 of file ncbi_localnet.c.

References buf, NcbiGetCgiClientIPv6Ex(), and NcbiIPv6ToIPv4().

Referenced by NcbiGetCgiClientIP().

◆ NcbiGetCgiClientIPv6()

TNCBI_IPv6Addr NcbiGetCgiClientIPv6 ( ECgiClientIP  flag,
const char *const tracking_env 
)

Same as NcbiGetCgiClientIPv6Ex(., NULL, 0, .)

See also
NcbiGetCgiClientIPv6Ex

Definition at line 346 of file ncbi_localnet.c.

References NcbiGetCgiClientIPv6Ex().

Referenced by CHttpRequest::GetClientIP(), and NcbiIsLocalCgiClient().

◆ NcbiGetCgiClientIPv6Ex()

TNCBI_IPv6Addr NcbiGetCgiClientIPv6Ex ( ECgiClientIP  flag,
char *  buf,
size_t  buf_size,
const char *const tracking_env 
)

Same as NcbiGetCgiClientIPEx but IPv6-aware.

IPv4 addresses packed as IPv6. Returns an empty IPv6 address when NcbiGetCgiClientIPEx() would return 0.

See also
NcbiGetCgiClientIPEx

Definition at line 221 of file ncbi_localnet.c.

References assert, buf, CORE_LOG, eCgiClientIP_TryAll, eCgiClientIP_TryLeast, eLOG_Trace, free(), i, NcbiIPv6ToIPv4(), NcbiIsEmptyIPv6(), NcbiIsLocalIPEx, s_IsPrivateIP(), s_SearchForwardedFor(), s_SearchTrackingEnv(), SizeOf, and x_StringToAddr().

Referenced by NcbiGetCgiClientIPEx(), and NcbiGetCgiClientIPv6().

◆ NcbiIsAPIPA()

int NcbiIsAPIPA ( unsigned int  ip)

Return non-zero (true) if the IP address (in network byte order) provided as an agrument, is an Automatic Private IP Address (APIPA); return zero (false) otherwise.

Definition at line 104 of file ncbi_localnet.c.

References ip, SOCK_NetToHostLong, and x_IsAPIPA().

Referenced by NcbiGetHostIfConfEx().

◆ NcbiIsLocalCgiClient()

int NcbiIsLocalCgiClient ( const char *const tracking_env)

Return non-zero (true) if called from within a CGI that was invoked by an NCBI local client; zero otherwise.

Parameters
tracking_envstring array with the tracking environment, or if NULL then the process environment (as provided by the run-time library) is used

Definition at line 371 of file ncbi_localnet.c.

References eCgiClientIP_TryAll, NcbiGetCgiClientIPv6(), NcbiIsLocalIPEx, and s_SearchTrackingEnv().

◆ NcbiIsPrivateIP()

int NcbiIsPrivateIP ( unsigned int  ip)

Return non-zero (true) if the IP address (in network byte order) provided as an agrument, is a nonroutable private IP address (including loopback, multicast, and RFC1918); return zero (false) otherwise.

Definition at line 89 of file ncbi_localnet.c.

References ip, SOCK_NetToHostLong, and x_IsPrivateIP().

◆ s_IsPrivateIP()

static int s_IsPrivateIP ( unsigned int  ip)
static

Definition at line 113 of file ncbi_localnet.c.

References ip, SOCK_NetToHostLong, x_IsAPIPA(), and x_IsPrivateIP().

Referenced by NcbiGetCgiClientIPv6Ex(), and s_SearchForwardedFor().

◆ s_SearchForwardedFor()

static const char* s_SearchForwardedFor ( TNCBI_IPv6Addr addr,
const char *const tracking_env 
)
static

◆ s_SearchTrackingEnv()

static const char* s_SearchTrackingEnv ( const char *  name,
const char *const tracking_env 
)
static

◆ x_IsAPIPA()

static int x_IsAPIPA ( unsigned int  addr)
static

Definition at line 98 of file ncbi_localnet.c.

Referenced by NcbiIsAPIPA(), and s_IsPrivateIP().

◆ x_IsPrivateIP()

static int x_IsPrivateIP ( unsigned int  addr)
static

Definition at line 61 of file ncbi_localnet.c.

References IN_LOOPBACKNET, and INADDR_LOOPBACK.

Referenced by NcbiIsPrivateIP(), and s_IsPrivateIP().

◆ x_StringToAddr()

static const TNCBI_IPv6Addr* x_StringToAddr ( TNCBI_IPv6Addr addr,
const char *  str 
)
static
Modified on Fri Sep 20 14:57:48 2024 by modify_doxy.py rev. 669887