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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
  
     | 
    
      
/***************************************************************************
 * ICMPv6Header.cc -- The ICMPv6Header Class represents an ICMP version 6  *
 * packet. It contains methods to set any header field. In general, these  *
 * methods do error checkings and byte order conversion.                   *
 *                                                                         *
 ***********************IMPORTANT NMAP LICENSE TERMS************************
 *                                                                         *
 * The Nmap Security Scanner is (C) 1996-2022 Nmap Software LLC ("The Nmap *
 * Project"). Nmap is also a registered trademark of the Nmap Project.     *
 *                                                                         *
 * This program is distributed under the terms of the Nmap Public Source   *
 * License (NPSL). The exact license text applying to a particular Nmap    *
 * release or source code control revision is contained in the LICENSE     *
 * file distributed with that version of Nmap or source code control       *
 * revision. More Nmap copyright/legal information is available from       *
 * https://nmap.org/book/man-legal.html, and further information on the    *
 * NPSL license itself can be found at https://nmap.org/npsl/ . This       *
 * header summarizes some key points from the Nmap license, but is no      *
 * substitute for the actual license text.                                 *
 *                                                                         *
 * Nmap is generally free for end users to download and use themselves,    *
 * including commercial use. It is available from https://nmap.org.        *
 *                                                                         *
 * The Nmap license generally prohibits companies from using and           *
 * redistributing Nmap in commercial products, but we sell a special Nmap  *
 * OEM Edition with a more permissive license and special features for     *
 * this purpose. See https://nmap.org/oem/                                 *
 *                                                                         *
 * If you have received a written Nmap license agreement or contract       *
 * stating terms other than these (such as an Nmap OEM license), you may   *
 * choose to use and redistribute Nmap under those terms instead.          *
 *                                                                         *
 * The official Nmap Windows builds include the Npcap software             *
 * (https://npcap.com) for packet capture and transmission. It is under    *
 * separate license terms which forbid redistribution without special      *
 * permission. So the official Nmap Windows builds may not be              *
 * redistributed without special permission (such as an Nmap OEM           *
 * license).                                                               *
 *                                                                         *
 * Source is provided to this software because we believe users have a     *
 * right to know exactly what a program is going to do before they run it. *
 * This also allows you to audit the software for security holes.          *
 *                                                                         *
 * Source code also allows you to port Nmap to new platforms, fix bugs,    *
 * and add new features.  You are highly encouraged to submit your         *
 * changes as a Github PR or by email to the dev@nmap.org mailing list     *
 * for possible incorporation into the main distribution. Unless you       *
 * specify otherwise, it is understood that you are offering us very       *
 * broad rights to use your submissions as described in the Nmap Public    *
 * Source License Contributor Agreement. This is important because we      *
 * fund the project by selling licenses with various terms, and also       *
 * because the inability to relicense code has caused devastating          *
 * problems for other Free Software projects (such as KDE and NASM).       *
 *                                                                         *
 * The free version of Nmap is distributed in the hope that it will be     *
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of  *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Warranties,        *
 * indemnification and commercial support are all available through the    *
 * Npcap OEM program--see https://nmap.org/oem/                            *
 *                                                                         *
 ***************************************************************************/
/* This code was originally part of the Nping tool.                        */
#include "ICMPv6Header.h"
#include "IPv6Header.h"
#include <assert.h>
/******************************************************************************/
/* CONTRUCTORS, DESTRUCTORS AND INITIALIZATION METHODS                        */
/******************************************************************************/
ICMPv6Header::ICMPv6Header() {
  this->reset();
} /* End of ICMPv6Header constructor */
ICMPv6Header::~ICMPv6Header() {
} /* End of ICMPv6Header destructor */
/** Sets every attribute to its default value */
void ICMPv6Header::reset(){
  memset(&this->h, 0, sizeof(nping_icmpv6_hdr_t));
  h_du = (dest_unreach_msg_t       *)this->h.data;
  h_ptb= (pkt_too_big_msg_t        *)this->h.data;
  h_te = (time_exceeded_msg_t      *)this->h.data;
  h_pp = (parameter_problem_msg_t  *)this->h.data;
  h_e  = (echo_msg_t               *)this->h.data;
  h_ra = (router_advert_msg_t      *)this->h.data;
  h_rs = (router_solicit_msg_t     *)this->h.data;
  h_na = (neighbor_advert_msg_t    *)this->h.data;
  h_ns = (neighbor_solicit_msg_t   *)this->h.data;
  h_r  = (redirect_msg_t           *)this->h.data;
  h_rr = (router_renumbering_msg_t *)this->h.data;
  h_ni = (nodeinfo_msg_t           *)this->h.data;
  h_mld= (mld_msg_t                *)this->h.data;
} /* End of reset() */
/******************************************************************************/
/* PacketElement:: OVERWRITTEN METHODS                                        */
/******************************************************************************/
/** @warning This method is essential for the superclass getBinaryBuffer()
 *  method to work. Do NOT change a thing unless you know what you're doing  */
u8 *ICMPv6Header::getBufferPointer(){
  return (u8*)(&this->h);
} /* End of getBufferPointer() */
/** Stores supplied packet in the internal buffer so the information
  * can be accessed using the standard get & set methods.
  * @warning  The ICMPv6Header class is able to hold a maximum of
  * sizeof(nping_icmpv6_hdr_t) bytes. If the supplied buffer is longer than
  * that, only the first 1508 bytes will be stored in the internal buffer.
  * @warning Supplied len MUST be at least 8 bytes (min ICMPv6 header length).
  * @return OP_SUCCESS on success and OP_FAILURE in case of error */
