dhcp-option.c revision 20b958bf157dfb2f521b191ef7158035bcaa3003
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2013 Intel Corporation. All rights reserved.
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 <stdint.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include "dhcp-internal.h"
switch (code) {
case DHCP_OPTION_PAD:
case DHCP_OPTION_END:
return -ENOBUFS;
*offset += 1;
break;
default:
return -ENOBUFS;
break;
}
return 0;
}
void *user_data)
{
while (buflen > 0) {
switch (*code) {
case DHCP_OPTION_PAD:
buflen -= 1;
code++;
break;
case DHCP_OPTION_END:
return 0;
case DHCP_OPTION_MESSAGE_TYPE:
if (buflen < 3)
return -ENOBUFS;
buflen -= 3;
if (*len != 1)
return -EINVAL;
if (message_type)
code += 3;
break;
case DHCP_OPTION_OVERLOAD:
if (buflen < 3)
return -ENOBUFS;
buflen -= 3;
if (*len != 1)
return -EINVAL;
if (overload)
code += 3;
break;
default:
if (buflen < 3)
return -ENOBUFS;
return -EINVAL;
if (cb)
break;
}
}
if (buflen)
return -EINVAL;
return 0;
}
{
uint8_t message_type = 0;
int res;
if (!message)
return -EINVAL;
if (len < sizeof(DHCPMessage))
return -EINVAL;
len -= sizeof(DHCPMessage);
if (res < 0)
return res;
if (overload & DHCP_OVERLOAD_FILE) {
if (res < 0)
return res;
}
if (overload & DHCP_OVERLOAD_SNAME) {
if (res < 0)
return res;
}
if (message_type)
return message_type;
return -ENOMSG;
}