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/>.
21 #include "system/network.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
,
38 size_t offset
= 0, np
;
40 ctdb_uint32_push(&in
->length
, buf
+offset
, &np
);
43 ctdb_uint32_push(&in
->reqid
, buf
+offset
, &np
);
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
;
55 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->length
, &np
);
61 ret
= ctdb_uint32_pull(buf
+offset
, buflen
-offset
, &out
->reqid
, &np
);
71 void sock_packet_header_set_reqid(struct sock_packet_header
*h
,
77 void sock_packet_header_set_length(struct sock_packet_header
*h
,