Source Code Cross Referenced for NtpUtils.java in  » Net » Apache-commons-net-1.4.1 » org » apache » commons » net » ntp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache commons net 1.4.1 » org.apache.commons.net.ntp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.commons.net.ntp;
002:
003:        /*
004:         * Copyright 2001-2005 The Apache Software Foundation
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         *
010:         *     http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        /***
020:         * Common NtpUtils Helper class.
021:         *
022:         * @author Jason Mathews, MITRE Corp
023:         *
024:         * @version $Revision: 165675 $ $Date: 2005-05-02 15:09:55 -0500 (Mon, 02 May 2005) $
025:         */
026:        public final class NtpUtils {
027:
028:            /***
029:             * Returns 32-bit integer address to IPv4 address string "%d.%d.%d.%d" format.
030:             *
031:             * @param address  the 32-bit address
032:             * @return  the raw IP address in a string format.
033:             */
034:            public static String getHostAddress(int address) {
035:                return ((address >>> 24) & 0xFF) + "."
036:                        + ((address >>> 16) & 0xFF) + "."
037:                        + ((address >>> 8) & 0xFF) + "."
038:                        + ((address >>> 0) & 0xFF);
039:            }
040:
041:            /***
042:             * Returns NTP packet reference identifier as IP address.
043:             *
044:             * @param packet  NTP packet
045:             * @return  the packet reference id (as IP address) in "%d.%d.%d.%d" format.
046:             */
047:            public static String getRefAddress(NtpV3Packet packet) {
048:                int address = (packet == null) ? 0 : packet.getReferenceId();
049:                return getHostAddress(address);
050:            }
051:
052:            /***
053:             * Get refId as reference clock string (e.g. GPS, WWV, LCL). If string is
054:             * invalid (non-ASCII character) then returns empty string "".
055:             * For details refer to the <A HREF="http://www.eecis.udel.edu/~mills/ntp/html/refclock.html#list">Comprehensive
056:             * List of Clock Drivers</A>.
057:             *
058:             * @param message
059:             * @return reference clock string if primary NTP server
060:             */
061:            public static String getReferenceClock(NtpV3Packet message) {
062:                if (message == null)
063:                    return "";
064:                int refId = message.getReferenceId();
065:                if (refId == 0)
066:                    return "";
067:                StringBuffer buf = new StringBuffer(4);
068:                // start at highest-order byte (0x4c434c00 -> LCL)
069:                for (int shiftBits = 24; shiftBits >= 0; shiftBits -= 8) {
070:                    char c = (char) ((refId >>> shiftBits) & 0xff);
071:                    if (c == 0)
072:                        break; // 0-terminated ASCII string
073:                    if (!Character.isLetterOrDigit(c))
074:                        return "";
075:                    buf.append(c);
076:                }
077:                return buf.toString();
078:            }
079:
080:            /***
081:             * Return human-readable name of message mode type (RFC 1305).
082:             *
083:             * @param mode
084:             * @return mode name
085:             */
086:            public static String getModeName(int mode) {
087:                switch (mode) {
088:                case NtpV3Packet.MODE_RESERVED:
089:                    return "Reserved";
090:                case NtpV3Packet.MODE_SYMMETRIC_ACTIVE:
091:                    return "Symmetric Active";
092:                case NtpV3Packet.MODE_SYMMETRIC_PASSIVE:
093:                    return "Symmetric Passive";
094:                case NtpV3Packet.MODE_CLIENT:
095:                    return "Client";
096:                case NtpV3Packet.MODE_SERVER:
097:                    return "Server";
098:                case NtpV3Packet.MODE_BROADCAST:
099:                    return "Broadcast";
100:                case NtpV3Packet.MODE_CONTROL_MESSAGE:
101:                    return "Control";
102:                case NtpV3Packet.MODE_PRIVATE:
103:                    return "Private";
104:                default:
105:                    return "Unknown";
106:                }
107:            }
108:
109:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.