1cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti/* 2cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * Copyright (C) 2013 The Android Open Source Project 3cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * 4cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * Licensed under the Apache License, Version 2.0 (the "License"); 5cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * you may not use this file except in compliance with the License. 6cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * You may obtain a copy of the License at 7cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * 8cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * http://www.apache.org/licenses/LICENSE-2.0 9cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * 10cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * Unless required by applicable law or agreed to in writing, software 11cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * distributed under the License is distributed on an "AS IS" BASIS, 12cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * See the License for the specific language governing permissions and 14cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * limitations under the License. 15cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * 16cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti * icmp.c - convenience functions for translating ICMP and ICMPv6 packets. 17cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti */ 18cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 19cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti#ifndef __ICMP_H__ 20cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti#define __ICMP_H__ 21cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 22cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti#include <stdint.h> 23cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 24cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti// Guesses the number of hops a received packet has traversed based on its TTL. 25cd70b354eb985678175904a937085bed6094af77Lorenzo Colittiuint8_t icmp_guess_ttl(uint8_t ttl); 26cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 27cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti// Determines whether an ICMP type is an error message. 28cd70b354eb985678175904a937085bed6094af77Lorenzo Colittiint is_icmp_error(uint8_t type); 29cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 30cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti// Determines whether an ICMPv6 type is an error message. 31cd70b354eb985678175904a937085bed6094af77Lorenzo Colittiint is_icmp6_error(uint8_t type); 32cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 33cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti// Maps ICMP types to ICMPv6 types. Partial implementation of RFC 6145, section 4.2. 34cd70b354eb985678175904a937085bed6094af77Lorenzo Colittiuint8_t icmp_to_icmp6_type(uint8_t type, uint8_t code); 35cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 36cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti// Maps ICMP codes to ICMPv6 codes. Partial implementation of RFC 6145, section 4.2. 37cd70b354eb985678175904a937085bed6094af77Lorenzo Colittiuint8_t icmp_to_icmp6_code(uint8_t type, uint8_t code); 38cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 39cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti// Maps ICMPv6 types to ICMP types. Partial implementation of RFC 6145, section 5.2. 40cd70b354eb985678175904a937085bed6094af77Lorenzo Colittiuint8_t icmp6_to_icmp_type(uint8_t type, uint8_t code); 41cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 42cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti// Maps ICMPv6 codes to ICMP codes. Partial implementation of RFC 6145, section 5.2. 43cd70b354eb985678175904a937085bed6094af77Lorenzo Colittiuint8_t icmp6_to_icmp_code(uint8_t type, uint8_t code); 44cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti 45cd70b354eb985678175904a937085bed6094af77Lorenzo Colitti#endif /* __ICMP_H__ */ 46