MCPcopy Create free account
hub / github.com/catboost/catboost / IsValidIPv6

Function IsValidIPv6

library/cpp/netliba/v6/udp_address.cpp:16–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15namespace NNetliba {
16 static bool IsValidIPv6(const char* sz) {
17 enum {
18 S1,
19 SEMICOLON,
20 SCOPE
21 };
22 int state = S1, scCount = 0, digitCount = 0, hasDoubleSemicolon = false;
23 while (*sz) {
24 if (state == S1) {
25 switch (*sz) {
26 case '0':
27 case '1':
28 case '2':
29 case '3':
30 case '4':
31 case '5':
32 case '6':
33 case '7':
34 case '8':
35 case '9':
36 case 'A':
37 case 'B':
38 case 'C':
39 case 'D':
40 case 'E':
41 case 'F':
42 case 'a':
43 case 'b':
44 case 'c':
45 case 'd':
46 case 'e':
47 case 'f':
48 ++digitCount;
49 if (digitCount > 4)
50 return false;
51 break;
52 case ':':
53 state = SEMICOLON;
54 ++scCount;
55 break;
56 case '%':
57 state = SCOPE;
58 break;
59 default:
60 return false;
61 }
62 ++sz;
63 } else if (state == SEMICOLON) {
64 if (*sz == ':') {
65 if (hasDoubleSemicolon)
66 return false;
67 hasDoubleSemicolon = true;
68 ++scCount;
69 digitCount = 0;
70 state = S1;
71 ++sz;
72 } else {
73 digitCount = 0;

Callers 1

ParseInetNameFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected