sd-dhcp-lease.c revision 109731eb250705e055b98b844d7c0dfb74bcf728
/***
This file is part of systemd.
Copyright (C) 2013 Intel Corporation. All rights reserved.
Copyright (C) 2014 Tom Gundersen
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <net/ethernet.h>
#include "util.h"
#include "list.h"
#include "mkdir.h"
#include "fileio.h"
#include "dhcp-protocol.h"
#include "dhcp-internal.h"
#include "dhcp-lease-internal.h"
#include "sd-dhcp-lease.h"
#include "sd-dhcp-client.h"
return 0;
}
else
return -ENOENT;
return 0;
}
} else
return -ENOENT;
return 0;
}
} else
return -ENOENT;
return 0;
}
if (lease->domainname)
else
return -ENOENT;
return 0;
}
else
return -ENOENT;
return 0;
}
else
return -ENOENT;
return 0;
}
return 0;
}
return 0;
}
return 0;
}
return 0;
}
if (lease)
return lease;
}
}
return NULL;
}
void *user_data) {
switch(code) {
if (len == 4) {
}
break;
if (len >= 4)
break;
case DHCP_OPTION_SUBNET_MASK:
if (len >= 4)
break;
case DHCP_OPTION_ROUTER:
if (len >= 4)
break;
return -ENOMEM;
}
break;
case DHCP_OPTION_NTP_SERVER:
return -ENOMEM;
}
break;
if (len >= 2) {
}
break;
case DHCP_OPTION_DOMAIN_NAME:
if (len >= 1) {
}
break;
case DHCP_OPTION_HOST_NAME:
if (len >= 1) {
}
break;
case DHCP_OPTION_ROOT_PATH:
if (len >= 1) {
}
break;
if (len == 4) {
}
break;
if (len == 4) {
}
break;
}
return 0;
}
if (!lease)
return -ENOMEM;
return 0;
}
unsigned i;
fputs("DNS=", f);
for (i = 0; i < size; i++)
fputs("\n", f);
}
struct in_addr *new_addresses;
int r;
if (!new_addresses)
return -ENOMEM;
if (r < 0)
continue;
(*size)++;
}
return 0;
}
const char *string;
int r;
if (r < 0)
goto finish;
if (r < 0)
goto finish;
fprintf(f,
"# This is private data. Do not parse.\n"
if (r < 0)
goto finish;
if (r < 0)
goto finish;
if (r >= 0)
fprintf(f, "SERVER_ADDRESS=%s\n",
if (r >= 0)
if (r >= 0)
if (r >= 0)
if (r >= 0)
if (r >= 0)
if (r >= 0)
if (r >= 0)
r = 0;
fflush(f);
r = -errno;
}
if (r < 0)
return r;
}
int r;
r = dhcp_lease_new(&lease);
if (r < 0)
return r;
"ADDRESS", &address,
"ROUTER", &router,
"NETMASK", &netmask,
"SERVER_IDENTIFIER", &server_address,
"NEXT_SERVER", &next_server,
"DNS", &dns,
"NTP", &ntp,
"MTU", &mtu,
NULL);
if (r < 0) {
if (r == -ENOENT)
return 0;
return r;
}
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (server_address) {
if (r < 0)
return r;
}
if (next_server) {
if (r < 0)
return r;
}
if (dns) {
if (r < 0)
return r;
}
if (ntp) {
if (r < 0)
return r;
}
if (mtu) {
uint16_t u;
}
return 0;
}
/* fall back to the default subnet masks based on address class */
/* class A, leading bits: 0 */
/* class B, leading bits 10 */
/* class C, leading bits 110 */
else
/* class D or E, no default mask. give up */
return -ERANGE;
return 0;
}