int ICMPv6Header::storeRecvData(const u8 *buf, size_t len){
  if(buf==NULL || len<ICMPv6_MIN_HEADER_LEN){
    this->length=0;
    return OP_FAILURE;
  }else{
    int stored_len = MIN( sizeof(nping_icmpv6_hdr_t), len);
    this->reset(); /* Re-init the object, just in case the caller had used it already */
    this->length=stored_len;
    memcpy(&(this->h), buf, stored_len);
  }
 return OP_SUCCESS;
} /* End of storeRecvData() */
/* Returns a protocol identifier. This is used by packet parsing funtions
 * that return linked lists of PacketElement objects, to determine the protocol
 * the object represents. */
int ICMPv6Header::protocol_id() const {
    return HEADER_TYPE_ICMPv6;
} /* End of protocol_id() */
/** Determines if the data stored in the object after an storeRecvData() call
  * is valid and safe to use. This mainly checks the length of the data but may
  * also test the value of certain protocol fields to ensure their correctness.
  * @return the length, in bytes, of the header, if its found to be valid or
  * OP_FAILURE (-1) otherwise. */
int ICMPv6Header::validate(){
  int should_have=this->getHeaderLengthFromType( this->getType() );
  if(this->length < should_have){
      return OP_FAILURE;
  }else{
      /* WARNING: If we extend this class to support new ICMPv6 types with
       * a variable length header (not even sure they exist), we need to
       * parse the objects data and return our actual size, not this size that
       * is obtained from the type. */
      return should_have;
  }
} /* End of validate() */
/** Prints the contents of the header and calls print() on the next protocol
  * header in the chain (if there is any).
  * @return OP_SUCCESS on success and OP_FAILURE in case of error. */
int ICMPv6Header::print(FILE *output, int detail) const {
  u8 type=this->getType();
  u8 code=this->getCode();
  const char *typestr=this->type2string(type, code);
  fprintf(output, "ICMPv6[%s", typestr);
  if(detail>=PRINT_DETAIL_MED)
    fprintf(output, " (type=%u/code=%u)", type, code);
  switch(type) {
    case ICMPv6_UNREACH:
    case ICMPv6_TIMXCEED:
      if(detail>=PRINT_DETAIL_HIGH)
        fprintf(output, " unused=%lu", (long unsigned int)this->getUnused());
    break;
    case ICMPv6_ROUTERSOLICIT:
      if(detail>=PRINT_DETAIL_HIGH)
        fprintf(output, " reserved=%lu", (long unsigned int)this->getReserved());
    break;
    case ICMPv6_PKTTOOBIG:
      fprintf(output, " mtu=%lu", (long unsigned int)this->getMTU());
    break;
    case ICMPv6_PARAMPROB:
      fprintf(output, " pointer=%lu", (long unsigned int)this->getPointer());
    break;
    case ICMPv6_ECHO:
    case ICMPv6_ECHOREPLY:
      fprintf(output, " id=%u seq=%u", this->getIdentifier(), this->getSequence());
    break;
    case ICMPv6_NODEINFOQUERY:
    case ICMPv6_NODEINFORESP:
      if(this->getNodeInfoFlags()!=0){
        fprintf(output, " flags=");
        if(this->getNodeInfoFlags() & ICMPv6_NI_FLAG_T)
          fprintf(output, "T");
        if(this->getNodeInfoFlags() & ICMPv6_NI_FLAG_A)
          fprintf(output, "A");
        if(this->getNodeInfoFlags() & ICMPv6_NI_FLAG_C)
          fprintf(output, "C");
        if(this->getNodeInfoFlags() & ICMPv6_NI_FLAG_L)
          fprintf(output, "L");
        if(this->getNodeInfoFlags() & ICMPv6_NI_FLAG_G)
          fprintf(output, "G");
        if(this->getNodeInfoFlags() & ICMPv6_NI_FLAG_S)
          fprintf(output, "S");
        }
      if(detail>=PRINT_DETAIL_HIGH){
        #ifdef WIN32
          fprintf(output, " nonce=%I64u",  (long long unsigned int)this->getNonce());
        #else
          fprintf(output, " nonce=%llu",  (long long unsigned int)this->getNonce());
        #endif
      }
    break;
    default:
        /* Print nothing */
    break;
  }
  if(detail>=PRINT_DETAIL_HIGH)
      fprintf(output, " csum=0x%04X", ntohs(this->getSum()));
  fprintf(output, "]");
  if(this->next!=NULL){
    print_separator(output, detail);
    next->print(output, detail);
  }
  return OP_SUCCESS;
} /* End of print() */
/******************************************************************************/
/* PROTOCOL-SPECIFIC METHODS                                                  */
/******************************************************************************/
/******************************************************************************/
/* ICMPv6 COMMON HEADER                                                       */
/******************************************************************************/
/** Set ICMPv6 type field */
int ICMPv6Header::setType(u8 val){
  this->h.type = val;
  this->length = getHeaderLengthFromType(val);
  return OP_SUCCESS;
} /* End of setType() */
/** Returns ICMPv6 type field */
u8 ICMPv6Header::getType() const {
  return this->h.type;
} /* End of getType() */
/* Returns true if the supplied ICMPv6 type is supported by this class */
bool ICMPv6Header::validateType(u8 val){
  switch( val ){
    case ICMPv6_UNREACH:
    case ICMPv6_PKTTOOBIG:
    case ICMPv6_TIMXCEED:
    case ICMPv6_PARAMPROB:
    case ICMPv6_ECHO:
    case ICMPv6_ECHOREPLY:
    case ICMPv6_ROUTERSOLICIT:
    case ICMPv6_ROUTERADVERT:
    case ICMPv6_NGHBRSOLICIT:
    case ICMPv6_NGHBRADVERT:
    case ICMPv6_REDIRECT:
    case ICMPv6_RTRRENUM:
        return true;
    break;
    default:
        return false;
    break;
  }
  return false;
} /* End of validateType() */
bool ICMPv6Header::validateType(){
  return validateType(this->h.type);
} /* End of validateType() */
/** Set ICMPv6 code field */
int ICMPv6Header::setCode(u8 val){
  this->h.code = val;
  return OP_SUCCESS;
} /* End of setCode() */
/** Returns ICMPv6 code field */
u8 ICMPv6Header::getCode() const {
  return this->h.code;
} /* End of getCode() */
/** Given an ICMP Type and a code, determines whether the code corresponds to
  * a RFC compliant code (eg: code 0x03  for "port unreachable" in ICMP
  * Unreachable messages) or just some other bogus code. */
