INET Framework for OMNeT++/OMNEST
inet::PacketDump Class Reference

Utility class that provides tcpdump-like functionality. More...

#include <PacketDump.h>

Public Member Functions

 PacketDump ()
 Constructor. More...
 
 ~PacketDump ()
 Destructor. More...
 
void setOutStream (std::ostream &o)
 Sets the output stream. More...
 
std::ostream & getOutStream () const
 Returns the output stream. More...
 
void setVerbose (bool verb)
 Enable/disable verbose output. More...
 
bool isVerbose () const
 Returns the verbosity flag. More...
 
void dump (const char *label, const char *msg)
 Writes the given text on the output stream. More...
 
void dumpPacket (bool l2r, cPacket *packet)
 Dumps info about the given packet. More...
 
void dumpIPv4 (bool l2r, const char *label, IPv4Datagram *dgram, const char *comment=nullptr)
 Dumps info about the given IPv4 datagram. More...
 
void dumpARP (bool l2r, const char *label, ARPPacket *dgram, const char *comment=nullptr)
 
void dumpIPv6 (bool l2r, const char *label, IPv6Datagram *dgram, const char *comment=nullptr)
 Dumps info about the given IPv6 datagram. More...
 
void sctpDump (const char *label, sctp::SCTPMessage *sctpmsg, const std::string &srcAddr, const std::string &destAddr, const char *comment=nullptr)
 Dumps info about the given SCTP message. More...
 
void tcpDump (bool l2r, const char *label, tcp::TCPSegment *tcpseg, const std::string &srcAddr, const std::string &destAddr, const char *comment=nullptr)
 Dumps info about the given TCP segment. More...
 
void udpDump (bool l2r, const char *label, UDPPacket *udppkt, const std::string &srcAddr, const std::string &destAddr, const char *comment)
 Dumps info about the given UDP packet. More...
 

Protected Attributes

bool verbose
 
std::ostream * outp
 

Detailed Description

Utility class that provides tcpdump-like functionality.

It prints information about each packet on the given output stream.

Constructor & Destructor Documentation

inet::PacketDump::PacketDump ( )

Constructor.

The output stream initially points to the C++ standard output (std::cout); you probably want to call setOutStream(getEnvir()->getOStream()) to redirect it to EV.

52 {
53  outp = &std::cout;
54  verbose = false;
55 }
bool verbose
Definition: PacketDump.h:43
std::ostream * outp
Definition: PacketDump.h:44
inet::PacketDump::~PacketDump ( )

Destructor.

It does not close the output stream.

58 {
59 }

Member Function Documentation

void inet::PacketDump::dump ( const char *  label,
const char *  msg 
)

Writes the given text on the output stream.

Referenced by inet::TCPDump::finish(), and inet::PcapRecorder::finish().

356 {
357  std::ostream& out = *outp;
358 
359  // seq and time (not part of the tcpdump format)
360  char buf[30];
361 
362  sprintf(buf, "[%.3f%s] ", simTime().dbl(), label);
363  out << buf << msg << endl;
364 }
std::ostream * outp
Definition: PacketDump.h:44
void inet::PacketDump::dumpARP ( bool  l2r,
const char *  label,
ARPPacket dgram,
const char *  comment = nullptr 
)

Referenced by dumpPacket().

475 {
476 #ifdef WITH_IPv4
477  std::ostream& out = *outp;
478  char buf[30];
479  sprintf(buf, "[%.3f%s] ", simTime().dbl(), label);
480  out << buf << " src: " << dgram->getSrcIPAddress() << ", " << dgram->getSrcMACAddress()
481  << "; dest: " << dgram->getDestIPAddress() << ", " << dgram->getDestMACAddress() << endl;
482 #endif // ifdef WITH_IPv4
483 }
std::ostream * outp
Definition: PacketDump.h:44
void inet::PacketDump::dumpIPv4 ( bool  l2r,
const char *  label,
IPv4Datagram dgram,
const char *  comment = nullptr 
)

