lsquic_packet_in.c revision bfc7bfd8
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" 8bfc7bfd8SDmitri Tikhonov#include "lsquic_packet_common.h" 950aadb33SDmitri Tikhonov#include "lsquic_packet_in.h" 1050aadb33SDmitri Tikhonov 1150aadb33SDmitri Tikhonov 1250aadb33SDmitri Tikhonovint 1350aadb33SDmitri Tikhonovpacket_in_ver_first (const lsquic_packet_in_t *packet_in, struct ver_iter *vi, 1450aadb33SDmitri Tikhonov lsquic_ver_tag_t *ver_tag) 1550aadb33SDmitri Tikhonov{ 1650aadb33SDmitri Tikhonov vi->packet_in = packet_in; 1750aadb33SDmitri Tikhonov vi->off = packet_in->pi_quic_ver; 1850aadb33SDmitri Tikhonov return packet_in_ver_next(vi, ver_tag); 1950aadb33SDmitri Tikhonov} 2050aadb33SDmitri Tikhonov 2150aadb33SDmitri Tikhonov 2250aadb33SDmitri Tikhonovint 2350aadb33SDmitri Tikhonovpacket_in_ver_next (struct ver_iter *vi, lsquic_ver_tag_t *ver_tag) 2450aadb33SDmitri Tikhonov{ 2550aadb33SDmitri Tikhonov if (vi->off + 4 <= vi->packet_in->pi_header_sz) 2650aadb33SDmitri Tikhonov { 2750aadb33SDmitri Tikhonov memcpy(ver_tag, vi->packet_in->pi_data + vi->off, 4); 2850aadb33SDmitri Tikhonov vi->off += 4; 2950aadb33SDmitri Tikhonov return 1; 3050aadb33SDmitri Tikhonov } 3150aadb33SDmitri Tikhonov else 3250aadb33SDmitri Tikhonov { 3350aadb33SDmitri Tikhonov assert(vi->packet_in->pi_header_sz == vi->off); 3450aadb33SDmitri Tikhonov return 0; 3550aadb33SDmitri Tikhonov } 3650aadb33SDmitri Tikhonov} 37c51ce338SDmitri Tikhonov 38c51ce338SDmitri Tikhonov 39c51ce338SDmitri Tikhonovsize_t 40c51ce338SDmitri Tikhonovlsquic_packet_in_mem_used (const struct lsquic_packet_in *packet_in) 41c51ce338SDmitri Tikhonov{ 42c51ce338SDmitri Tikhonov size_t size; 43c51ce338SDmitri Tikhonov 44c51ce338SDmitri Tikhonov size = sizeof(*packet_in); 45c51ce338SDmitri Tikhonov 46c51ce338SDmitri Tikhonov if (packet_in->pi_flags & PI_OWN_DATA) 47c51ce338SDmitri Tikhonov size += packet_in->pi_data_sz; 48c51ce338SDmitri Tikhonov 49c51ce338SDmitri Tikhonov return size; 50c51ce338SDmitri Tikhonov} 51