bool ICMPv6Header::validateCode(u8 type, u8 code){
//    switch (type){
//
//        case ICMPv6_UNREACH:
//            return (code==0);
//        break;
//
//        case ICMPv6_PKTTOOBIG:
//            switch( code ){
//                case XXXXXXXXXXXX:
//                case YYYYYYYYYYYY:
//                case ZZZZZZZZZZZZ:
//                    return true;
//                break;
//            }
//        break;
//
//        case ICMPv6_TIMXCEED:
//
//        break;
//
//        case ICMPv6_PARAMPROB:
//
//        break;
//
//        case ICMPv6_ECHO:
//
//        break;
//
//        case ICMPv6_ECHOREPLY:
//
//        break;
//
//        case ICMPv6_ROUTERSOLICIT:
//        case ICMPv6_ROUTERADVERT:
//        case ICMPv6_NGHBRSOLICIT:
//        case ICMPv6_NGHBRADVERT:
//        case ICMPv6_REDIRECT:
//        break;
//
//        default:
//            return false;
//        break;
//    }
    return false;
} /* End of validateCode() */
/** Computes the ICMP header checksum and sets the checksum field to the right
 *  value.
 * @warning  This method requires the ICMPv6Object to be linked to an IPv6Header
 * object, so make sure setNextElement() has been called like this:
 *
 * IPv6Header ip6;
 * ICMPv6Header icmp6;
 * [...] # Set header fields
 * ip6.setNextElement(&icmp6);
 * icmp6.setSum();
 *
 * Note that there can be a number of extension headers between the ICMPv6
 * header and the IPv6 one, but all of them need to be linked in order for this
 * method to traverse the list of headers and find the IPv6 source and
 * destination address, required to compute the checksum. So things like the
 * following are OK:
 *
 * IPv6Header ip6;
 * HopByHopHeader hop;
 * RoutingHeader rte;
 * FragmentHeader frg;
 * ICMPv6Header icmp6;
 * [...] # Set whatever header fields you need
 * ip6.setNextElement(&hop);
 * hop.setNextElement(&rte);
 * rte.setNextElement(&frg);
 * frg.setNextElement(&icmp6);
 * icmp6.setSum(); # setSum() will be able to reach the IPv6Header.
 *
 */
int ICMPv6Header::setSum(){
  PacketElement *hdr;
  hdr=this->getPrevElement();
  /* Traverse the list of headers backwards until we find the IPv6 header */
  while(hdr!=NULL){
      if (hdr->protocol_id()==HEADER_TYPE_IPv6){
            IPv6Header *v6hdr=(IPv6Header *)hdr;
            struct in6_addr i6src, i6dst;
            this->h.checksum=0;
            memcpy(i6src.s6_addr, v6hdr->getSourceAddress(), 16);
            memcpy(i6dst.s6_addr, v6hdr->getDestinationAddress(), 16);
            u8 *buff=(u8 *)safe_malloc(this->getLen());
            this->dumpToBinaryBuffer(buff, this->getLen());
            this->h.checksum=ipv6_pseudoheader_cksum(&i6src, &i6dst, this->protocol_id(), this->getLen(), buff);
            free(buff);
          return OP_SUCCESS;
      }else{
          hdr=hdr->getPrevElement();
      }
  }
  return OP_FAILURE;
} /* End of setSum() */
/** @warning Sum is set to supplied value with NO byte ordering conversion
 *  performed.
 *  @warning If sum is supplied this way, no error checks are made. Caller is
 *  responsible for the correctness of the value. */
int ICMPv6Header::setSum(u16 s){
  this->h.checksum=s;
  return OP_SUCCESS;
} /* End of setSum() */
/** Returns the value of the checksum field.
 *  @warning The returned value is in NETWORK byte order, no conversion is
 *  performed */
u16 ICMPv6Header::getSum() const{
  return this->h.checksum;
} /* End of getSum() */
/** @warning Supplied value MUST be in host byte order because it will get
 *  converted by this method using htonl() */