Dumps info about the given IPv4 datagram.

The l2r parameter denotes the direction of the packet.

Referenced by dumpPacket().

486 {
487  std::ostream& out = *outp;
488  char buf[30];
489  std::string classes;
490 
491 #ifdef WITH_IPv4
492  cPacket *encapmsg = dgram->getEncapsulatedPacket();
493 
494 #ifdef WITH_TCP_COMMON
495  if (dynamic_cast<tcp::TCPSegment *>(encapmsg)) {
496  // if TCP, dump as TCP
497  tcpDump(l2r, label, static_cast<tcp::TCPSegment *>(encapmsg), dgram->getSrcAddress().str(),
498  dgram->getDestAddress().str(), comment);
499  }
500  else
501 #endif // ifdef WITH_TCP_COMMON
502 #ifdef WITH_UDP
503  if (dynamic_cast<UDPPacket *>(encapmsg)) {
504  udpDump(l2r, label, (UDPPacket *)encapmsg, dgram->getSrcAddress().str(),
505  dgram->getDestAddress().str(), comment);
506  }
507  else
508 #endif // ifdef WITH_UDP
509 #ifdef WITH_SCTP
510  if (dynamic_cast<sctp::SCTPMessage *>(dgram->getEncapsulatedPacket())) {
511  sctp::SCTPMessage *sctpmsg = check_and_cast<sctp::SCTPMessage *>(dgram->getEncapsulatedPacket());
512  if (dgram->hasBitError())
513  sctpmsg->setBitError(true);
514  sctpDump(label, sctpmsg, dgram->getSrcAddress().str(), dgram->getDestAddress().str(), comment);
515  }
516  else
517 #endif // ifdef WITH_SCTP
518  {
519  // some other packet, dump what we can
520  // seq and time (not part of the tcpdump format)
521  sprintf(buf, "[%.3f%s] ", SIMTIME_DBL(simTime()), label);
522  out << buf;
523  out << "[IPv4] " << dgram->getSrcAddress() << " > " << dgram->getDestAddress();
524 
525  if (dgram->getMoreFragments() || dgram->getFragmentOffset())
526  out << ((dgram->getMoreFragments()) ? " inner" : " last") << " fragment from offset " << dgram->getFragmentOffset();
527 
528  if (encapmsg) {
529  // packet class and name
530  out << " ? " << encapmsg->getClassName() << " \"" << encapmsg->getName() << "\"";
531  }
532 
533  // comment
534  if (comment)
535  out << " # " << comment;
536 
537  out << endl;
538  }
539 #else // ifdef WITH_IPv4
540  sprintf(buf, "[%.3f%s] ", SIMTIME_DBL(simTime()), label);
541  out << buf << "[IPv4]";
542 
543  // comment
544  if (comment)
545  out << " # " << comment;
546 
547  out << endl;
548 #endif // ifdef WITH_IPv4
549 }
void sctpDump(const char *label, sctp::SCTPMessage *sctpmsg, const std::string &srcAddr, const std::string &destAddr, const char *comment=nullptr)
Dumps info about the given SCTP message.
Definition: PacketDump.cc:61
void tcpDump(bool l2r, const char *label, tcp::TCPSegment *tcpseg, const std::string &srcAddr, const std::string &destAddr, const char *comment=nullptr)
Dumps info about the given TCP segment.
Definition: PacketDump.cc:596
std::ostream * outp
Definition: PacketDump.h:44
void udpDump(bool l2r, const char *label, UDPPacket *udppkt, const std::string &srcAddr, const std::string &destAddr, const char *comment)
Dumps info about the given UDP packet.
Definition: PacketDump.cc:429
void inet::PacketDump::dumpIPv6 ( bool  l2r,
const char *  label,
IPv6Datagram dgram,
const char *  comment = nullptr 
)

Dumps info about the given IPv6 datagram.

