lsquic_packet_in.c revision 229fce07
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE. */
2#include <assert.h>
3#include <stdint.h>
4#include <string.h>
5#include <sys/queue.h>
6#ifdef WIN32
7#include <vc_compat.h>
8#endif
9
10#include "lsquic_int_types.h"
11#include "lsquic_types.h"
12#include "lsquic_packet_common.h"
13#include "lsquic_packet_in.h"
14
15
16int
17packet_in_ver_first (const lsquic_packet_in_t *packet_in, struct ver_iter *vi,
18                     lsquic_ver_tag_t *ver_tag)
19{
20    vi->packet_in = packet_in;
21    vi->off       = packet_in->pi_quic_ver;
22    return packet_in_ver_next(vi, ver_tag);
23}
24
25
26int
27packet_in_ver_next (struct ver_iter *vi, lsquic_ver_tag_t *ver_tag)
28{
29    if (vi->off + 4 <= vi->packet_in->pi_header_sz)
30    {
31        memcpy(ver_tag, vi->packet_in->pi_data + vi->off, 4);
32        vi->off += 4;
33        return 1;
34    }
35    else
36    {
37        assert(vi->packet_in->pi_header_sz == vi->off);
38        return 0;
39    }
40}
41
42
43size_t
44lsquic_packet_in_mem_used (const struct lsquic_packet_in *packet_in)
45{
46    size_t size;
47
48    size = sizeof(*packet_in);
49
50    if (packet_in->pi_flags & PI_OWN_DATA)
51        size += packet_in->pi_data_sz;
52
53    return size;
54}
55