int ICMPv6Header::setReserved(u32 val){
  u32 aux32=0;
  u8 *auxpnt=(u8 *)&aux32;
  switch(this->h.type){
    case ICMPv6_UNREACH:
        this->h_du->unused=htonl(val);
    break;
    case ICMPv6_TIMXCEED:
        this->h_te->unused=htonl(val);
    break;
    case ICMPv6_ROUTERSOLICIT:
        this->h_rs->reserved=htonl(val);
    break;
    case ICMPv6_NGHBRSOLICIT:
        this->h_ns->reserved=htonl(val);
    break;
    case ICMPv6_REDIRECT:
        this->h_r->reserved=htonl(val);
    break;
    case ICMPv6_NGHBRADVERT:
        /* The reserved field in Neighbor Advertisement messages is only
         * 24-bits long so we convert the supplied value to big endian and
         * use only the 24 least significant bits. */
        aux32=htonl(val);
        this->h_na->reserved[0]=auxpnt[1];
        this->h_na->reserved[1]=auxpnt[2];
        this->h_na->reserved[2]=auxpnt[3];
    break;
    case ICMPv6_RTRRENUM:
        this->h_rr->reserved=htonl(val);
    break;
    /* Types that don't have a reserved field */
    case ICMPv6_ROUTERADVERT:
    case ICMPv6_ECHO:
    case ICMPv6_ECHOREPLY:
    case ICMPv6_PARAMPROB:
    case ICMPv6_PKTTOOBIG:
    default:
        return OP_FAILURE;
    break;
  }
  return OP_SUCCESS;
} /* End of setReserved() */
/** @warning Returned value is in host byte order */
u32 ICMPv6Header::getReserved() const {
  u32 aux32=0;
  u8 *auxpnt=(u8 *)&aux32;
  switch(this->h.type){
    case ICMPv6_UNREACH:
        return ntohl(this->h_du->unused);
    break;
    case ICMPv6_TIMXCEED:
        return ntohl(this->h_te->unused);
    break;
    case ICMPv6_ROUTERSOLICIT:
        return ntohl(this->h_rs->reserved);
    break;
    case ICMPv6_NGHBRSOLICIT:
        return ntohl(this->h_ns->reserved);
    break;
    case ICMPv6_REDIRECT:
        return ntohl(this->h_r->reserved);
    break;
    case ICMPv6_NGHBRADVERT:
        /* The reserved field in Neighbor Advertisement messages is only
         * 24-bits long so we extract the stored value and convert it to host
         * byte order. */
        auxpnt[0]=0;
        auxpnt[1]=this->h_na->reserved[0];
        auxpnt[2]=this->h_na->reserved[1];
        auxpnt[3]=this->h_na->reserved[2];
        return ntohl(aux32);
    break;
    case ICMPv6_RTRRENUM:
        return ntohl(this->h_rr->reserved);
    break;
    /* Types that don't have a reserved field */
    case ICMPv6_ROUTERADVERT:
    case ICMPv6_ECHO:
    case ICMPv6_ECHOREPLY:
    case ICMPv6_PARAMPROB:
    case ICMPv6_PKTTOOBIG:
    default:
        return 0;
    break;
  }
} /* End of setReserved() */
int ICMPv6Header::setUnused(u32 val){
  return this->setReserved(val);
} /* End of setUnused() */
u32 ICMPv6Header::getUnused() const {
  return this->getReserved();
} /* End of getUnused() */
int ICMPv6Header::setFlags(u8 val){
  switch(this->h.type){
    case ICMPv6_ROUTERADVERT:
        this->h_ra->autoconfig_flags=val;
    break;
    case ICMPv6_NGHBRADVERT:
        this->h_na->flags=val;
    break;
    case ICMPv6_RTRRENUM:
        this->h_rr->flags=val;
    break;
    case ICMPv6_NODEINFOQUERY:
    case ICMPv6_NODEINFORESP:
        netutil_fatal("setFlags() cannot be used in NI, use setNodeInfoFlags() instead\n");
    break;
    /* Types that don't have a flags field */
    case ICMPv6_TIMXCEED:
    case ICMPv6_UNREACH:
    case ICMPv6_ROUTERSOLICIT:
    case ICMPv6_NGHBRSOLICIT:
    case ICMPv6_REDIRECT:
    case ICMPv6_ECHO:
    case ICMPv6_ECHOREPLY:
    case ICMPv6_PARAMPROB:
    case ICMPv6_PKTTOOBIG:
    default:
        return OP_FAILURE;
    break;
  }
  return OP_SUCCESS;
} /* End of setFlags() */
u8 ICMPv6Header::getFlags() const {
  switch(this->h.type){
    case ICMPv6_ROUTERADVERT:
        return this->h_ra->autoconfig_flags;
    break;
    case ICMPv6_NGHBRADVERT:
        return this->h_na->flags;
    break;
    case ICMPv6_RTRRENUM:
        return this->h_rr->flags;
    break;
    case ICMPv6_NODEINFOQUERY:
    case ICMPv6_NODEINFORESP:
        netutil_fatal("getFlags() cannot be used in NI, use getNodeInfoFlags() instead\n");
        return 0;
    break;
    /* Types that don't have a flags field */
    case ICMPv6_TIMXCEED:
    case ICMPv6_UNREACH:
    case ICMPv6_ROUTERSOLICIT:
    case ICMPv6_NGHBRSOLICIT:
    case ICMPv6_REDIRECT:
    case ICMPv6_ECHO:
    case ICMPv6_ECHOREPLY:
    case ICMPv6_PARAMPROB:
    case ICMPv6_PKTTOOBIG:
    default:
        return 0;
    break;
  }
} /* End of getFlags() */
/******************************************************************************/
/* ICMPv6 DESTINATION UNREACHABLE                                             */
/******************************************************************************/
/******************************************************************************/
/* ICMPv6 PACKET TOO BIG                                                      */
/******************************************************************************/
int ICMPv6Header::setMTU(u32 mtu){
  this->h_ptb->mtu=htonl(mtu);
  return OP_SUCCESS;
} /* End of setMTU() */
u32 ICMPv6Header::getMTU() const {
  return ntohl(this->h_ptb->mtu);
} /* End of getMTU() */
/******************************************************************************/
/* ICMPv6 TIME EXCEEDED                                                       */
/******************************************************************************/
/******************************************************************************/
/* ICMPv6 PARAMETER PROBLEM                                                   */
/******************************************************************************/
int ICMPv6Header::setPointer(u32 pnt){
  this->h_pp->pointer=htonl(pnt);
  return OP_SUCCESS;
} /* End of setPointer() */
u32 ICMPv6Header::getPointer() const {
  return ntohl(this->h_pp->pointer);
} /* End of getPointer() */
/******************************************************************************/
/* ICMPv6 ECHO                                                                */
/******************************************************************************/
int ICMPv6Header::setIdentifier(u16 val){
  this->h_e->id=htons(val);
  return OP_SUCCESS;
} /* End of setIdentifier() */
u16 ICMPv6Header::getIdentifier() const{
  return ntohs(this->h_e->id);
} /* End of getIdentifier() */
int ICMPv6Header::setSequence(u16 val){
  switch(this->h.type){
    case ICMPv6_RTRRENUM:
        this->h_rr->seq=htonl( ((u32)val) );
    break;
    case ICMPv6_ECHO:
    case ICMPv6_ECHOREPLY:
        this->h_e->seq=htons(val);
    break;
    default:
        return OP_FAILURE;
    break;
  }
  return OP_SUCCESS;
} /* End of setSequence() */
int ICMPv6Header::setSequence(u32 val){
  switch(this->h.type){
    case ICMPv6_RTRRENUM:
        this->h_rr->seq=htonl(val);
    break;
    case ICMPv6_ECHO:
    case ICMPv6_ECHOREPLY:
        this->h_e->seq=htons( ((u16)val) );
    break;
    default:
        return OP_FAILURE;
    break;
  }
  return OP_SUCCESS;
} /* End of setSequence() */
u32 ICMPv6Header::getSequence() const{
  switch(this->h.type){
    case ICMPv6_RTRRENUM:
        return ntohl(this->h_rr->seq);
    break;
    case ICMPv6_ECHO:
    case ICMPv6_ECHOREPLY:
        return (u32)ntohs(this->h_e->seq);
    break;
  }
  return 0;
} /* End of getSequence() */
/******************************************************************************/
/* ICMPv6 ROUTER ADVERTISEMENT                                                */
/******************************************************************************/
int ICMPv6Header::setCurrentHopLimit(u8 val){
  this->h_ra->current_hop_limit=val;
  return OP_SUCCESS;
} /* End of setCurrentHopLimit() */
u8 ICMPv6Header::getCurrentHopLimit() const {
  return this->h_ra->current_hop_limit;
} /* End of getCurrentHopLimit() */
int ICMPv6Header::setRouterLifetime(u16 val){
  this->h_ra->router_lifetime=val;
  return OP_SUCCESS;
} /* End of setRouterLifetime() */
u16 ICMPv6Header::getRouterLifetime() const {
  return this->h_ra->router_lifetime;
} /* End of getRouterLifetime() */
int ICMPv6Header::setReachableTime(u32 val){
  this->h_ra->reachable_time=val;
  return OP_SUCCESS;
} /* End of setReachableTime() */
u32 ICMPv6Header::getReachableTime() const {
    return this->h_ra->reachable_time;
} /* End of getReachableTime() */
int ICMPv6Header::setRetransmissionTimer(u32 val){
  this->h_ra->retransmission_timer=val;
  return OP_SUCCESS;
} /* End of setRetransmissionTimer() */
u32 ICMPv6Header::getRetransmissionTimer() const {
  return this->h_ra->retransmission_timer;
} /* End of getRetransmissionTimer() */
/******************************************************************************/
/* ICMPv6 ROUTER SOLICITATION                                                 */
/******************************************************************************/
/******************************************************************************/
/* ICMPv6 NEIGHBOR ADVERTISEMENT                                              */
/******************************************************************************/
int ICMPv6Header::setTargetAddress(struct in6_addr addr){
  switch(this->h.type){
    case ICMPv6_NGHBRADVERT:
        memcpy(this->h_na->target_address, addr.s6_addr, 16);
    break;
    case ICMPv6_NGHBRSOLICIT:
        memcpy(this->h_ns->target_address, addr.s6_addr, 16);
    break;
    case ICMPv6_REDIRECT:
         memcpy(this->h_r->target_address, addr.s6_addr, 16);
    break;
    default:
        return OP_FAILURE;
    break;
  }
  return OP_SUCCESS;
} /* End of setTargetAddress() */
struct in6_addr ICMPv6Header::getTargetAddress() const {
  struct in6_addr addr;
  memset(&addr, 0, sizeof(struct in6_addr));
  switch(this->h.type){
    case ICMPv6_NGHBRADVERT:
        memcpy(addr.s6_addr, this->h_na->target_address, 16);
    break;
    case ICMPv6_NGHBRSOLICIT:
        memcpy(addr.s6_addr, this->h_ns->target_address, 16);
    break;
    case ICMPv6_REDIRECT:
         memcpy(addr.s6_addr, this->h_r->target_address, 16);
    break;
  }
  return addr;
} /* End of setTargetAddress() */
int ICMPv6Header::setDestinationAddress(struct in6_addr addr){
  switch(this->h.type){
    case ICMPv6_REDIRECT:
         memcpy(this->h_r->destination_address, addr.s6_addr, 16);
    break;
    default:
        return OP_FAILURE;
    break;
  }
  return OP_SUCCESS;
} /* End of setDestinationAddress() */
struct in6_addr ICMPv6Header::getDestinationAddress() const {
  struct in6_addr addr;
  memset(&addr, 0, sizeof(struct in6_addr));
  switch(this->h.type){
    case ICMPv6_REDIRECT:
         memcpy(addr.s6_addr, this->h_r->destination_address, 16);
    break;
  }
  return addr;
} /* End of setTargetAddress() */
/******************************************************************************/
/* ICMPv6 NEIGHBOR SOLICITATION                                               */
/******************************************************************************/
/******************************************************************************/
/* ICMPv6 REDIRECT                                                            */
/******************************************************************************/
/******************************************************************************/
/* ICMPv6 ROUTER RENUMBERING                                                  */
/******************************************************************************/
int ICMPv6Header::setSegmentNumber(u8 val){
  this->h_rr->segment_number=val;
  return OP_SUCCESS;
} /* End of setSegmentNumber() */
u8 ICMPv6Header::getSegmentNumber() const {
  return this->h_rr->segment_number;
} /* End of getSegmentNumber() */
int ICMPv6Header::setMaxDelay(u16 val){
  switch(this->h.type){
    case ICMPv6_RTRRENUM:
      this->h_rr->max_delay=htons(val);
      return OP_SUCCESS;
    break;
    case ICMPv6_GRPMEMBQUERY:
    case ICMPv6_GRPMEMBREP:
    case ICMPv6_GRPMEMBRED:
      this->h_mld->max_response_delay=htons(val);
      return OP_SUCCESS;
    break;
    default:
      return OP_FAILURE;
    break;
  }
} /* End of setMaxDelay() */
u16 ICMPv6Header::getMaxDelay() const {
  switch(this->h.type){
    case ICMPv6_RTRRENUM:
      return ntohs(this->h_rr->max_delay);
    break;
    case ICMPv6_GRPMEMBQUERY:
    case ICMPv6_GRPMEMBREP:
    case ICMPv6_GRPMEMBRED:
      return ntohs(this->h_mld->max_response_delay);
    break;
    default:
      return 0;
    break;
  }
} /* End of getMaxDelay() */
/******************************************************************************/
/* ICMPv6 NODE INFORMATION QUERIES                                            */
/******************************************************************************/
/** Set NI Qtype */
int ICMPv6Header::setQtype(u16 val){
  this->h_ni->qtype = htons(val);
  return OP_SUCCESS;
} /* End of setQtype() */
/** Returns NI Qtype */
u16 ICMPv6Header::getQtype() const {
  return ntohs(this->h_ni->qtype);
} /* End of getQtype() */
/** Set NI Flags */
int ICMPv6Header::setNodeInfoFlags(u16 val){
  this->h_ni->flags = htons(val);
  return OP_SUCCESS;
} /* End of setNodeInfoFlags() */
/** Returns NI Flags */
u16 ICMPv6Header::getNodeInfoFlags() const {
  return ntohs(this->h_ni->flags);
} /* End of getNodeInfoFlags() */
/*  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |       unused      |G|S|L|C|A|T|
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */
/* Set NI Flag G */
int ICMPv6Header::setG(bool flag_value){
  u16 current_flags = this->getNodeInfoFlags();
  if(flag_value)
    current_flags = current_flags | 0x0020;
  else
    current_flags = current_flags & ~0x0020;
  this->setNodeInfoFlags(current_flags);
  return OP_SUCCESS;
} /* End of setG() */
/* Get NI Flag G */
bool ICMPv6Header::getG() const {
  return this->getNodeInfoFlags() & 0x0020;
} /* End of getG() */
/* Set NI Flag S */
int ICMPv6Header::setS(bool flag_value){
  u16 current_flags = this->getNodeInfoFlags();
  if(flag_value)
    current_flags = current_flags | 0x0010;
  else
    current_flags = current_flags & ~0x0010;
  this->setNodeInfoFlags(current_flags);
  return OP_SUCCESS;
} /* End of setS() */
/* Get NI Flag  S */
bool ICMPv6Header::getS() const {
  return this->getNodeInfoFlags() & 0x0010;
} /* End of getS() */
/* Set NI Flag L */
int ICMPv6Header::setL(bool flag_value){
  u16 current_flags = this->getNodeInfoFlags();
  if(flag_value)
    current_flags = current_flags | 0x0008;
  else
    current_flags = current_flags & ~0x0008;
  this->setNodeInfoFlags(current_flags);
  return OP_SUCCESS;
} /* End of setL() */
/* Get NI Flag L */
bool ICMPv6Header::getL() const {
  return this->getNodeInfoFlags() & 0x0008;
} /* End of getL() */
/* Set NI Flag C */
int ICMPv6Header::setC(bool flag_value){
  u16 current_flags = this->getNodeInfoFlags();
  if(flag_value)
    current_flags = current_flags | 0x0004;
  else
    current_flags = current_flags & ~0x0004;
  this->setNodeInfoFlags(current_flags);
  return OP_SUCCESS;
} /* End of setC() */
/* Get NI Flag C */
bool ICMPv6Header::getC() const {
  return this->getNodeInfoFlags() & 0x0004;
} /* End of getC() */
/* Set NI Flag A */
int ICMPv6Header::setA(bool flag_value){
  u16 current_flags = this->getNodeInfoFlags();
  if(flag_value)
    current_flags = current_flags | 0x0002;
  else
    current_flags = current_flags & ~0x0002;
  this->setNodeInfoFlags(current_flags);
  return OP_SUCCESS;
} /* End of setA() */
/* Get NI Flag A */
bool ICMPv6Header::getA() const {
  return this->getNodeInfoFlags() & 0x0002;
} /* End of getA() */
/* Set NI Flag T */
int ICMPv6Header::setT(bool flag_value){
  u16 current_flags = this->getNodeInfoFlags();
  if(flag_value)
    current_flags = current_flags | 0x0001;
  else
    current_flags = current_flags & ~0x0001;
  this->setNodeInfoFlags(current_flags);
  return OP_SUCCESS;
} /* End of setT() */
/* Get NI Flag T */
bool ICMPv6Header::getT() const {
  return this->getNodeInfoFlags() & 0x0001;
} /* End of getT() */
/* Set the Nonce field. */
int ICMPv6Header::setNonce(u64 nonce_value){
  this->h_ni->nonce=nonce_value;
  return OP_SUCCESS;
} /* End of setNonce() */
/* Set the Nonce field.
 * @warning: Supplied buffer must contain 8 bytes. */
