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

Go to the SVN repository for this file.

1 #ifndef CONNECT___NCBI_IPRANGE__H
2 #define CONNECT___NCBI_IPRANGE__H
3 
4 /* $Id: ncbi_iprange.h 95392 2021-11-12 04:25:50Z 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  * IP range manipulating API
33  *
34  */
35 
36 #include <connect/ncbi_ipv6.h>
37 
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 typedef enum {
44  eIPRange_None = 0, /* invalid entry */
45  eIPRange_Host, /* a is set, b is 0 */
46  eIPRange_Range, /* a is set, b is set, IPv4 only */
47  eIPRange_Network, /* a is set, b is mask for IPv4, bits for IPv6 */
48  eIPRange_Application /* a and b application-specific */
50 
51 
52 typedef struct {
54  TNCBI_IPv6Addr a; /* IPv4 | IPv6 */
55  unsigned int b; /* IPv4 | bits */
56 } SIPRange;
57 
58 
60 int/*bool*/ NcbiIsInIPRange(const SIPRange* range,
61  const TNCBI_IPv6Addr* addr);
62 
63 
64 /* NB: NOP for IPv6 (which can be either "Host" or "Network") */
67 
68 
70 const char* NcbiDumpIPRange(const SIPRange* range, char* buf, size_t bufsize);
71 
72 
73 /** Acceptable forms (netmasked IPv4s may omit trailing .0s before '/'):
74  * 4 quad full IP: 123.123.123.123
75  * IPv4 range: 123.123.1-123 (meaning 123.123.1.0 thru 123.123.123.255)
76  * IPv4 w/netmask: 123.123/255.255.240.0 (equivalent to the following line)
77  * IPv4 CIDR: 123.123/20 (meaning 123.123.0.0 thru 123.123.15.255)
78  * IPv4 wildcard: 123.123.* (meaning 123.123.0.0 thru 123.123.255.255)
79  * IPv6[/CIDR]: aa:bb::cc/64 (IPv6 addr must be complete,/CIDR optional)
80  * hostname: DNS format
81  * @note
82  * IP subnets (both IPv4 and IPv6) require that the unmasked "host" portion
83  * of the address was 0 (otherwise, parsing fails).
84  * @return
85  * 0 (false) if failed; non-zero (true) if successful and the parsed range
86  * stored at the location pointed to by "range".
87  */
89 int/*bool*/ NcbiParseIPRange(SIPRange* range, const char* s);
90 
91 
92 #ifdef __cplusplus
93 } /* extern "C" */
94 #endif
95 
96 
97 #endif /*CONNECT___NCBI_IPRANGE__H*/
#define NCBI_XCONNECT_EXPORT
char * buf
range(_Ty, _Ty) -> range< _Ty >
EIPRangeType
Definition: ncbi_iprange.h:43
@ eIPRange_Network
Definition: ncbi_iprange.h:47
@ eIPRange_None
Definition: ncbi_iprange.h:44
@ eIPRange_Range
Definition: ncbi_iprange.h:46
@ eIPRange_Host
Definition: ncbi_iprange.h:45
@ eIPRange_Application
Definition: ncbi_iprange.h:48
int NcbiParseIPRange(SIPRange *range, const char *s)
Acceptable forms (netmasked IPv4s may omit trailing .0s before '/'): 4 quad full IP: 123....
Definition: ncbi_iprange.c:216
SIPRange NcbiTrueIPRange(const SIPRange *range)
Definition: ncbi_iprange.c:89
int NcbiIsInIPRange(const SIPRange *range, const TNCBI_IPv6Addr *addr)
Definition: ncbi_iprange.c:43
const char * NcbiDumpIPRange(const SIPRange *range, char *buf, size_t bufsize)
Definition: ncbi_iprange.c:144
static int bufsize
Definition: pcregrep.c:162
unsigned int b
Definition: ncbi_iprange.h:55
EIPRangeType type
Definition: ncbi_iprange.h:53
TNCBI_IPv6Addr a
Definition: ncbi_iprange.h:54
Modified on Sat Dec 02 09:20:32 2023 by modify_doxy.py rev. 669887