lsquic_packet_in.c revision bfc7bfd8
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_common.h" 9#include "lsquic_packet_in.h" 10 11 12int 13packet_in_ver_first (const lsquic_packet_in_t *packet_in, struct ver_iter *vi, 14 lsquic_ver_tag_t *ver_tag) 15{ 16 vi->packet_in = packet_in; 17 vi->off = packet_in->pi_quic_ver; 18 return packet_in_ver_next(vi, ver_tag); 19} 20 21 22int 23packet_in_ver_next (struct ver_iter *vi, lsquic_ver_tag_t *ver_tag) 24{ 25 if (vi->off + 4 <= vi->packet_in->pi_header_sz) 26 { 27 memcpy(ver_tag, vi->packet_in->pi_data + vi->off, 4); 28 vi->off += 4; 29 return 1; 30 } 31 else 32 { 33 assert(vi->packet_in->pi_header_sz == vi->off); 34 return 0; 35 } 36} 37 38 39size_t 40lsquic_packet_in_mem_used (const struct lsquic_packet_in *packet_in) 41{ 42 size_t size; 43 44 size = sizeof(*packet_in); 45 46 if (packet_in->pi_flags & PI_OWN_DATA) 47 size += packet_in->pi_data_sz; 48 49 return size; 50} 51