Simon Kelley | c5ad4e7 | 2012-02-24 16:06:20 +0000 | [diff] [blame] | 1 | /* dnsmasq is Copyright (c) 2000-2012 Simon Kelley |
| 2 | |
| 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 | |
| 22 | static size_t outpacket_counter; |
| 23 | |
| 24 | void 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 | |
| 32 | int save_counter(int newval) |
| 33 | { |
| 34 | int ret = outpacket_counter; |
| 35 | if (newval != -1) |
| 36 | outpacket_counter = newval; |
| 37 | |
| 38 | return ret; |
| 39 | } |
| 40 | |
| 41 | void *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 | |
| 55 | int 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 | |
| 69 | void *put_opt6(void *data, size_t len) |
| 70 | { |
| 71 | void *p; |
| 72 | |
| 73 | if ((p = expand(len))) |
| 74 | memcpy(p, data, len); |
| 75 | |
| 76 | return p; |
| 77 | } |
| 78 | |
| 79 | void put_opt6_long(unsigned int val) |
| 80 | { |
| 81 | void *p; |
| 82 | |
| 83 | if ((p = expand(4))) |
| 84 | PUTLONG(val, p); |
| 85 | } |
| 86 | |
| 87 | void put_opt6_short(unsigned int val) |
| 88 | { |
| 89 | void *p; |
| 90 | |
| 91 | if ((p = expand(2))) |
| 92 | PUTSHORT(val, p); |
| 93 | } |
| 94 | |
| 95 | void put_opt6_char(unsigned int val) |
| 96 | { |
| 97 | unsigned char *p; |
| 98 | |
| 99 | if ((p = expand(1))) |
| 100 | *p = val; |
| 101 | } |
| 102 | |
| 103 | void put_opt6_string(char *s) |
| 104 | { |
| 105 | put_opt6(s, strlen(s)); |
| 106 | } |
| 107 | |
| 108 | #endif |