1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25 package com.sun.dhcpmgr.data;
26
27 import java.util.*;
28 import java.io.Serializable;
29
30 /**
31 * This class defines the set of standard DHCP options we know about.
32 */
33 public class StandardOptions implements Serializable {
34
35 /*
36 * The following list of options are the ones that we use
37 * in order to configure DHCP for the user.
38 */
39 public static final String CD_SUBNETMASK = "Subnet";
40 public static final String CD_TIMEOFFSET = "UTCoffst";
41 public static final String CD_ROUTER = "Router";
42 public static final String CD_TIMESERV = "Timeserv";
43 public static final String CD_DNSSERV = "DNSserv";
44 public static final String CD_DNSDOMAIN = "DNSdmain";
45 public static final String CD_BROADCASTADDR = "Broadcst";
46 public static final String CD_ROUTER_DISCVRY_ON = "RDiscvyF";
47 public static final String CD_NIS_DOMAIN = "NISdmain";
48 public static final String CD_NIS_SERV = "NISservs";
49 public static final String CD_LEASE_TIME = "LeaseTim";
50 public static final String CD_BOOL_LEASENEG = "LeaseNeg";
51
52 /*
53 * Following list of options must be kept in sync with the list in
54 * usr/src/cmd/cmd-inet/usr.lib/in.dhcpd/dhcptab.c in SunOS source tree.
55 */
56 private static Option [] options = null;
57
58 /**
59 * Return the size of this list
60 * @return the number of options known
61 */
62 public static int size() {
63 return (options == null) ? 0 :options.length;
64 }
65
66 /**
67 * Enumerate the options defined here.
68 * @return an Enumeration of the standard options.
69 */
70 public Enumeration enumOptions() {
71 return new Enumeration() {
72 int cursor = 0;
73
74 public boolean hasMoreElements() {
75 return (cursor < size());
76 }
77
78 public Object nextElement() throws NoSuchElementException {
79 if (cursor >= size()) {
80 throw new NoSuchElementException();
81 }
82 return (options[cursor++]);
83 }
84 };
85 }
86
87 /**
88 * Return all options as an array
89 * @return the array of options defined here
90 */
91 public static Option [] getAllOptions() {
92 return options;
93 }
94
95 /**
96 * Set all options as an array
97 * @param options array of STANDARD options
98 */
99 public static void setAllOptions(Option [] ops) {
100 options = ops;
101 }
102
103 /**
104 * Find the option name for a given code. This could be
105 * much faster but not clear that it needs to be yet.
106 * @return the name of the option, or null if that code is unknown.
107 */
108 public static String nameForCode(int code) {
109 for (int i = 0; i < options.length; ++i) {
110 if (options[i].getCode() == code) {
111 return options[i].getKey();
112 }
113 }
114 return null;
115 }
116 }