summaryrefslogtreecommitdiff
path: root/usr/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib')
-rw-r--r--usr/src/lib/libdhcpagent/common/dhcpagent_ipc.c32
-rw-r--r--usr/src/lib/libdhcpagent/common/dhcpagent_ipc.h2
-rw-r--r--usr/src/lib/libdhcpagent/common/dhcpagent_util.c32
3 files changed, 27 insertions, 39 deletions
diff --git a/usr/src/lib/libdhcpagent/common/dhcpagent_ipc.c b/usr/src/lib/libdhcpagent/common/dhcpagent_ipc.c
index 8a3ec18060..0d5cc7f8ff 100644
--- a/usr/src/lib/libdhcpagent/common/dhcpagent_ipc.c
+++ b/usr/src/lib/libdhcpagent/common/dhcpagent_ipc.c
@@ -76,6 +76,12 @@ static int dhcp_ipc_timed_read(int, void *, unsigned int, int *);
static int getinfo_ifnames(const char *, dhcp_optnum_t *, DHCP_OPT **);
static char *get_ifnames(int, int);
+/* must be kept in sync with enum in dhcpagent_ipc.h */
+static const char *ipc_typestr[] = {
+ "drop", "extend", "ping", "release", "start", "status",
+ "inform", "get_tag"
+};
+
/*
* dhcp_ipc_alloc_request(): allocates a dhcp_ipc_request_t of the given type
* and interface, with a timeout of 0.
@@ -636,6 +642,25 @@ dhcp_ipc_strerror(int error)
}
/*
+ * dhcp_string_to_request(): maps a string into a request code
+ *
+ * input: const char *: the string to map
+ * output: dhcp_ipc_type_t: the request code, or -1 if unknown
+ */
+
+dhcp_ipc_type_t
+dhcp_string_to_request(const char *request)
+{
+ unsigned int i;
+
+ for (i = 0; i < DHCP_NIPC; i++)
+ if (strcmp(ipc_typestr[i], request) == 0)
+ return ((dhcp_ipc_type_t)i);
+
+ return ((dhcp_ipc_type_t)-1);
+}
+
+/*
* dhcp_ipc_type_to_string(): maps an ipc command code into a human-readable
* string
*
@@ -646,15 +671,10 @@ dhcp_ipc_strerror(int error)
const char *
dhcp_ipc_type_to_string(dhcp_ipc_type_t type)
{
- static const char *typestr[] = {
- "drop", "extend", "ping", "release", "start", "status",
- "inform", "get_tag"
- };
-
if (type < 0 || type >= DHCP_NIPC)
return ("unknown");
else
- return (typestr[(int)type]);
+ return (ipc_typestr[(int)type]);
}
/*
diff --git a/usr/src/lib/libdhcpagent/common/dhcpagent_ipc.h b/usr/src/lib/libdhcpagent/common/dhcpagent_ipc.h
index 91236a85bb..58f06c9d3f 100644
--- a/usr/src/lib/libdhcpagent/common/dhcpagent_ipc.h
+++ b/usr/src/lib/libdhcpagent/common/dhcpagent_ipc.h
@@ -85,7 +85,7 @@ typedef enum {
* code in dhcpagent relies on the numeric values of these
* requests -- but there's no sane reason to change them anyway.
*
- * If any commands are changed, added, or removed, see the typestr[]
+ * If any commands are changed, added, or removed, see the ipc_typestr[]
* array in dhcpagent_ipc.c.
*/
diff --git a/usr/src/lib/libdhcpagent/common/dhcpagent_util.c b/usr/src/lib/libdhcpagent/common/dhcpagent_util.c
index 61101bb66c..e6d95cd0d1 100644
--- a/usr/src/lib/libdhcpagent/common/dhcpagent_util.c
+++ b/usr/src/lib/libdhcpagent/common/dhcpagent_util.c
@@ -79,38 +79,6 @@ dhcp_state_to_string(DHCPSTATE state)
}
/*
- * dhcp_string_to_request(): maps a string into a request code
- *
- * input: const char *: the string to map
- * output: dhcp_ipc_type_t: the request code, or -1 if unknown
- */
-
-dhcp_ipc_type_t
-dhcp_string_to_request(const char *request)
-{
- static struct {
- const char *string;
- dhcp_ipc_type_t type;
- } types[] = {
- { "drop", DHCP_DROP },
- { "extend", DHCP_EXTEND },
- { "inform", DHCP_INFORM },
- { "ping", DHCP_PING },
- { "release", DHCP_RELEASE },
- { "start", DHCP_START },
- { "status", DHCP_STATUS }
- };
-
- unsigned int i;
-
- for (i = 0; i < (sizeof (types) / sizeof (*types)); i++)
- if (strcmp(types[i].string, request) == 0)
- return (types[i].type);
-
- return (-1);
-}
-
-/*
* dhcp_start_agent(): starts the agent if not already running
*
* input: int: number of seconds to wait for agent to start (-1 is forever)