Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/kj/cidr.h @ 69:33d812a61356
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 17:55:14 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 69:33d812a61356 |
---|---|
1 | |
2 // Copyright (c) 2013-2014 Sandstorm Development Group, Inc. and contributors | |
3 // Licensed under the MIT License: | |
4 // | |
5 // Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 // of this software and associated documentation files (the "Software"), to deal | |
7 // in the Software without restriction, including without limitation the rights | |
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 // copies of the Software, and to permit persons to whom the Software is | |
10 // furnished to do so, subject to the following conditions: | |
11 // | |
12 // The above copyright notice and this permission notice shall be included in | |
13 // all copies or substantial portions of the Software. | |
14 // | |
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
21 // THE SOFTWARE. | |
22 | |
23 #pragma once | |
24 | |
25 #include "common.h" | |
26 #include <cstdint> | |
27 | |
28 KJ_BEGIN_HEADER | |
29 | |
30 struct sockaddr; | |
31 | |
32 namespace kj { | |
33 | |
34 class CidrRange { | |
35 public: | |
36 CidrRange(StringPtr pattern); | |
37 | |
38 static CidrRange inet4(ArrayPtr<const byte> bits, uint bitCount); | |
39 static CidrRange inet6(ArrayPtr<const uint16_t> prefix, ArrayPtr<const uint16_t> suffix, | |
40 uint bitCount); | |
41 // Zeros are inserted between `prefix` and `suffix` to extend the address to 128 bits. | |
42 | |
43 uint getSpecificity() const { return bitCount; } | |
44 | |
45 bool matches(const struct sockaddr* addr) const; | |
46 bool matchesFamily(int family) const; | |
47 | |
48 String toString() const; | |
49 | |
50 private: | |
51 int family; | |
52 byte bits[16]; | |
53 uint bitCount; // how many bits in `bits` need to match | |
54 | |
55 CidrRange(int family, ArrayPtr<const byte> bits, uint bitCount); | |
56 | |
57 void zeroIrrelevantBits(); | |
58 }; | |
59 | |
60 } // namespace kj | |
61 | |
62 KJ_END_HEADER |