/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <fcntl.h>
#include <libcontract.h>
#include <libcontract_priv.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dhcpagent_ipc.h"
#include "dhcpagent_util.h"
/*
* Strings returned by dhcp_status_hdr_string() and
* dhcp_status_reply_to_string(). The first define is the header line, and
* the second defines line printed underneath.
* The spacing of fields must match.
*/
/*
* dhcp_state_to_string(): given a state, provides the state's name
*
* input: DHCPSTATE: the state to get the name of
* output: const char *: the state's name
*/
const char *
{
const char *states[] = {
"INIT",
"SELECTING",
"REQUESTING",
"PRE_BOUND",
"BOUND",
"RENEWING",
"REBINDING",
"INFORMATION",
"INIT_REBOOT",
"ADOPTING",
"INFORM_SENT",
"DECLINING",
"RELEASING"
};
return ("<unknown>");
}
static int
init_template(void)
{
int fd;
int err = 0;
if (fd == -1)
return (-1);
/*
* Deliver no events, don't inherit, and allow it to be orphaned.
*/
return (-1);
}
return (fd);
}
/*
* dhcp_start_agent(): starts the agent if not already running
*
* input: int: number of seconds to wait for agent to start (-1 is forever)
* output: int: 0 on success, -1 on failure
*/
int
{
int error;
int ctfd;
/*
* just send a dummy request to the agent to find out if it's
* up. we do this instead of directly connecting to it since
* we want to make sure we follow its IPC conventions
* (otherwise, it will log warnings to syslog).
*/
return (-1);
if (error == 0) {
return (0);
}
if (error != DHCP_IPC_E_CONNECT)
goto fail;
goto fail;
(void) ct_tmpl_clear(ctfd);
switch (childpid) {
case -1:
goto fail;
case 0:
default:
break;
}
/* wait for the daemon to run and then abandon the contract */
(void) contract_abandon_id(ct);
if (error == 0) {
return (0);
} else if (error != DHCP_IPC_E_CONNECT)
break;
(void) sleep(1);
}
fail:
return (-1);
}
/*
* dhcp_status_hdr_string(): Return a string suitable to use as the header
* when printing DHCP_STATUS reply.
* output: const char *: newline terminated printable string
*/
const char *
dhcp_status_hdr_string(void)
{
return (DHCP_STATUS_HDR);
}
/*
* time_to_string(): Utility routine for printing time
*
* input: time_t *: time_t to stringify
* output: const char *: printable time
*/
static const char *
{
return ("Never");
return ("<unknown>");
return (time_buf);
}
/*
* dhcp_status_reply_to_string(): Return DHCP IPC reply of type DHCP_STATUS
* as a printable string
*
* input: dhcp_reply_t *: contains the status structure to print
* output: const char *: newline terminated printable string
*/
const char *
{
if (reply_size < DHCP_STATUS_VER1_SIZE)
return ("<Internal error: status msg size>\n");
case BOUND:
case RENEWING:
case REBINDING:
break;
default:
return (str);
}
return (str);
}