The l2r parameter denotes the direction of the packet.

Referenced by dumpPacket().

552 {
553  using namespace tcp;
554 
555  std::ostream& out = *outp;
556  char buf[30];
557 
558 #ifdef WITH_IPv6
559  cPacket *encapmsg = dgram->getEncapsulatedPacket();
560 
561 #ifdef WITH_TCP_COMMON
562  if (dynamic_cast<TCPSegment *>(encapmsg)) {
563  // if TCP, dump as TCP
564  tcpDump(l2r, label, (TCPSegment *)encapmsg, dgram->getSrcAddress().str(),
565  dgram->getDestAddress().str(), comment);
566  }
567  else
568 #endif // ifdef WITH_TCP_COMMON
569  {
570  // some other packet, dump what we can
571  // seq and time (not part of the tcpdump format)
572  sprintf(buf, "[%.3f%s] ", SIMTIME_DBL(simTime()), label);
573  out << buf;
574 
575  // packet class and name
576  out << "? " << encapmsg->getClassName() << " \"" << encapmsg->getName() << "\"\n";
577 
578  // comment
579  if (comment)
580  out << "# " << comment;
581 
582  out << endl;
583  }
584 #else // ifdef WITH_IPv6
585  sprintf(buf, "[%.3f%s] ", SIMTIME_DBL(simTime()), label);
586  out << buf << "[IPv4]";
587 
588  // comment
589  if (comment)
590  out << " # " << comment;
591 
592  out << endl;
593 #endif // ifdef WITH_IPv6
594 }
void tcpDump(bool l2r, const char *label, tcp::TCPSegment *tcpseg, const std::string &srcAddr, const std::string &destAddr, const char *comment=nullptr)
Dumps info about the given TCP segment.
Definition: PacketDump.cc:596
std::ostream * outp
Definition: PacketDump.h:44
void inet::PacketDump::dumpPacket ( bool  l2r,
cPacket *  packet 
)

Dumps info about the given packet.

It dispatches to the more specific dump functions. The l2r parameter denotes the direction of the packet.

Referenced by inet::TCPDump::handleMessage(), and inet::PcapRecorder::recordPacket().

