summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/quiche/src/quic/qbone/qbone_packet_processor_test_tools.cc
blob: 5df158d87f9c94c440179873fdc27e5398d30381 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "quic/qbone/qbone_packet_processor_test_tools.h"

#include <netinet/ip6.h>

namespace quic {

std::string PrependIPv6HeaderForTest(const std::string& body, int hops) {
  ip6_hdr header;
  memset(&header, 0, sizeof(header));

  header.ip6_vfc = 6 << 4;
  header.ip6_plen = htons(body.size());
  header.ip6_nxt = IPPROTO_UDP;
  header.ip6_hops = hops;
  header.ip6_src = in6addr_loopback;
  header.ip6_dst = in6addr_loopback;

  std::string packet(sizeof(header) + body.size(), '\0');
  memcpy(&packet[0], &header, sizeof(header));
  memcpy(&packet[sizeof(header)], body.data(), body.size());
  return packet;
}

}  // namespace quic