NCBI C++ ToolKit
ncbi_localip.h
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CONNECT___NCBI_LOCALIP__H
2 #define CONNECT___NCBI_LOCALIP__H
3 
4 /* $Id: ncbi_localip.h 94296 2021-07-18 15:04:54Z lavr $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Anton Lavrentiev
30  *
31  * File Description:
32  * Determine IP locality (within NCBI) of a given address
33  *
34  * @warning
35  * Use <connect/ncbi_localip.hpp> in C++ code!
36  *
37  * @note
38  * This API works correctly only if used within NCBI.
39  *
40  */
41 
42 #include <connect/ncbi_ipv6.h>
43 
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 
50 /**
51  * Return non-zero (true) if the IP address (in network byte order) provided as
52  * an agrument, is a local one (i.e. belongs to NCBI); return zero (false)
53  * otherwise.
54  * @warning Loopback addresses are generally considered "local". If that is a
55  * security issue, analyze the address prior to passing it in to this call.
56  * @sa
57  * NcbiIsLocalIPEx, SOCK_IsLoopbackAddress
58  */
60 int/*bool*/ NcbiIsLocalIP(unsigned int ip);
61 
62 
63 typedef struct {
64  const char* sfx; /* textual domain suffix (may be truncated) */
65  unsigned int num; /* numerical domain sequence number (non-0) */
67 
68 
69 /**
70  * Return non-zero (true) if the IP address (in network byte order) provided as
71  * an agrument, is a local one (i.e. belongs to NCBI), and update domain info
72  * (when passed non-NULL) of the address, if available; return zero (false)
73  * otherwise.
74  * @note Domain information remains valid until a call for NcbiInitLocalIP().
75  * @warning Loopback addresses are generally considered "local". If that is a
76  * security issue, analyze the address prior to passing it in to this call.
77  * @sa
78  * NcbiIsLocalIP, NcbiInitLocalIP
79  */
81 int/*bool*/ NcbiIsLocalIPEx
82 (const TNCBI_IPv6Addr* addr, /**< Either true IPv6 or IPv6-mapped IPv4 */
83  SNcbiDomainInfo* info); /**< Optional, can be NULL for no info to get */
84 
85 
86 /**
87  * Init local IP classification.
88  * @note Generally the required initialization is done automagically, so this
89  * call need *not* to be used explicitly.
90  * @warning This call invalidates any domain information returned to client
91  * via the NcbiIsLocalIPEx() calls.
92  * @sa
93  * NcbiIsLocalIPEx, NcbiIsLocalIP
94  */
96 void NcbiInitLocalIP(void);
97 
98 
99 #ifdef __cplusplus
100 } /* extern "C" */
101 #endif
102 
103 
104 #endif /*CONNECT___NCBI_LOCALIP__H*/
static const char ip[]
Definition: des.c:75
#define NCBI_XCONNECT_EXPORT
static MDB_envinfo info
Definition: mdb_load.c:37
int NcbiIsLocalIP(unsigned int ip)
Return non-zero (true) if the IP address (in network byte order) provided as an agrument,...
Definition: ncbi_localip.c:420
void NcbiInitLocalIP(void)
Init local IP classification.
Definition: ncbi_localip.c:354
int NcbiIsLocalIPEx(const TNCBI_IPv6Addr *addr, SNcbiDomainInfo *info)
Return non-zero (true) if the IP address (in network byte order) provided as an agrument,...
Definition: ncbi_localip.c:362
unsigned int num
Definition: ncbi_localip.h:65
const char * sfx
Definition: ncbi_localip.h:64
Modified on Sat Dec 09 04:46:39 2023 by modify_doxy.py rev. 669887