367 {
368  std::ostream& out = *outp;
369 
370 #ifdef WITH_IPv4
371  if (dynamic_cast<IPv4Datagram *>(msg)) {
372  dumpIPv4(l2r, "", (IPv4Datagram *)msg, "");
373  }
374  else if (dynamic_cast<ARPPacket *>(msg)) {
375  dumpARP(l2r, "", (ARPPacket *)msg, "");
376  }
377  else
378 #endif // ifdef WITH_IPv4
379 #ifdef WITH_SCTP
380  if (dynamic_cast<sctp::SCTPMessage *>(msg)) {
381  sctpDump("", (sctp::SCTPMessage *)msg, std::string(l2r ? "A" : "B"), std::string(l2r ? "B" : "A"));
382  }
383  else
384 #endif // ifdef WITH_SCTP
385 #ifdef WITH_TCP_COMMON
386  if (dynamic_cast<tcp::TCPSegment *>(msg)) {
387  tcpDump(l2r, "", static_cast<tcp::TCPSegment *>(msg), std::string(l2r ? "A" : "B"), std::string(l2r ? "B" : "A"));
388  }
389  else
390 #endif // ifdef WITH_TCP_COMMON
391 #ifdef WITH_IPv4
392  if (dynamic_cast<ICMPMessage *>(msg)) {
393  out << "ICMPMessage " << msg->getName() << (msg->hasBitError() ? " (BitError)" : "") << endl;
394  }
395  else
396 #endif // ifdef WITH_IPv4
397  {
398  // search for encapsulated IPv4[v6]Datagram in it
399  while (msg) {
400 #ifdef WITH_IPv4
401  if (dynamic_cast<IPv4Datagram *>(msg)) {
402  dumpIPv4(l2r, "", (IPv4Datagram *)msg);
403  break;
404  }
405  else if (dynamic_cast<ARPPacket *>(msg)) {
406  dumpARP(l2r, "", (ARPPacket *)msg, "");
407  break;
408  }
409 #endif // ifdef WITH_IPv4
410 #ifdef WITH_IPv6
411  if (dynamic_cast<IPv6Datagram *>(msg)) {
412  dumpIPv6(l2r, "", (IPv6Datagram *)msg);
413  break;
414  }
415 #endif // ifdef WITH_IPv6
416  out << "Packet " << msg->getClassName() << " '" << msg->getName() << "'"
417  << (msg->hasBitError() ? " (BitError)" : "") << ": ";
418  msg = msg->getEncapsulatedPacket();
419  }
420 
421  if (!msg) {
422  //We do not want this to end in an error if EtherAutoconf messages
423  //are passed, so just print a warning. -WEI
424  out << "CANNOT DECODE, packet doesn't contain either IPv4 or IPv6 Datagram\n";
425  }
426  }
427 }
void dumpIPv6(bool l2r, const char *label, IPv6Datagram *dgram, const char *comment=nullptr)
Dumps info about the given IPv6 datagram.
Definition: PacketDump.cc:551
void sctpDump(const char *label, sctp::SCTPMessage *sctpmsg, const std::string &srcAddr, const std::string &destAddr, const char *comment=nullptr)
Dumps info about the given SCTP message.
Definition: PacketDump.cc:61
void dumpARP(bool l2r, const char *label, ARPPacket *dgram, const char *comment=nullptr)
Definition: PacketDump.cc:474
void tcpDump(bool l2r, const char *label, tcp::TCPSegment *tcpseg, const std::string &srcAddr, const std::string &destAddr, const char *comment=nullptr)
Dumps info about the given TCP segment.
Definition: PacketDump.cc:596
std::ostream * outp
Definition: PacketDump.h:44
void dumpIPv4(bool l2r, const char *label, IPv4Datagram *dgram, const char *comment=nullptr)
Dumps info about the given IPv4 datagram.
Definition: PacketDump.cc:485
std::ostream& inet::PacketDump::getOutStream ( ) const
inline

Returns the output stream.

67 { return *outp; }
std::ostream * outp
Definition: PacketDump.h:44
bool inet::PacketDump::isVerbose ( ) const
inline

Returns the verbosity flag.

77 { return verbose; }
bool verbose
Definition: PacketDump.h:43
void inet::PacketDump::sctpDump ( const char *  label,
sctp::SCTPMessage sctpmsg,
const std::string &  srcAddr,
const std::string &  destAddr,
const char *  comment = nullptr 
)

Dumps info about the given SCTP message.

Referenced by dumpIPv4(), dumpPacket(), and udpDump().

