1 //===========================================================================
2 // @(#) $Name: arts++-1-1-a13 $
3 // @(#) $Id: ArtsSelectedPortTable.cc,v 1.2 2004/04/21 23:51:35 kkeys Exp $
4 //===========================================================================
5 //  Copyright Notice
6 //
7 //  By accessing this software, arts++, you are duly informed
8 //  of and agree to be bound by the conditions described below in this
9 //  notice:
10 //
11 //  This software product, arts++, is developed by Daniel W. McRobb, and
12 //  copyrighted(C) 1998 by the University of California, San Diego
13 //  (UCSD), with all rights reserved.  UCSD administers the CAIDA grant,
14 //  NCR-9711092, under which part of this code was developed.
15 //
16 //  There is no charge for arts++ software.  You can redistribute it
17 //  and/or modify it under the terms of the GNU Lesser General Public
18 //  License, Version 2.1, February 1999, which is incorporated by
19 //  reference herein.
20 //
21 //  arts++ is distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF
22 //  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that the use
23 //  of it will not infringe on any third party's intellectual
24 //  property rights.
25 //
26 //  You should have received a copy of the GNU Lesser General Public
27 //  License along with arts++.  Copies can also be obtained from:
28 //
29 //    http://www.gnu.org/copyleft/lesser.html
30 //
31 //  or by writing to:
32 //
33 //  Free Software Foundation, Inc.
34 //  59 Temple Place, Suite 330
35 //  Boston, MA 02111-1307
36 //  USA
37 //
38 //  Or contact:
39 //
40 //    info@caida.org
41 //===========================================================================
42 
43 #include <string>
44 
45 #include "ArtsSelectedPortTable.hh"
46 
47 using namespace std;
48 
49 static const std::string rcsid = "@(#) $Name: arts++-1-1-a13 $ $Id: ArtsSelectedPortTable.cc,v 1.2 2004/04/21 23:51:35 kkeys Exp $";
50 
51 //-------------------------------------------------------------------------
52 //              ArtsSelectedPortTable::ArtsSelectedPortTable()
53 //.........................................................................
54 //
55 //-------------------------------------------------------------------------
ArtsSelectedPortTable()56 ArtsSelectedPortTable::ArtsSelectedPortTable()
57 {
58   this->Header().Identifier(artsC_OBJECT_SELECTED_PORT);
59   this->_data._selectedPortTable = new ArtsSelectedPortTableData();
60 }
61 
62 //-------------------------------------------------------------------------
63 //             ArtsSelectedPortTable::~ArtsSelectedPortTable()
64 //.........................................................................
65 //
66 //-------------------------------------------------------------------------
~ArtsSelectedPortTable()67 ArtsSelectedPortTable::~ArtsSelectedPortTable()
68 {
69 }
70 
71 //-------------------------------------------------------------------------
72 //          uint16_t ArtsSelectedPortTable::SampleInterval() const
73 //.........................................................................
74 //
75 //-------------------------------------------------------------------------
SampleInterval() const76 uint16_t ArtsSelectedPortTable::SampleInterval() const
77 {
78   return(this->_data._selectedPortTable->SampleInterval());
79 }
80 
81 //-------------------------------------------------------------------------
82 // uint16_t ArtsSelectedPortTable::SampleInterval(uint16_t sampleInterval)
83 //.........................................................................
84 //
85 //-------------------------------------------------------------------------
SampleInterval(uint16_t sampleInterval)86 uint16_t ArtsSelectedPortTable::SampleInterval(uint16_t sampleInterval)
87 {
88   return(this->_data._selectedPortTable->SampleInterval(sampleInterval));
89 }
90 
91 //-------------------------------------------------------------------------
92 //            uint64_t ArtsSelectedPortTable::TotalPkts() const
93 //.........................................................................
94 //
95 //-------------------------------------------------------------------------
TotalPkts() const96 uint64_t ArtsSelectedPortTable::TotalPkts() const
97 {
98   return(this->_data._selectedPortTable->TotalPkts());
99 }
100 
101 //-------------------------------------------------------------------------
102 //      uint64_t ArtsSelectedPortTable::TotalPkts(uint64_t totalPkts)
103 //.........................................................................
104 //
105 //-------------------------------------------------------------------------
TotalPkts(uint64_t totalPkts)106 uint64_t ArtsSelectedPortTable::TotalPkts(uint64_t totalPkts)
107 {
108   return(this->_data._selectedPortTable->TotalPkts(totalPkts));
109 }
110 
111 //-------------------------------------------------------------------------
112 //            uint64_t ArtsSelectedPortTable::TotalBytes() const
113 //.........................................................................
114 //
115 //-------------------------------------------------------------------------
TotalBytes() const116 uint64_t ArtsSelectedPortTable::TotalBytes() const
117 {
118   return(this->_data._selectedPortTable->TotalBytes());
119 }
120 
121 //-------------------------------------------------------------------------
122 //     uint64_t ArtsSelectedPortTable::TotalBytes(uint64_t totalBytes)
123 //.........................................................................
124 //
125 //-------------------------------------------------------------------------
TotalBytes(uint64_t totalBytes)126 uint64_t ArtsSelectedPortTable::TotalBytes(uint64_t totalBytes)
127 {
128   return(this->_data._selectedPortTable->TotalBytes(totalBytes));
129 }
130 
131 //-------------------------------------------------------------------------
132 //       ArtsPortChooser & ArtsSelectedPortTable::PortChooser() const
133 //.........................................................................
134 //
135 //-------------------------------------------------------------------------
PortChooser() const136 ArtsPortChooser & ArtsSelectedPortTable::PortChooser() const
137 {
138   return(this->_data._selectedPortTable->PortChooser());
139 }
140 
141 //-------------------------------------------------------------------------
142 // vector<ArtsPortTableEntry> & ArtsSelectedPortTable::PortEntries() const
143 //.........................................................................
144 //
145 //-------------------------------------------------------------------------
PortEntries() const146 vector<ArtsPortTableEntry> & ArtsSelectedPortTable::PortEntries() const
147 {
148   return(this->_data._selectedPortTable->PortEntries());
149 }
150 
151 //----------------------------------------------------------------------------
152 //        istream &
153 //        operator >> (istream & is,
154 //                     ArtsSelectedPortTable & artsSelectedPortTable)
155 //............................................................................
156 //
157 //----------------------------------------------------------------------------
158 istream &
operator >>(istream & is,ArtsSelectedPortTable & artsSelectedPortTable)159 operator >> (istream & is,
160              ArtsSelectedPortTable & artsSelectedPortTable)
161 {
162   streampos   streamPosition;
163   ArtsHeader  artsHeader;
164 
165   //  save our stream position
166   streamPosition = is.tellg();
167 
168   //  read the object header
169   artsHeader.read(is);
170   if (is.eof()) {
171     return(is);
172   }
173 
174   //  skip over objects that are not selected port table objects
175   while (artsHeader.Identifier() != artsC_OBJECT_SELECTED_PORT) {
176     is.seekg(artsHeader.AttrLength() + artsHeader.DataLength(),ios::cur);
177     streamPosition = is.tellg();
178     artsHeader.read(is);
179     if (is.eof()) {
180       break;
181     }
182   }
183 
184   //  if we reached the end of the file before finding a selected
185   //  port table object, just return the istream and don't touch
186   //  artsSelectedPortTable
187   if (is.eof()) {
188     return(is);
189   }
190 
191   //  back up to the start of the header and read the entire selected
192   //  port table object, then return the istream.
193   is.seekg(streamPosition,ios::beg);
194   artsSelectedPortTable.read(is);
195   return(is);
196 }
197 
198