int ICMPv6Header::setNonce(const u8 *nonce){
  if(nonce==NULL)
    return OP_FAILURE;
  memcpy(&(this->h_ni->nonce), nonce, NI_NONCE_LEN);
  return OP_SUCCESS;
} /* End of setNonce() */
/* Returns a pointer to the nonce buffer.
 * @warning: The returned pointer is guaranteed to point to an 8-byte buffer.
 * However, what comes after the 8th byte is unspecified. */
u64 ICMPv6Header::getNonce() const {
  return this->h_ni->nonce;
} /* End of getNonce() */
/******************************************************************************/
/* MULTICAST LISTENER DISCOVERY                                               */
/******************************************************************************/
int ICMPv6Header::setMulticastAddress(struct in6_addr addr){
  switch(this->h.type){
    case ICMPv6_GRPMEMBQUERY:
    case ICMPv6_GRPMEMBREP:
    case ICMPv6_GRPMEMBRED:
       memcpy(this->h_mld->mcast_address, addr.s6_addr, 16);
    break;
    default:
        return OP_FAILURE;
    break;
  }
  return OP_SUCCESS;
} /* End of setMulticastAddress() */
struct in6_addr ICMPv6Header::getMulticastAddress() const {
  struct in6_addr addr;
  memset(&addr, 0, sizeof(struct in6_addr));
  switch(this->h.type){
    case ICMPv6_GRPMEMBQUERY:
    case ICMPv6_GRPMEMBREP:
    case ICMPv6_GRPMEMBRED:
       memcpy(addr.s6_addr, this->h_mld->mcast_address, 16);
    break;
  }
  return addr;
} /* End of setMulticastAddress() */
/******************************************************************************/
/* MISCELLANEOUS STUFF                                                        */
/******************************************************************************/
/** Returns the standard ICMPv6 header length for the supplied ICMP message type.
  * @warning Return value corresponds strictly to the ICMP header, this is,
  * the minimum length of the ICMP header, variable length payload is never
  * included. For example, an ICMPv6 Redirect has a fixed header of 40
  * bytes but then the packet may contain ICMPv6 options. We only return 40
  * because we don't know in advance the total number of bytes for the message.
  * Same applies to the rest of types. */
