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

Method fromAddress

src/main/java/core/org/xbill/DNS/ReverseMap.java:30–65  ·  view source on GitHub ↗

Creates a reverse map name corresponding to an address contained in an array of 4 bytes (for an IPv4 address) or 16 bytes (for an IPv6 address). @param addr The address from which to build a name. @return The name corresponding to the address in the reverse map.

(byte [] addr)

Source from the content-addressed store, hash-verified

28 * @return The name corresponding to the address in the reverse map.
29 */
30public static Name
31fromAddress(byte [] addr) {
32 if (addr.length != 4 && addr.length != 16)
33 throw new IllegalArgumentException("array must contain " +
34 "4 or 16 elements");
35
36 StringBuffer sb = new StringBuffer();
37 if (addr.length == 4) {
38 for (int i = addr.length - 1; i >= 0; i--) {
39 sb.append(addr[i] & 0xFF);
40 if (i > 0)
41 sb.append(".");
42 }
43 } else {
44 int [] nibbles = new int[2];
45 for (int i = addr.length - 1; i >= 0; i--) {
46 nibbles[0] = (addr[i] & 0xFF) >> 4;
47 nibbles[1] = (addr[i] & 0xFF) & 0xF;
48 for (int j = nibbles.length - 1; j >= 0; j--) {
49 sb.append(Integer.toHexString(nibbles[j]));
50 if (i > 0 || j > 0)
51 sb.append(".");
52 }
53 }
54 }
55
56 try {
57 if (addr.length == 4)
58 return Name.fromString(sb.toString(), inaddr4);
59 else
60 return Name.fromString(sb.toString(), inaddr6);
61 }
62 catch (TextParseException e) {
63 throw new IllegalStateException("name cannot be invalid");
64 }
65}
66
67/**
68 * Creates a reverse map name corresponding to an address contained in

Callers 1

getHostNameMethod · 0.95

Calls 6

fromStringMethod · 0.95
toByteArrayMethod · 0.95
toHexStringMethod · 0.80
getAddressMethod · 0.65
appendMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected