wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 1 | // Copyright (c) 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/qbone/qbone_packet_processor_test_tools.h" |
| 6 | |
| 7 | #include <netinet/ip6.h> |
| 8 | |
| 9 | namespace quic { |
| 10 | |
QUICHE team | b80d7c3 | 2020-02-23 23:44:20 -0800 | [diff] [blame] | 11 | std::string PrependIPv6HeaderForTest(const std::string& body, int hops) { |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 12 | ip6_hdr header; |
| 13 | memset(&header, 0, sizeof(header)); |
| 14 | |
| 15 | header.ip6_vfc = 6 << 4; |
| 16 | header.ip6_plen = htons(body.size()); |
| 17 | header.ip6_nxt = IPPROTO_UDP; |
| 18 | header.ip6_hops = hops; |
| 19 | header.ip6_src = in6addr_loopback; |
| 20 | header.ip6_dst = in6addr_loopback; |
| 21 | |
QUICHE team | b80d7c3 | 2020-02-23 23:44:20 -0800 | [diff] [blame] | 22 | std::string packet(sizeof(header) + body.size(), '\0'); |
wub | f975eac | 2019-08-19 19:41:01 -0700 | [diff] [blame] | 23 | memcpy(&packet[0], &header, sizeof(header)); |
| 24 | memcpy(&packet[sizeof(header)], body.data(), body.size()); |
| 25 | return packet; |
| 26 | } |
| 27 | |
| 28 | } // namespace quic |