63 {
64  using namespace sctp;
65 
66  std::ostream& out = *outp;
67 
68  // seq and time (not part of the tcpdump format)
69  char buf[30];
70  sprintf(buf, "[%.3f%s] ", simTime().dbl(), label);
71  out << buf;
72 
73 #ifndef WITH_SCTP
74  out << "[sctp] " << srcAddr << " > " << destAddr;
75 #else // ifndef WITH_SCTP
76  uint32 numberOfChunks;
77  SCTPChunk *chunk;
78  uint8 type;
79  // src/dest
80  out << srcAddr << "." << sctpmsg->getSrcPort() << " > "
81  << destAddr << "." << sctpmsg->getDestPort() << ": ";
82 
83  if (sctpmsg->hasBitError()) {
84  sctpmsg->setChecksumOk(false);
85  }
86 
87  numberOfChunks = sctpmsg->getChunksArraySize();
88  out << "numberOfChunks=" << numberOfChunks << " VTag=" << sctpmsg->getTag() << "\n";
89 
90  if (sctpmsg->hasBitError())
91  out << "Packet has bit error!!\n";
92 
93  for (uint32 i = 0; i < numberOfChunks; i++) {
94  chunk = (SCTPChunk *)sctpmsg->getChunks(i);
95  type = chunk->getChunkType();
96 
97  // FIXME create a getChunkTypeName(SCTPChunkType x) function in SCTP code and use it!
98  switch (type) {
99  case INIT:
100  out << "INIT ";
101  break;
102 
103  case INIT_ACK:
104  out << "INIT_ACK ";
105  break;
106 
107  case COOKIE_ECHO:
108  out << "COOKIE_ECHO ";
109  break;
110 
111  case COOKIE_ACK:
112  out << "COOKIE_ACK ";
113  break;
114 
115  case DATA:
116  out << "DATA ";
117  break;
118 
119  case SACK:
120  out << "SACK ";
121  break;
122 
123  case HEARTBEAT:
124  out << "HEARTBEAT ";
125  break;
126 
127  case HEARTBEAT_ACK:
128  out << "HEARTBEAT_ACK ";
129  break;
130 
131  case ABORT:
132  out << "ABORT ";
133  break;
134 
135  case SHUTDOWN:
136  out << "SHUTDOWN ";
137  break;
138 
139  case SHUTDOWN_ACK:
140  out << "SHUTDOWN_ACK ";
141  break;
142 
143  case SHUTDOWN_COMPLETE:
144  out << "SHUTDOWN_COMPLETE ";
145  break;
146 
147  case ERRORTYPE:
148  out << "ERROR";
149  break;
150  }
151  }
152 
153  if (verbose) {
154  out << endl;
155 
156  for (uint32 i = 0; i < numberOfChunks; i++) {
157  chunk = (SCTPChunk *)sctpmsg->getChunks(i);
158  type = chunk->getChunkType();
159 
160  sprintf(buf, " %3u: ", i + 1);
161  out << buf;
162 
163  switch (type) {
164  case INIT: {
165  SCTPInitChunk *initChunk;
166  initChunk = check_and_cast<SCTPInitChunk *>(chunk);
167  out << "INIT[InitiateTag=";
168  out << initChunk->getInitTag();
169  out << "; a_rwnd=";
170  out << initChunk->getA_rwnd();
171  out << "; OS=";
172  out << initChunk->getNoOutStreams();
173  out << "; IS=";
174  out << initChunk->getNoInStreams();
175  out << "; InitialTSN=";
176  out << initChunk->getInitTSN();
177 
178  if (initChunk->getAddressesArraySize() > 0) {
179  out << "; Addresses=";
180 
181  for (uint32 i = 0; i < initChunk->getAddressesArraySize(); i++) {
182  if (i > 0)
183  out << ",";
184 
185  if (initChunk->getAddresses(i).getType() == L3Address::IPv6)
186  out << initChunk->getAddresses(i).str();
187  else
188  out << initChunk->getAddresses(i);
189  }
190  }
191 
192  out << "]";
193  break;
194  }
195 
196  case INIT_ACK: {
197  SCTPInitAckChunk *initackChunk;
198  initackChunk = check_and_cast<SCTPInitAckChunk *>(chunk);
199  out << "INIT_ACK[InitiateTag=";
200  out << initackChunk->getInitTag();
201  out << "; a_rwnd=";
202  out << initackChunk->getA_rwnd();
203  out << "; OS=";
204  out << initackChunk->getNoOutStreams();
205  out << "; IS=";
206  out << initackChunk->getNoInStreams();
207  out << "; InitialTSN=";
208  out << initackChunk->getInitTSN();
209  out << "; CookieLength=";
210  out << initackChunk->getCookieArraySize();
211 
212  if (initackChunk->getAddressesArraySize() > 0) {
213  out << "; Addresses=";
214 
215  for (uint32 i = 0; i < initackChunk->getAddressesArraySize(); i++) {
216  if (i > 0)
217  out << ",";
218 
219  out << initackChunk->getAddresses(i);
220  }
221  }
222 
223  out << "]";
224  break;
225  }
226 
227  case COOKIE_ECHO:
228  out << "COOKIE_ECHO[CookieLength=";
229  out << chunk->getBitLength() / 8 - 4;
230  out << "]";
231  break;
232 
233  case COOKIE_ACK:
234  out << "COOKIE_ACK ";
235  break;
236 
237  case DATA: {
238  SCTPDataChunk *dataChunk;
239  dataChunk = check_and_cast<SCTPDataChunk *>(chunk);
240  out << "DATA[TSN=";
241  out << dataChunk->getTsn();
242  out << "; SID=";
243  out << dataChunk->getSid();
244  out << "; SSN=";
245  out << dataChunk->getSsn();
246  out << "; PPID=";
247  out << dataChunk->getPpid();
248  out << "; PayloadLength=";
249  out << dataChunk->getBitLength() / 8 - 16;
250  out << "]";
251  break;
252  }
253 
254  case SACK: {
255  SCTPSackChunk *sackChunk;
256  sackChunk = check_and_cast<SCTPSackChunk *>(chunk);
257  out << "SACK[CumTSNAck=";
258  out << sackChunk->getCumTsnAck();
259  out << "; a_rwnd=";
260  out << sackChunk->getA_rwnd();
261 
262  if (sackChunk->getGapStartArraySize() > 0) {
263  out << "; Gaps=";
264 
265  for (uint32 i = 0; i < sackChunk->getGapStartArraySize(); i++) {
266  if (i > 0)
267  out << ", ";
268 
269  out << sackChunk->getGapStart(i) << "-" << sackChunk->getGapStop(i);
270  }
271  }
272 
273  if (sackChunk->getDupTsnsArraySize() > 0) {
274  out << "; Dups=";
275 
276  for (uint32 i = 0; i < sackChunk->getDupTsnsArraySize(); i++) {
277  if (i > 0)
278  out << ", ";
279 
280  out << sackChunk->getDupTsns(i);
281  }
282  }
283 
284  out << "]";
285  break;
286  }
287 
288  case HEARTBEAT:
289  SCTPHeartbeatChunk *heartbeatChunk;
290  heartbeatChunk = check_and_cast<SCTPHeartbeatChunk *>(chunk);
291  out << "HEARTBEAT[InfoLength=";
292  out << chunk->getBitLength() / 8 - 4;
293  out << "; time=";
294  out << heartbeatChunk->getTimeField();
295  out << "]";
296  break;
297 
298  case HEARTBEAT_ACK:
299  out << "HEARTBEAT_ACK[InfoLength=";
300  out << chunk->getBitLength() / 8 - 4;
301  out << "]";
302  break;
303 
304  case ABORT:
305  SCTPAbortChunk *abortChunk;
306  abortChunk = check_and_cast<SCTPAbortChunk *>(chunk);
307  out << "ABORT[T-Bit=";
308  out << abortChunk->getT_Bit();
309  out << "]";
310  break;
311 
312  case SHUTDOWN:
313  SCTPShutdownChunk *shutdown;
314  shutdown = check_and_cast<SCTPShutdownChunk *>(chunk);
315  out << "SHUTDOWN[CumTSNAck=";
316  out << shutdown->getCumTsnAck();
317  out << "]";
318  break;
319 
320  case SHUTDOWN_ACK:
321  out << "SHUTDOWN_ACK ";
322  break;
323 
324  case SHUTDOWN_COMPLETE:
325  out << "SHUTDOWN_COMPLETE ";
326  break;
327 
328  case ERRORTYPE: {
329  out << "ERRORTYPE ";
330  SCTPErrorChunk *errorChunk;
331  errorChunk = check_and_cast<SCTPErrorChunk *>(chunk);
332  uint32 numberOfParameters = errorChunk->getParametersArraySize();
333  uint32 parameterType;
334 
335  for (uint32 i = 0; i < numberOfParameters; i++) {
336  SCTPParameter *param = (SCTPParameter *)errorChunk->getParameters(i);
337  parameterType = param->getParameterType();
338  out << parameterType << " ";
339  }
340  break;
341  }
342  }
343  out << endl;
344  }
345  }
346 #endif // ifndef WITH_SCTP
347 
348  // comment
349  if (comment)
350  out << "# " << comment;
351 
352  out << endl;
353 }
uint8_t uint8
Definition: Compat.h:34
Definition: SCTPAssociation.h:111
Definition: L3Address.h:47
Definition: SCTPAssociation.h:118
Definition: SCTPAssociation.h:119
Definition: SCTPAssociation.h:121
Definition: SCTPAssociation.h:122
Definition: SCTPAssociation.h:115
Definition: SCTPAssociation.h:116
Definition: SCTPAssociation.h:112
bool verbose
Definition: PacketDump.h:43
uint32_t uint32
Definition: Compat.h:30
Definition: SCTPAssociation.h:114
Definition: SCTPAssociation.h:120
Definition: SCTPAssociation.h:117
std::ostream * outp
Definition: PacketDump.h:44
Definition: SCTPAssociation.h:113
Definition: SCTPAssociation.h:123
void inet::PacketDump::setOutStream ( std::ostream &  o)
inline

