1 package org.apache.commons.net.ntp; 2 17 18 25 public final class NtpUtils { 26 27 33 public static String getHostAddress(int address) 34 { 35 return ((address >>> 24) & 0xFF) + "." + 36 ((address >>> 16) & 0xFF) + "." + 37 ((address >>> 8) & 0xFF) + "." + 38 ((address >>> 0) & 0xFF); 39 } 40 41 47 public static String getRefAddress(NtpV3Packet packet) 48 { 49 int address = (packet == null) ? 0 : packet.getReferenceId(); 50 return getHostAddress(address); 51 } 52 53 62 public static String getReferenceClock(NtpV3Packet message) { 63 if (message == null) 64 return ""; 65 int refId = message.getReferenceId(); 66 if (refId == 0) 67 return ""; 68 StringBuffer buf = new StringBuffer (4); 69 for (int shiftBits = 24; shiftBits >= 0; shiftBits -= 8) 71 { 72 char c = (char) ((refId >>> shiftBits) & 0xff); 73 if (c == 0) break; if (!Character.isLetterOrDigit(c)) 75 return ""; 76 buf.append(c); 77 } 78 return buf.toString(); 79 } 80 81 87 public static String getModeName(int mode) 88 { 89 switch (mode) { 90 case NtpV3Packet.MODE_RESERVED: 91 return "Reserved"; 92 case NtpV3Packet.MODE_SYMMETRIC_ACTIVE: 93 return "Symmetric Active"; 94 case NtpV3Packet.MODE_SYMMETRIC_PASSIVE: 95 return "Symmetric Passive"; 96 case NtpV3Packet.MODE_CLIENT: 97 return "Client"; 98 case NtpV3Packet.MODE_SERVER: 99 return "Server"; 100 case NtpV3Packet.MODE_BROADCAST: 101 return "Broadcast"; 102 case NtpV3Packet.MODE_CONTROL_MESSAGE: 103 return "Control"; 104 case NtpV3Packet.MODE_PRIVATE: 105 return "Private"; 106 default: 107 return "Unknown"; 108 } 109 } 110 111 } 112 | Popular Tags |