lsquic_packet_in.c revision 50aadb33
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