Sets the output stream.

Referenced by inet::TCPDump::initialize(), and inet::PcapRecorder::initialize().

62 { outp = &o; }
std::ostream * outp
Definition: PacketDump.h:44
void inet::PacketDump::setVerbose ( bool  verb)
inline

Enable/disable verbose output.

Referenced by inet::TCPDump::initialize(), and inet::PcapRecorder::initialize().

72 { verbose = verb; }
bool verbose
Definition: PacketDump.h:43
void inet::PacketDump::tcpDump ( bool  l2r,
const char *  label,
tcp::TCPSegment tcpseg,
const std::string &  srcAddr,
const std::string &  destAddr,
const char *  comment = nullptr 
)

Dumps info about the given TCP segment.

Referenced by dumpIPv4(), dumpIPv6(), and dumpPacket().

598 {
599  using namespace tcp;
600 
601  std::ostream& out = *outp;
602 
603  // seq and time (not part of the tcpdump format)
604  char buf[30];
605  sprintf(buf, "[%.3f%s] ", SIMTIME_DBL(simTime()), label);
606  out << buf;
607 
608 #ifndef WITH_TCP_COMMON
609  if (l2r)
610  out << srcAddr << " > " << destAddr << ": ";
611  else
612  out << destAddr << " < " << srcAddr << ": ";
613 #else // ifndef WITH_TCP_COMMON
614  // src/dest ports
615  if (l2r) {
616  out << srcAddr << "." << tcpseg->getSrcPort() << " > ";
617  out << destAddr << "." << tcpseg->getDestPort() << ": ";
618  }
619  else {
620  out << destAddr << "." << tcpseg->getDestPort() << " < ";
621  out << srcAddr << "." << tcpseg->getSrcPort() << ": ";
622  }
623 
624  // flags
625  bool flags = false;
626  if (tcpseg->getUrgBit()) {
627  flags = true;
628  out << "U ";
629  }
630  if (tcpseg->getAckBit()) {
631  flags = true;
632  out << "A ";
633  }
634  if (tcpseg->getPshBit()) {
635  flags = true;
636  out << "P ";
637  }
638  if (tcpseg->getRstBit()) {
639  flags = true;
640  out << "R ";
641  }
642  if (tcpseg->getSynBit()) {
643  flags = true;
644  out << "S ";
645  }
646  if (tcpseg->getFinBit()) {
647  flags = true;
648  out << "F ";
649  }
650  if (!flags) {
651  out << ". ";
652  }
653 
654  // data-seqno
655  if (tcpseg->getPayloadLength() > 0 || tcpseg->getSynBit()) {
656  out << tcpseg->getSequenceNo() << ":" << tcpseg->getSequenceNo() + tcpseg->getPayloadLength();
657  out << "(" << tcpseg->getPayloadLength() << ") ";
658  }
659 
660  // ack
661  if (tcpseg->getAckBit())
662  out << "ack " << tcpseg->getAckNo() << " ";
663 
664  // window
665  out << "win " << tcpseg->getWindow() << " ";
666 
667  // urgent
668  if (tcpseg->getUrgBit())
669  out << "urg " << tcpseg->getUrgentPointer() << " ";
670 
671  // options present?
672  if (tcpseg->getHeaderLength() > 20) {
673  const char *direction = l2r ? "sent" : "received";
674 
675  if (verbose) {
676  unsigned short numOptions = tcpseg->getHeaderOptionArraySize();
677  out << "\n TCP Header Option(s) " << direction << ":\n";
678 
679  for (int i = 0; i < numOptions; i++) {
680  TCPOption *option = tcpseg->getHeaderOption(i);
681  out << " " << (i + 1) << ". option kind=" << option->getKind() << " length=" << option->getLength() << "\n";
682  }
683  }
684  }
685 #endif // ifndef WITH_TCP_COMMON
686 
687  // comment
688  if (comment)
689  out << "# " << comment;
690 
691  out << endl;
692 }
bool verbose
Definition: PacketDump.h:43
std::ostream * outp
Definition: PacketDump.h:44
void inet::PacketDump::udpDump ( bool  l2r,
const char *  label,
UDPPacket udppkt,
const std::string &  srcAddr,
const std::string &  destAddr,
const char *  comment 
)

