MCPcopy Create free account
hub / github.com/DeNA/PacketProxy / parseV4

Method parseV4

src/main/java/core/org/xbill/DNS/Address.java:23–70  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

21Address() {}
22
23private static byte []
24parseV4(String s) {
25 int numDigits;
26 int currentOctet;
27 byte [] values = new byte[4];
28 int currentValue;
29 int length = s.length();
30
31 currentOctet = 0;
32 currentValue = 0;
33 numDigits = 0;
34 for (int i = 0; i < length; i++) {
35 char c = s.charAt(i);
36 if (c >= '0' && c <= '9') {
37 /* Can't have more than 3 digits per octet. */
38 if (numDigits == 3)
39 return null;
40 /* Octets shouldn't start with 0, unless they are 0. */
41 if (numDigits > 0 && currentValue == 0)
42 return null;
43 numDigits++;
44 currentValue *= 10;
45 currentValue += (c - '0');
46 /* 255 is the maximum value for an octet. */
47 if (currentValue > 255)
48 return null;
49 } else if (c == '.') {
50 /* Can't have more than 3 dots. */
51 if (currentOctet == 3)
52 return null;
53 /* Two consecutive dots are bad. */
54 if (numDigits == 0)
55 return null;
56 values[currentOctet++] = (byte) currentValue;
57 currentValue = 0;
58 numDigits = 0;
59 } else
60 return null;
61 }
62 /* Must have 4 octets. */
63 if (currentOctet != 3)
64 return null;
65 /* The fourth octet can't be empty. */
66 if (numDigits == 0)
67 return null;
68 values[currentOctet] = (byte) currentValue;
69 return values;
70}
71
72private static byte []
73parseV6(String s) {

Callers 1

toByteArrayMethod · 0.95

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected