dhcp-option.c revision 89ca10c6a61309d84d54c5dc5a295387ce39e610
/*-*- 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"
if (code != DHCP_OPTION_END)
/* always make sure there is space for an END option */
size --;
switch (code) {
case DHCP_OPTION_PAD:
case DHCP_OPTION_END:
return -ENOBUFS;
*offset += 1;
break;
default:
return -ENOBUFS;
if (optlen) {
}
break;
}
return 0;
}
int r;
/* still space in the options array */
if (r >= 0)
return 0;
/* did not fit, but we have more buffers to try
close the options array and move the offset to its end */
if (r < 0)
return r;
} else
return r;
}
if (overload & DHCP_OVERLOAD_FILE) {
/* still space in the 'file' array */
if (r >= 0) {
return 0;
/* did not fit, but we have more buffers to try
close the file array and move the offset to its end */
if (r < 0)
return r;
} else
return r;
}
}
if (overload & DHCP_OVERLOAD_SNAME) {
/* still space in the 'sname' array */
if (r >= 0) {
return 0;
} else {
/* no space, or other error, give up */
return r;
}
}
}
return -ENOBUFS;
}
void *userdata) {
case DHCP_OPTION_PAD:
offset++;
break;
case DHCP_OPTION_END:
return 0;
case DHCP_OPTION_MESSAGE_TYPE:
return -ENOBUFS;
if (len != 1)
return -EINVAL;
if (message_type)
else
offset++;
offset++;
break;
case DHCP_OPTION_OVERLOAD:
return -ENOBUFS;
if (len != 1)
return -EINVAL;
if (overload)
else
offset++;
offset++;
break;
default:
return -ENOBUFS;
return -EINVAL;
if (cb)
break;
}
}
return -EINVAL;
return 0;
}
uint8_t message_type = 0;
int r;
if (!message)
return -EINVAL;
if (len < sizeof(DHCPMessage))
return -EINVAL;
len -= sizeof(DHCPMessage);
if (r < 0)
return r;
if (overload & DHCP_OVERLOAD_FILE) {
if (r < 0)
return r;
}
if (overload & DHCP_OVERLOAD_SNAME) {
if (r < 0)
return r;
}
if (message_type)
return message_type;
return -ENOMSG;
}