mirror of
http://thekelleys.org.uk/git/dnsmasq.git
synced 2026-10-25 12:14:38 +00:00
I am attaching an incremental git-am ready patch to go on top your Git HEAD, to fix all sorts of issues and make this conforming C99 with default options set, and fix another load of warnings you receive when setting the compiler to pick the nits, -pedantic-errors -std=c99 (or c11, c18, c2x). It changes many void * to uint8_t * to make the "increment by bytes" explicit. You can't do: void *foo; // ... foo += 2.
119 lines
2.2 KiB
C
119 lines
2.2 KiB
C
/* dnsmasq is Copyright (c) 2000-2024 Simon Kelley
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 dated June, 1991, or
|
|
(at your option) version 3 dated 29 June, 2007.
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
|
|
#include "dnsmasq.h"
|
|
|
|
#ifdef HAVE_DHCP6
|
|
|
|
static size_t outpacket_counter;
|
|
|
|
void end_opt6(int container)
|
|
{
|
|
uint8_t *p = (uint8_t *)daemon->outpacket.iov_base + container + 2;
|
|
u16 len = outpacket_counter - container - 4 ;
|
|
|
|
PUTSHORT(len, p);
|
|
}
|
|
|
|
void reset_counter(void)
|
|
{
|
|
/* Clear out buffer when starting from beginning */
|
|
if (daemon->outpacket.iov_base)
|
|
memset(daemon->outpacket.iov_base, 0, daemon->outpacket.iov_len);
|
|
|
|
save_counter(0);
|
|
}
|
|
|
|
int save_counter(int newval)
|
|
{
|
|
int ret = outpacket_counter;
|
|
|
|
if (newval != -1)
|
|
outpacket_counter = newval;
|
|
|
|
return ret;
|
|
}
|
|
|
|
void *expand(size_t headroom)
|
|
{
|
|
uint8_t *ret;
|
|
|
|
if (expand_buf(&daemon->outpacket, outpacket_counter + headroom))
|
|
{
|
|
ret = (uint8_t *)daemon->outpacket.iov_base + outpacket_counter;
|
|
outpacket_counter += headroom;
|
|
return ret;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
int new_opt6(int opt)
|
|
{
|
|
int ret = outpacket_counter;
|
|
unsigned char *p;
|
|
|
|
if ((p = expand(4)))
|
|
{
|
|
PUTSHORT(opt, p);
|
|
PUTSHORT(0, p);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
void *put_opt6(void *data, size_t len)
|
|
{
|
|
void *p;
|
|
|
|
if ((p = expand(len)) && data)
|
|
memcpy(p, data, len);
|
|
|
|
return p;
|
|
}
|
|
|
|
void put_opt6_long(unsigned int val)
|
|
{
|
|
unsigned char *p;
|
|
|
|
if ((p = expand(4)))
|
|
PUTLONG(val, p);
|
|
}
|
|
|
|
void put_opt6_short(unsigned int val)
|
|
{
|
|
uint8_t *p;
|
|
|
|
if ((p = expand(2)))
|
|
PUTSHORT(val, p);
|
|
}
|
|
|
|
void put_opt6_char(unsigned int val)
|
|
{
|
|
unsigned char *p;
|
|
|
|
if ((p = expand(1)))
|
|
*p = val;
|
|
}
|
|
|
|
void put_opt6_string(char *s)
|
|
{
|
|
put_opt6(s, strlen(s));
|
|
}
|
|
|
|
#endif
|