1 /* Copyright (C) 1999, 2000, 2001, 2002, 2003 Simon Patarin, INRIA
3 This file is part of Pandora, the Flexible Monitoring Platform.
5 Pandora is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 Pandora is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with Pandora; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA. */
21 #include <libpandora/global.h>
23 #include "tcpprintcomponent.h"
24 #include <pandora_components/ippacket.h>
25 #include <pandora_components/tcppacket.h>
26 #include <pandora_components/udppacket.h>
28 component_export(TCPPrintComponent
, TCPPacket
+|UDPPacket
+,);
30 int TCPPrintComponent::id
= 0;
32 bool TCPPrintComponent::add(Packet
*pkt
)
34 int sport
= 0, dport
= 0;
36 locatePacket0(TCPPacket
, tcpp
, pkt
);
37 locatePacket0(UDPPacket
, udpp
, pkt
);
42 } else if (udpp
!= NULL
) {
47 locatePacket(IPPacket
, ipp
, pkt
);
54 int len
= ipp
->dlength();
61 cout
<< "new_packet ";
63 char *data
= ipp
->data();
65 cout
<< "TCP " << cnx
;
67 cout
<< "UDP " << cnx
;
70 cout
<< " \"" << ipp
->src
<< "\" " << ntohs(sport
) << " \""
71 << ipp
->dst
<< "\" " << ntohs(dport
) << "\n";
74 for (int i
= 0; i
< len
; ++i
) {
75 int c
= (int) (unsigned char)data
[i
];
76 if (c
== '\\') cout
<< "\\\\";
78 if (c
== '"') cout
<< "\\\"";
80 if (c
== '\n' || (c
> 31 && c
< 127))
87 cout
<< "\n(*----------------------------------------------------------------------*)\n";