NCBI C++ ToolKit
Enumerations | Functions
ncbi_localnet.h File Reference
#include <connect/ncbi_ipv6.h>
#include <connect/ncbi_localip.h>
+ Include dependency graph for ncbi_localnet.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Go to the SVN repository for this file.

Enumerations

enum  ECgiClientIP { eCgiClientIP_TryAll = 0 , eCgiClientIP_TryMost = 1 , eCgiClientIP_TryLeast = 2 }
 Return IP address (in network byte order) of the CGI client, and optionally store the client hostname in a user-supplied buffer (if the size is not adequate to accomodate the result, then it is not stored). More...
 

Functions

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...
 
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...
 
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...
 
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...
 
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...
 

Enumeration Type Documentation

◆ ECgiClientIP

Return IP address (in network byte order) of the CGI client, and optionally store the client hostname in a user-supplied buffer (if the size is not adequate to accomodate the result, then it is not stored).

Return 0 if the IP address cannot be obtained; however, the text form of the host can still be stored in the provided buffer (check for '\0' at [0]).

Warning
Result is generally undefined if called not from within a CGI executable.
Parameters
flagmodifies the search algorithm: most users would want to specify eCgiClientIP_TryAll (and those who are absolutely sure that the requests cannot be coming from the older NI facility of the C Toolkit, would want to use eCgiClientIP_TryMost); eCgiClientIP_TryLeast causes the search to ignore the special "Client-Host:" tag that can indicate the real origin of the request (when this request is made on behalf of the indicated IP)
bufbuffer where the client host (a hostname or textual representation of the network address as provided by the web-server) will be saved (may be NULL not to save)
buf_sizethe size of the buffer (must be large enough, truncation not allowed)
tracking_envstring array with the tracking environment, or if NULL then the process environment (as provided by the run-time library) is used
Warning
FCGI applications *must* use CCgiRequest::GetClientTrackingEnv() to obtain proper tracking environment per each request
See also
CCgiRequest::GetClientTrackingEnv()
Enumerator
eCgiClientIP_TryAll 

Try all env.vars (NI_CLIENT_IPADDR incl.)

eCgiClientIP_TryMost 

Try most of known environment variables.

eCgiClientIP_TryLeast 

Try to detect caller's IP only,not origin.

Definition at line 109 of file ncbi_localnet.h.

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().

Modified on Mon Apr 22 04:05:54 2024 by modify_doxy.py rev. 669887