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