print-msdp.c revision 190207
198524Sfenner/* 298524Sfenner * Copyright (c) 2001 William C. Fenner. 398524Sfenner * All rights reserved. 498524Sfenner * 598524Sfenner * Redistribution and use in source and binary forms, with or without 698524Sfenner * modification, are permitted provided that: (1) source code 798524Sfenner * distributions retain the above copyright notice and this paragraph 898524Sfenner * in its entirety, and (2) distributions including binary code include 998524Sfenner * the above copyright notice and this paragraph in its entirety in 1098524Sfenner * the documentation or other materials provided with the distribution. 1198524Sfenner * The name of William C. Fenner may not be used to endorse or 1298524Sfenner * promote products derived from this software without specific prior 1398524Sfenner * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND 1498524Sfenner * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 1598524Sfenner * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1698524Sfenner * FOR A PARTICULAR PURPOSE. 1798524Sfenner */ 1898524Sfenner#ifndef lint 19127668Sbmsstatic const char rcsid[] _U_ = 20190207Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/print-msdp.c,v 1.7 2005-04-06 21:32:41 mcr Exp $"; 2198524Sfenner#endif 2298524Sfenner 2398524Sfenner#ifdef HAVE_CONFIG_H 2498524Sfenner#include "config.h" 2598524Sfenner#endif 2698524Sfenner 27127668Sbms#include <tcpdump-stdinc.h> 28127668Sbms 2998524Sfenner#include <stdio.h> 3098524Sfenner#include <stdlib.h> 3198524Sfenner 3298524Sfenner#include "interface.h" 3398524Sfenner#include "addrtoname.h" 3498524Sfenner#include "extract.h" 3598524Sfenner 3698524Sfenner#define MSDP_TYPE_MAX 7 3798524Sfenner 3898524Sfennervoid 3998524Sfennermsdp_print(const unsigned char *sp, u_int length) 4098524Sfenner{ 4198524Sfenner unsigned int type, len; 4298524Sfenner 4398524Sfenner TCHECK2(*sp, 3); 4498524Sfenner /* See if we think we're at the beginning of a compound packet */ 4598524Sfenner type = *sp; 4698524Sfenner len = EXTRACT_16BITS(sp + 1); 4798524Sfenner if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX) 4898524Sfenner goto trunc; /* not really truncated, but still not decodable */ 4998524Sfenner (void)printf(" msdp:"); 5098524Sfenner while (length > 0) { 5198524Sfenner TCHECK2(*sp, 3); 5298524Sfenner type = *sp; 5398524Sfenner len = EXTRACT_16BITS(sp + 1); 5498524Sfenner if (len > 1400 || vflag) 55127668Sbms printf(" [len %u]", len); 5698524Sfenner if (len < 3) 5798524Sfenner goto trunc; 5898524Sfenner sp += 3; 5998524Sfenner length -= 3; 6098524Sfenner switch (type) { 6198524Sfenner case 1: /* IPv4 Source-Active */ 6298524Sfenner case 3: /* IPv4 Source-Active Response */ 6398524Sfenner if (type == 1) 6498524Sfenner (void)printf(" SA"); 6598524Sfenner else 6698524Sfenner (void)printf(" SA-Response"); 6798524Sfenner TCHECK(*sp); 68127668Sbms (void)printf(" %u entries", *sp); 69127668Sbms if ((u_int)((*sp * 12) + 8) < len) { 7098524Sfenner (void)printf(" [w/data]"); 7198524Sfenner if (vflag > 1) { 7298524Sfenner (void)printf(" "); 73146773Ssam ip_print(gndo, sp + *sp * 12 + 8 - 3, 7498524Sfenner len - (*sp * 12 + 8)); 7598524Sfenner } 7698524Sfenner } 7798524Sfenner break; 7898524Sfenner case 2: 7998524Sfenner (void)printf(" SA-Request"); 8098524Sfenner TCHECK2(*sp, 5); 8198524Sfenner (void)printf(" for %s", ipaddr_string(sp + 1)); 8298524Sfenner break; 8398524Sfenner case 4: 8498524Sfenner (void)printf(" Keepalive"); 8598524Sfenner if (len != 3) 8698524Sfenner (void)printf("[len=%d] ", len); 8798524Sfenner break; 8898524Sfenner case 5: 8998524Sfenner (void)printf(" Notification"); 9098524Sfenner break; 9198524Sfenner default: 9298524Sfenner (void)printf(" [type=%d len=%d]", type, len); 9398524Sfenner break; 9498524Sfenner } 9598524Sfenner sp += (len - 3); 9698524Sfenner length -= (len - 3); 9798524Sfenner } 9898524Sfenner return; 9998524Sfennertrunc: 10098524Sfenner (void)printf(" [|msdp]"); 10198524Sfenner} 102146773Ssam 103146773Ssam/* 104146773Ssam * Local Variables: 105146773Ssam * c-style: whitesmith 106146773Ssam * c-basic-offset: 8 107146773Ssam * End: 108146773Ssam */ 109