blob: dce68f7cb09f4c4b4e1935806fa15c7f7495afea [file] [log] [blame]
Simon Kelleyc47e3ba2014-01-08 17:07:54 +00001/* dnsmasq is Copyright (c) 2000-2014 Simon Kelley
Simon Kelleyc5ad4e72012-02-24 16:06:20 +00002
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
15*/
16
17
18#include "dnsmasq.h"
19
20#ifdef HAVE_DHCP6
21
22static size_t outpacket_counter;
23
24void end_opt6(int container)
25{
26 void *p = daemon->outpacket.iov_base + container + 2;
27 u16 len = outpacket_counter - container - 4 ;
28
29 PUTSHORT(len, p);
30}
31
32int save_counter(int newval)
33{
34 int ret = outpacket_counter;
35 if (newval != -1)
36 outpacket_counter = newval;
37
38 return ret;
39}
40
41void *expand(size_t headroom)
42{
43 void *ret;
44
45 if (expand_buf(&daemon->outpacket, outpacket_counter + headroom))
46 {
47 ret = daemon->outpacket.iov_base + outpacket_counter;
48 outpacket_counter += headroom;
49 return ret;
50 }
51
52 return NULL;
53}
54
55int new_opt6(int opt)
56{
57 int ret = outpacket_counter;
58 void *p;
59
60 if ((p = expand(4)))
61 {
62 PUTSHORT(opt, p);
63 PUTSHORT(0, p);
64 }
65
66 return ret;
67}
68
69void *put_opt6(void *data, size_t len)
70{
71 void *p;
72
Simon Kelleyff7eea22013-09-04 18:01:38 +010073 if ((p = expand(len)) && data)
Simon Kelleyc5ad4e72012-02-24 16:06:20 +000074 memcpy(p, data, len);
Simon Kelleyff7eea22013-09-04 18:01:38 +010075
Simon Kelleyc5ad4e72012-02-24 16:06:20 +000076 return p;
77}
78
79void put_opt6_long(unsigned int val)
80{
81 void *p;
82
83 if ((p = expand(4)))
84 PUTLONG(val, p);
85}
86
87void put_opt6_short(unsigned int val)
88{
89 void *p;
90
91 if ((p = expand(2)))
92 PUTSHORT(val, p);
93}
94
95void put_opt6_char(unsigned int val)
96{
97 unsigned char *p;
98
99 if ((p = expand(1)))
100 *p = val;
101}
102
103void put_opt6_string(char *s)
104{
105 put_opt6(s, strlen(s));
106}
107
108#endif