Handle potential NULL pointer with DHCP options
[framework/connectivity/connman.git] / gdhcp / gdhcp.h
1 /*
2  *
3  *  DHCP client library with GLib integration
4  *
5  *  Copyright (C) 2009-2010  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #ifndef __G_DHCP_H
23 #define __G_DHCP_H
24
25 #include <glib.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 struct _GDHCPClient;
32
33 typedef struct _GDHCPClient GDHCPClient;
34
35 typedef enum {
36         G_DHCP_CLIENT_ERROR_NONE,
37         G_DHCP_CLIENT_ERROR_INTERFACE_UNAVAILABLE,
38         G_DHCP_CLIENT_ERROR_INTERFACE_IN_USE,
39         G_DHCP_CLIENT_ERROR_INTERFACE_DOWN,
40         G_DHCP_CLIENT_ERROR_NOMEM,
41         G_DHCP_CLIENT_ERROR_INVALID_INDEX,
42         G_DHCP_CLIENT_ERROR_INVALID_OPTION
43 } GDHCPClientError;
44
45 typedef enum {
46         G_DHCP_CLIENT_EVENT_LEASE_AVAILABLE,
47         G_DHCP_CLIENT_EVENT_NO_LEASE,
48         G_DHCP_CLIENT_EVENT_LEASE_LOST,
49         G_DHCP_CLIENT_EVENT_ADDRESS_CONFLICT,
50 } GDHCPClientEvent;
51
52 typedef enum {
53         G_DHCP_IPV4,
54         G_DHCP_IPV6,
55 } GDHCPType;
56
57 #define G_DHCP_SUBNET           0x01
58 #define G_DHCP_ROUTER           0x03
59 #define G_DHCP_TIME_SERVER      0x04
60 #define G_DHCP_DNS_SERVER       0x06
61 #define G_DHCP_DOMAIN_NAME      0x0f
62 #define G_DHCP_HOST_NAME        0x0c
63 #define G_DHCP_NTP_SERVER       0x2a
64
65 typedef void (*GDHCPClientEventFunc) (GDHCPClient *client, gpointer user_data);
66
67 typedef void (*GDHCPDebugFunc)(const char *str, gpointer user_data);
68
69 GDHCPClient *g_dhcp_client_new(GDHCPType type, int index,
70                                                 GDHCPClientError *error);
71
72 int g_dhcp_client_start(GDHCPClient *client);
73 void g_dhcp_client_stop(GDHCPClient *client);
74
75 GDHCPClient *g_dhcp_client_ref(GDHCPClient *client);
76 void g_dhcp_client_unref(GDHCPClient *client);
77
78 void g_dhcp_client_register_event(GDHCPClient *client,
79                                         GDHCPClientEvent event,
80                                         GDHCPClientEventFunc func,
81                                         gpointer user_data);
82
83 GDHCPClientError g_dhcp_client_set_request(GDHCPClient *client,
84                                                 unsigned char option_code);
85 GDHCPClientError g_dhcp_client_set_send(GDHCPClient *client,
86                                                 unsigned char option_code,
87                                                 const char *option_value);
88
89 char *g_dhcp_client_get_address(GDHCPClient *client);
90 GList *g_dhcp_client_get_option(GDHCPClient *client,
91                                                 unsigned char option_code);
92 int g_dhcp_client_get_index(GDHCPClient *client);
93
94 void g_dhcp_client_set_debug(GDHCPClient *client,
95                                 GDHCPDebugFunc func, gpointer user_data);
96
97 #ifdef __cplusplus
98 }
99 #endif
100
101 #endif /* __G_DHCP_H */