1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef NET_DCSCTP_PACKET_ERROR_CAUSE_UNRESOLVABLE_ADDRESS_CAUSE_H_ 11 #define NET_DCSCTP_PACKET_ERROR_CAUSE_UNRESOLVABLE_ADDRESS_CAUSE_H_ 12 #include <stddef.h> 13 #include <stdint.h> 14 15 #include <cstdint> 16 #include <string> 17 #include <vector> 18 19 #include "absl/strings/string_view.h" 20 #include "api/array_view.h" 21 #include "net/dcsctp/packet/error_cause/error_cause.h" 22 #include "net/dcsctp/packet/tlv_trait.h" 23 24 namespace dcsctp { 25 26 // https://tools.ietf.org/html/rfc4960#section-3.3.10.5 27 struct UnresolvableAddressCauseConfig : public ParameterConfig { 28 static constexpr int kType = 5; 29 static constexpr size_t kHeaderSize = 4; 30 static constexpr size_t kVariableLengthAlignment = 1; 31 }; 32 33 class UnresolvableAddressCause 34 : public Parameter, 35 public TLVTrait<UnresolvableAddressCauseConfig> { 36 public: 37 static constexpr int kType = UnresolvableAddressCauseConfig::kType; 38 UnresolvableAddressCause(rtc::ArrayView<const uint8_t> unresolvable_address)39 explicit UnresolvableAddressCause( 40 rtc::ArrayView<const uint8_t> unresolvable_address) 41 : unresolvable_address_(unresolvable_address.begin(), 42 unresolvable_address.end()) {} 43 44 static absl::optional<UnresolvableAddressCause> Parse( 45 rtc::ArrayView<const uint8_t> data); 46 47 void SerializeTo(std::vector<uint8_t>& out) const override; 48 std::string ToString() const override; 49 unresolvable_address()50 rtc::ArrayView<const uint8_t> unresolvable_address() const { 51 return unresolvable_address_; 52 } 53 54 private: 55 std::vector<uint8_t> unresolvable_address_; 56 }; 57 58 } // namespace dcsctp 59 60 #endif // NET_DCSCTP_PACKET_ERROR_CAUSE_UNRESOLVABLE_ADDRESS_CAUSE_H_ 61