xref: /titanic_50/usr/src/cmd/cmd-inet/sbin/dhcpagent/util.h (revision cfb9c9abdc2696bc174bb10a3a28552dc917b98f)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	UTIL_H
27 #define	UTIL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <netinet/in.h>
33 #include <netinet/dhcp.h>
34 #include <netinet/dhcp6.h>
35 #include <libinetutil.h>
36 #include <dhcpagent_ipc.h>
37 
38 #include "common.h"
39 
40 /*
41  * general utility functions which have no better home.  see util.c
42  * for documentation on how to use the exported functions.
43  */
44 
45 #ifdef	__cplusplus
46 extern "C" {
47 #endif
48 
49 struct dhcp_timer_s {
50 	iu_timer_id_t	dt_id;
51 	lease_t		dt_start;		/* Initial timer value */
52 };
53 
54 /* conversion functions */
55 const char	*pkt_type_to_string(uchar_t, boolean_t);
56 const char	*monosec_to_string(monosec_t);
57 time_t		monosec_to_time(monosec_t);
58 monosec_t	hrtime_to_monosec(hrtime_t);
59 
60 /* shutdown handlers */
61 void		graceful_shutdown(int);
62 void		inactivity_shutdown(iu_tq_t *, void *);
63 
64 /* timer functions */
65 void		init_timer(dhcp_timer_t *, lease_t);
66 boolean_t	cancel_timer(dhcp_timer_t *);
67 boolean_t	schedule_timer(dhcp_timer_t *, iu_tq_callback_t *, void *);
68 
69 /* miscellaneous */
70 boolean_t	add_default_route(uint32_t, struct in_addr *);
71 boolean_t	del_default_route(uint32_t, struct in_addr *);
72 int		daemonize(void);
73 monosec_t	monosec(void);
74 void		print_server_msg(dhcp_smach_t *, const char *, uint_t);
75 boolean_t	bind_sock(int, in_port_t, in_addr_t);
76 boolean_t	bind_sock_v6(int, in_port_t, const in6_addr_t *);
77 const char	*iffile_to_hostname(const char *);
78 int		dhcpv6_status_code(const dhcpv6_option_t *, uint_t,
79     const char **, const char **, uint_t *);
80 
81 #ifdef	__cplusplus
82 }
83 #endif
84 
85 #endif	/* UTIL_H */
86