lsquic_packet_in.c revision c51ce338
150aadb33SDmitri Tikhonov/* Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov#include <assert.h>
350aadb33SDmitri Tikhonov#include <stdint.h>
450aadb33SDmitri Tikhonov#include <string.h>
550aadb33SDmitri Tikhonov
650aadb33SDmitri Tikhonov#include "lsquic_int_types.h"
750aadb33SDmitri Tikhonov#include "lsquic_types.h"
850aadb33SDmitri Tikhonov#include "lsquic_packet_in.h"
950aadb33SDmitri Tikhonov
1050aadb33SDmitri Tikhonov
1150aadb33SDmitri Tikhonovint
1250aadb33SDmitri Tikhonovpacket_in_ver_first (const lsquic_packet_in_t *packet_in, struct ver_iter *vi,
1350aadb33SDmitri Tikhonov                     lsquic_ver_tag_t *ver_tag)
1450aadb33SDmitri Tikhonov{
1550aadb33SDmitri Tikhonov    vi->packet_in = packet_in;
1650aadb33SDmitri Tikhonov    vi->off       = packet_in->pi_quic_ver;
1750aadb33SDmitri Tikhonov    return packet_in_ver_next(vi, ver_tag);
1850aadb33SDmitri Tikhonov}
1950aadb33SDmitri Tikhonov
2050aadb33SDmitri Tikhonov
2150aadb33SDmitri Tikhonovint
2250aadb33SDmitri Tikhonovpacket_in_ver_next (struct ver_iter *vi, lsquic_ver_tag_t *ver_tag)
2350aadb33SDmitri Tikhonov{
2450aadb33SDmitri Tikhonov    if (vi->off + 4 <= vi->packet_in->pi_header_sz)
2550aadb33SDmitri Tikhonov    {
2650aadb33SDmitri Tikhonov        memcpy(ver_tag, vi->packet_in->pi_data + vi->off, 4);
2750aadb33SDmitri Tikhonov        vi->off += 4;
2850aadb33SDmitri Tikhonov        return 1;
2950aadb33SDmitri Tikhonov    }
3050aadb33SDmitri Tikhonov    else
3150aadb33SDmitri Tikhonov    {
3250aadb33SDmitri Tikhonov        assert(vi->packet_in->pi_header_sz == vi->off);
3350aadb33SDmitri Tikhonov        return 0;
3450aadb33SDmitri Tikhonov    }
3550aadb33SDmitri Tikhonov}
36c51ce338SDmitri Tikhonov
37c51ce338SDmitri Tikhonov
38c51ce338SDmitri Tikhonovsize_t
39c51ce338SDmitri Tikhonovlsquic_packet_in_mem_used (const struct lsquic_packet_in *packet_in)
40c51ce338SDmitri Tikhonov{
41c51ce338SDmitri Tikhonov    size_t size;
42c51ce338SDmitri Tikhonov
43c51ce338SDmitri Tikhonov    size = sizeof(*packet_in);
44c51ce338SDmitri Tikhonov
45c51ce338SDmitri Tikhonov    if (packet_in->pi_flags & PI_OWN_DATA)
46c51ce338SDmitri Tikhonov        size += packet_in->pi_data_sz;
47c51ce338SDmitri Tikhonov
48c51ce338SDmitri Tikhonov    return size;
49c51ce338SDmitri Tikhonov}
50