int ICMPv6Header::getHeaderLengthFromType(u8 type) const {
  switch( type ){
    case ICMPv6_UNREACH:
        return ICMPv6_UNREACH_LEN;
    break;
    case ICMPv6_PKTTOOBIG:
        return ICMPv6_PKTTOOBIG_LEN;
    break;
    case ICMPv6_TIMXCEED:
        return ICMPv6_TIMXCEED_LEN;
    break;
    case ICMPv6_PARAMPROB:
        return ICMPv6_PARAMPROB_LEN;
    break;
    case ICMPv6_ECHO:
        return ICMPv6_ECHO_LEN;
    break;
    case ICMPv6_ECHOREPLY:
        return ICMPv6_ECHOREPLY_LEN;
    break;
    case ICMPv6_ROUTERSOLICIT:
        return ICMPv6_ROUTERSOLICIT_LEN;
    break;
    case ICMPv6_ROUTERADVERT:
        return ICMPv6_ROUTERADVERT_LEN;
    break;
    case ICMPv6_NGHBRSOLICIT:
        return ICMPv6_NGHBRSOLICIT_LEN;
    break;
    case ICMPv6_NGHBRADVERT:
        return ICMPv6_NGHBRADVERT_LEN;
    break;
    case ICMPv6_REDIRECT:
        return ICMPv6_REDIRECT_LEN;
    break;
    case ICMPv6_RTRRENUM:
        return ICMPv6_RTRRENUM_LEN;
    break;
    case ICMPv6_NODEINFOQUERY:
    case ICMPv6_NODEINFORESP:
        return ICMPv6_NODEINFO_LEN;
    break;
    case ICMPv6_GRPMEMBQUERY:
    case ICMPv6_GRPMEMBREP:
    case ICMPv6_GRPMEMBRED:
        return ICMPv6_MLD_LEN;
    break;
    /* Packets with non RFC-Compliant types will be represented as an 8-byte
     * ICMPv6 header, just like the types that don't include additional info */
    default:
        return ICMPv6_MIN_HEADER_LEN;
    break;
  }
} /* End of getHeaderLengthFromType() */
/* Returns true if the packet is an ICMPv6 error message. */
bool ICMPv6Header::isError() const {
  switch( this->getType() ){
    case ICMPv6_UNREACH:
    case ICMPv6_PKTTOOBIG:
    case ICMPv6_TIMXCEED:
    case ICMPv6_PARAMPROB:
      return true;
    break;
    default:
      return false;
    break;
  }
} /* End of isError() */
const char *ICMPv6Header::type2string(int type, int code) const {
  switch(type) {
    case ICMPv6_UNREACH:
      switch(code) {
        case ICMPv6_UNREACH_NO_ROUTE: return "Network unreachable"; break;
        case ICMPv6_UNREACH_PROHIBITED: return "Comm prohibited"; break;
        case ICMPv6_UNREACH_BEYOND_SCOPE: return "Beyond scope"; break;
        case ICMPv6_UNREACH_ADDR_UNREACH: return "Address unreachable"; break;
        case ICMPv6_UNREACH_PORT_UNREACH: return "Port unreachable"; break;
        case ICMPv6_UNREACH_SRC_ADDR_FAILED: return "Source address failed"; break;
        case ICMPv6_UNREACH_REJECT_ROUTE: return "Reject route"; break;
        default: return "Destination unreachable (unknown code)"; break;
      }
    break;
    case ICMPv6_PKTTOOBIG:
      return "Packet too big";
    break;
    case ICMPv6_TIMXCEED:
      switch(code){
        case ICMPv6_TIMXCEED_HOP_EXCEEDED: return "HopLimit=0 in transit"; break;
        case ICMPv6_TIMXCEED_REASS_EXCEEDED: return "Reassembly time exceeded"; break;
        default: return "Time exceeded (unknown code)"; break;
      }
    break;
    case ICMPv6_PARAMPROB:
      switch(code){
        case ICMPv6_PARAMPROB_FIELD: return "Parameter problem (bad field)"; break;
        case ICMPv6_PARAMPROB_NEXT_HDR: return "Parameter problem (next header unknown)"; break;
        case ICMPv6_PARAMPROB_OPTION: return "Parameter problem (bad option)"; break;
        default: return "Parameter problem (unknown code)"; break;
      }
    break;
    case ICMPv6_ECHO:
      return "Echo request";
    break;
    case ICMPv6_ECHOREPLY:
      return "Echo reply";
    break;
    case ICMPv6_GRPMEMBQUERY:
      return "Group membership query";
    break;
    case ICMPv6_GRPMEMBREP:
      return "Group membership report";
    break;
    case ICMPv6_GRPMEMBRED:
      return "Group membership reduction";
    break;
    case ICMPv6_ROUTERSOLICIT:
      return "Router sol";
    break;
    case ICMPv6_ROUTERADVERT:
      return "Router advert";
    break;
    case ICMPv6_NGHBRSOLICIT:
      return "Neighbor sol";
    break;
    case ICMPv6_NGHBRADVERT:
      return "Neighbor advert";
    break;
    case ICMPv6_REDIRECT:
      return "Redirect";
    break;
    case ICMPv6_RTRRENUM:
      switch(code){
        case ICMPv6_RTRRENUM_COMMAND: return "Renumbering command"; break;
        case ICMPv6_RTRRENUM_RESULT: return "Renumbering result"; break;
        case ICMPv6_RTRRENUM_SEQ_RESET: return "Renumbering reset"; break;
        default: return "Router Renumbering (unknown code)"; break;
      }
    break;
    case ICMPv6_NODEINFOQUERY:
      switch(code){
        case ICMPv6_NODEINFOQUERY_IPv6ADDR: return "Node info query (IPv6 addr)"; break;
        case ICMPv6_NODEINFOQUERY_NAME: return "Node info query (name)"; break;
        case ICMPv6_NODEINFOQUERY_IPv4ADDR: return "Node info query (IPv4 addr)"; break;
        default: return "Node info query (unknown code)"; break;
      }
    break;
    case ICMPv6_NODEINFORESP:
      switch(code){
        case ICMPv6_NODEINFORESP_SUCCESS: return "Node info reply (success)"; break;
        case ICMPv6_NODEINFORESP_REFUSED: return "Node info reply (refused)"; break;
        case ICMPv6_NODEINFORESP_UNKNOWN: return "Node info reply (qtype unknown)"; break;
        default: return "Node info reply (unknown code)"; break;
      }
    break;
    case ICMPv6_INVNGHBRSOLICIT:
      return "Inverse neighbor sol";
    break;
    case ICMPv6_INVNGHBRADVERT:
      return "Inverse neighbor advert";
    break;
    case ICMPv6_MLDV2:
      return "MLDv2 report";
    break;
    case ICMPv6_AGENTDISCOVREQ:
      return "Home agent request";
    break;
    case ICMPv6_AGENTDISCOVREPLY:
      return "Home agent reply";
    break;
    case ICMPv6_MOBPREFIXSOLICIT:
      return "Prefix sol";
    break;
    case ICMPv6_MOBPREFIXADVERT:
      return "Prefix advert";
    break;
    case ICMPv6_CERTPATHSOLICIT:
      return "Cert path sol";
    break;
    case ICMPv6_CERTPATHADVERT:
      return "Cert path advert";
    break;
    case ICMPv6_EXPMOBILITY:
      return "Experimental mobility";
    break;
    case ICMPv6_MRDADVERT:
      return "Multicast router advert";
    break;
    case ICMPv6_MRDSOLICIT:
      return "Multicast router sol";
    break;
    case ICMPv6_MRDTERMINATE:
      return "Multicast router term";
    break;
    case ICMPv6_FMIPV6:
      return "FMIPv6";
    break;
    default:
      return "Unknown ICMPv6 type";
    break;
  } /* End of ICMP Type switch */
  return "Unknown ICMPv6 type";
} /* End of type2string() */
 
     |