2 This file is part of systemd.
4 Copyright (C) 2013 Intel Corporation. All rights reserved.
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
28 #include "dhcp-protocol.h"
29 #include "sd-dhcp-client.h"
31 struct sd_dhcp_client {
39 static const uint8_t default_req_opts[] = {
40 DHCP_OPTION_SUBNET_MASK,
42 DHCP_OPTION_HOST_NAME,
43 DHCP_OPTION_DOMAIN_NAME,
44 DHCP_OPTION_DOMAIN_NAME_SERVER,
45 DHCP_OPTION_NTP_SERVER,
48 int sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option)
52 assert_return(client, -EINVAL);
53 assert_return (client->state == DHCP_STATE_INIT, -EBUSY);
57 case DHCP_OPTION_OVERLOAD:
58 case DHCP_OPTION_MESSAGE_TYPE:
59 case DHCP_OPTION_PARAMETER_REQUEST_LIST:
67 for (i = 0; i < client->req_opts_size; i++)
68 if (client->req_opts[i] == option)
71 if (!GREEDY_REALLOC(client->req_opts, client->req_opts_size,
72 client->req_opts_size + 1))
75 client->req_opts[client->req_opts_size - 1] = option;
80 int sd_dhcp_client_set_request_address(sd_dhcp_client *client,
81 const struct in_addr *last_addr)
83 assert_return(client, -EINVAL);
84 assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
87 client->last_addr = last_addr->s_addr;
89 client->last_addr = INADDR_ANY;
94 int sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index)
96 assert_return(client, -EINVAL);
97 assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
98 assert_return(interface_index >= -1, -EINVAL);
100 client->index = interface_index;
105 sd_dhcp_client *sd_dhcp_client_new(void)
107 sd_dhcp_client *client;
109 client = new0(sd_dhcp_client, 1);
113 client->state = DHCP_STATE_INIT;
116 client->req_opts_size = ELEMENTSOF(default_req_opts);
118 client->req_opts = memdup(default_req_opts, client->req_opts_size);
119 if (!client->req_opts) {