provision: Add support for BIND 9.16.x
[samba.git] / ctdb / protocol / protocol_sock.c
blobe32f08767e75d406c4e044db378824590362b693
1 /*
2 CTDB generic sock packet marshalling
4 Copyright (C) Amitay Isaacs 2017
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "replace.h"
21 #include "system/network.h"
23 #include <talloc.h>
25 #include "protocol.h"
26 #include "protocol_private.h"
27 #include "protocol_api.h"
29 size_t sock_packet_header_len(struct sock_packet_header *in)
31 return ctdb_uint32_len(&in->length) +
32 ctdb_uint32_len(&in->reqid);
35 void sock_packet_header_push(struct sock_packet_header *in, uint8_t *buf,
36 size_t *npush)
38 size_t offset = 0, np;
40 ctdb_uint32_push(&in->length, buf+offset, &np);
41 offset += np;
43 ctdb_uint32_push(&in->reqid, buf+offset, &np);
44 offset += np;
46 *npush = offset;
49 int sock_packet_header_pull(uint8_t *buf, size_t buflen,
50 struct sock_packet_header *out, size_t *npull)
52 size_t offset = 0, np;
53 int ret;
55 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->length, &np);
56 if (ret != 0) {
57 return ret;
59 offset += np;
61 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reqid, &np);
62 if (ret != 0) {
63 return ret;
65 offset += np;
67 *npull = offset;
68 return 0;
71 void sock_packet_header_set_reqid(struct sock_packet_header *h,
72 uint32_t reqid)
74 h->reqid = reqid;
77 void sock_packet_header_set_length(struct sock_packet_header *h,
78 uint32_t length)
80 h->length = length;