1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16#pragma once 17 18#include <netinet/icmp6.h> 19#include <netinet/ip6.h> 20 21#include <string> 22#include <vector> 23 24#include "message.h" 25 26class Packet { 27public: 28 enum class Type { 29 NeighborSolicitation, 30 NeighborAdvertisement, 31 RouterSolicitation, 32 RouterAdvertisement, 33 Other 34 }; 35 36 explicit Packet(Message& message); 37 38 // Create a string that can be used for debug purposes to describe 39 // what type of packet and potentially its target for certain types. 40 std::string description() const; 41 42 // Full size including IP header 43 size_t fullSize() const { 44 return mMessage.size(); 45 } 46 // Remaining size including ICMPv6 header but excluding IP header 47 size_t icmpSize() const { 48 return mMessage.size() - sizeof(ip6_hdr); 49 } 50 51 Type type() const { 52 return mType; 53 } 54 const ip6_hdr* ip() const { 55 return mIp; 56 } 57 const icmp6_hdr* icmp() const { 58 return mIcmp; 59 } 60 61 nd_opt_hdr* firstOpt(); 62 nd_opt_hdr* nextOpt(nd_opt_hdr* currentHeader); 63 64private: 65 Message& mMessage; 66 Type mType; 67 68 const ip6_hdr* mIp; 69 const icmp6_hdr* mIcmp; 70 nd_opt_hdr* mFirstOpt; 71}; 72 73