Dumps info about the given UDP packet.

Referenced by dumpIPv4().

431 {
432  std::ostream& out = *outp;
433 
434  char buf[30];
435  sprintf(buf, "[%.3f%s] ", simTime().dbl(), label);
436  out << buf;
437 
438 #ifndef WITH_UDP
439  if (l2r)
440  out << "[UDP] " << srcAddr << " > " << destAddr << ": ";
441  else
442  out << "[UDP] " << destAddr << " < " << srcAddr << ": ";
443 #else // ifndef WITH_UDP
444  // seq and time (not part of the tcpdump format)
445  // src/dest
446  if (l2r) {
447  out << srcAddr << "." << udppkt->getSourcePort() << " > ";
448  out << destAddr << "." << udppkt->getDestinationPort() << ": ";
449  }
450  else {
451  out << destAddr << "." << udppkt->getDestinationPort() << " < ";
452  out << srcAddr << "." << udppkt->getSourcePort() << ": ";
453  }
454 
455  //out << endl;
456  out << "UDP: Payload length=" << udppkt->getByteLength() - 8 << endl;
457 
458 #ifdef WITH_SCTP
459  if (udppkt->getSourcePort() == 9899 || udppkt->getDestinationPort() == 9899) {
460  if (dynamic_cast<sctp::SCTPMessage *>(udppkt->getEncapsulatedPacket()))
461  sctpDump("", (sctp::SCTPMessage *)(udppkt->getEncapsulatedPacket()),
462  std::string(l2r ? "A" : "B"), std::string(l2r ? "B" : "A"));
463  }
464 #endif // ifdef WITH_SCTP
465 #endif // ifndef WITH_UDP
466 
467  // comment
468  if (comment)
469  out << "# " << comment;
470 
471  out << endl;
472 }
void sctpDump(const char *label, sctp::SCTPMessage *sctpmsg, const std::string &srcAddr, const std::string &destAddr, const char *comment=nullptr)
Dumps info about the given SCTP message.
Definition: PacketDump.cc:61
std::ostream * outp
Definition: PacketDump.h:44

Member Data Documentation

std::ostream* inet::PacketDump::outp
protected
bool inet::PacketDump::verbose
protected

Referenced by PacketDump(), sctpDump(), and tcpDump().


The documentation for this class was generated from the following files: