|
|
|
|
79
|
|
79
|
|
80
|
## Laboratory session:
|
80
|
## Laboratory session:
|
81
|
|
81
|
|
82
|
-The application that you will complete today allows the users to analyze network traffic and to monitor the images that are being tranfered through the net.
|
|
|
|
|
82
|
+The application that you will complete today allows the users to analyze network traffic and monitor the images that are being tranfered through the net.
|
83
|
|
83
|
|
84
|
Figure 2 shows an image of the application interface. Each row in the table is the information of each captured packet. The text box under the table presents a ASCII summary of a selected packet from the table. The list in the right presents the images that have been captured by the sniffer.
|
84
|
Figure 2 shows an image of the application interface. Each row in the table is the information of each captured packet. The text box under the table presents a ASCII summary of a selected packet from the table. The list in the right presents the images that have been captured by the sniffer.
|
85
|
|
85
|
|
|
|
|
|
95
|
|
95
|
|
96
|
The task of the sniffer programmer to decode the raw stream into human readable information. Fortunately this is not your task, but you can learn how to do it, if you want, by reading the source code of this laboratory. Your task is to follow the exercises below so you provide the packet sniffer with the needed objects (Classes) to process the packets.
|
96
|
The task of the sniffer programmer to decode the raw stream into human readable information. Fortunately this is not your task, but you can learn how to do it, if you want, by reading the source code of this laboratory. Your task is to follow the exercises below so you provide the packet sniffer with the needed objects (Classes) to process the packets.
|
97
|
|
97
|
|
|
|
98
|
+
|
98
|
### Exercise 1 - Familiarize yourself with the application
|
99
|
### Exercise 1 - Familiarize yourself with the application
|
99
|
|
100
|
|
100
|
#### Instructions:
|
101
|
#### Instructions:
|
|
|
|
|
107
|
2. Configure the project. The project consists of several files. In this laboratory experience you will be working with the files `ethernet_hdr.h`, `ethernet_packet.h`, `ethernet_packet.cpp`, `ip_packet.h` and `ip_packet.cpp`.
|
108
|
2. Configure the project. The project consists of several files. In this laboratory experience you will be working with the files `ethernet_hdr.h`, `ethernet_packet.h`, `ethernet_packet.cpp`, `ip_packet.h` and `ip_packet.cpp`.
|
108
|
|
109
|
|
109
|
|
110
|
|
110
|
-### Exercise 2: Complete the class ethernet_packet
|
|
|
|
|
111
|
+### Exercise 2 - Complete the class ethernet_packet
|
111
|
|
112
|
|
112
|
-Study the file `ethernet_hdr.h`. This file contains the definition of the data structure that represents an Ethernet header.:
|
|
|
|
|
113
|
+1. Study the file `ethernet_hdr.h`. This file contains the definition of the data structure that represents an Ethernet header.:
|
113
|
|
114
|
|
114
|
-```
|
|
|
115
|
-#define ETHER_ADDR_LEN 6
|
|
|
|
|
115
|
+ ```
|
|
|
116
|
+ #define ETHER_ADDR_LEN 6
|
116
|
|
117
|
|
117
|
-struct sniff_ethernet {
|
|
|
|
|
118
|
+ struct sniff_ethernet {
|
118
|
u_char ether_dhost[ETHER_ADDR_LEN]; /* destination host address */
|
119
|
u_char ether_dhost[ETHER_ADDR_LEN]; /* destination host address */
|
119
|
u_char ether_shost[ETHER_ADDR_LEN]; /* source host address */
|
120
|
u_char ether_shost[ETHER_ADDR_LEN]; /* source host address */
|
120
|
u_short ether_type; /* IP? ARP? RARP? etc */
|
121
|
u_short ether_type; /* IP? ARP? RARP? etc */
|
121
|
-};
|
|
|
122
|
-```
|
|
|
|
|
122
|
+ };
|
|
|
123
|
+ ```
|
123
|
|
124
|
|
124
|
-The Ethernet header above is used to decode the ethernet part of the raw data in each packet. It is composed of the source MAC address (ether_shost, 6 bytes), the destiantion MAC address (ether_dhost, 6 bytes), and the type of Ethernet packet (ether_type, 2 bytes) which is used to determine if the packet is an IP packet.
|
|
|
|
|
125
|
+ The Ethernet header above is used to decode the ethernet part of the raw data in each packet. It is composed of the source MAC address (ether_shost, 6 bytes), the destiantion MAC address (ether_dhost, 6 bytes), and the type of Ethernet packet (ether_type, 2 bytes) which is used to determine if the packet is an IP packet.
|
125
|
|
126
|
|
126
|
-As you know, it is not a good idea to show this information format to a regular user. Your first task is to define the functions of the C++ class that defines the functions to translate the MAC address information into human readable strings.
|
|
|
|
|
127
|
+ As you know, it is not a good idea to show this information format to a regular user. Your first task is to define the functions of the C++ class that defines the functions to translate the MAC address information into human readable strings.
|
127
|
|
128
|
|
128
|
-The following code is the definition of the class `ethernet_packet`, that can be found in file `ethernet_packet.h`:
|
|
|
|
|
129
|
+2. The following code is the definition of the class `ethernet_packet`, that can be found in file `ethernet_packet.h`:
|
129
|
|
130
|
|
130
|
-```
|
|
|
131
|
-class ethernet_packet
|
|
|
132
|
-{
|
|
|
|
|
131
|
+ ```
|
|
|
132
|
+ class ethernet_packet
|
|
|
133
|
+ {
|
133
|
|
134
|
|
134
|
- sniff_ethernet ethernet ;
|
|
|
135
|
- // Returns a 6 bytes MAC address in string representation.
|
|
|
136
|
- string mac2string(u_char []) ;
|
|
|
|
|
135
|
+ sniff_ethernet ethernet ;
|
|
|
136
|
+ // Returns a 6 bytes MAC address in string representation.
|
|
|
137
|
+ string mac2string(u_char []) ;
|
137
|
|
138
|
|
138
|
-public:
|
|
|
139
|
- ethernet_packet(); // Default constructor
|
|
|
|
|
139
|
+ public:
|
|
|
140
|
+ ethernet_packet(); // Default constructor
|
140
|
|
141
|
|
141
|
- // Set the ethernet variable member ether_dhost to the values
|
|
|
142
|
- // received in the array
|
|
|
143
|
- void setEtherDHost(u_char []) ;
|
|
|
144
|
- // Same as above but to the ether_shost
|
|
|
145
|
- void setEtherSHost(u_char []) ;
|
|
|
|
|
142
|
+ // Set the ethernet variable member ether_dhost to the values
|
|
|
143
|
+ // received in the array
|
|
|
144
|
+ void setEtherDHost(u_char []) ;
|
|
|
145
|
+
|
|
|
146
|
+ // Same as above but to the ether_shost
|
|
|
147
|
+ void setEtherSHost(u_char []) ;
|
146
|
|
148
|
|
147
|
- // Set the ethernet type to the value received.
|
|
|
148
|
- void setEtherType(u_short) ;
|
|
|
|
|
149
|
+ // Set the ethernet type to the value received.
|
|
|
150
|
+ void setEtherType(u_short) ;
|
149
|
|
151
|
|
150
|
- // returns the string representation of the ethernet addresses
|
|
|
151
|
- string getEtherDHost() ;
|
|
|
152
|
- string getEtherSHost() ;
|
|
|
|
|
152
|
+ // returns the string representation of the ethernet addresses
|
|
|
153
|
+ string getEtherDHost() ;
|
|
|
154
|
+ string getEtherSHost() ;
|
153
|
|
155
|
|
154
|
- // Return the ethernet type
|
|
|
155
|
- u_short getEtherType() ;
|
|
|
|
|
156
|
+ // Return the ethernet type
|
|
|
157
|
+ u_short getEtherType() ;
|
156
|
|
158
|
|
157
|
-};
|
|
|
158
|
-```
|
|
|
|
|
159
|
+ };
|
|
|
160
|
+ ```
|
159
|
|
161
|
|
160
|
-Note that each object of the class `ethernet_packet` only has one attribute: a structure of type `sniff_ethernet` named `ethernet`
|
|
|
|
|
162
|
+ Note that each object of the class `ethernet_packet` only has one attribute: a structure of type `sniff_ethernet` named `ethernet`
|
161
|
|
163
|
|
162
|
-The rest are methods that act as interface to the attribute:
|
|
|
|
|
164
|
+3. The rest are methods that act as interface to the attribute:
|
163
|
|
165
|
|
164
|
* `void setEtherDHost(u_char [])`: is a *setter* to the field `ether_dhost` of the attribute `ethernet`
|
166
|
* `void setEtherDHost(u_char [])`: is a *setter* to the field `ether_dhost` of the attribute `ethernet`
|
165
|
* `void setEtherSHost(u_char [])`: is a *setter* to the field `ether_shost` of the attribute `ethernet`
|
167
|
* `void setEtherSHost(u_char [])`: is a *setter* to the field `ether_shost` of the attribute `ethernet`
|
|
|
|
|
168
|
* `getEtherType()` is a *getter* that returns the value of `ether_type` as *unsigned char*.
|
170
|
* `getEtherType()` is a *getter* that returns the value of `ether_type` as *unsigned char*.
|
169
|
* the private method `string mac2string(u_char [])` receives an array of six *unsigned characters* and returns the corresponding string to its hexadecimal representation. For example, if it receives `{ 0x8A, 0x11, 0xAB, 0xFF, 0x12, 0x34}` it must return the string `"8A:11:AB:FF:12:34"`.
|
171
|
* the private method `string mac2string(u_char [])` receives an array of six *unsigned characters* and returns the corresponding string to its hexadecimal representation. For example, if it receives `{ 0x8A, 0x11, 0xAB, 0xFF, 0x12, 0x34}` it must return the string `"8A:11:AB:FF:12:34"`.
|
170
|
|
172
|
|
171
|
-Your task in this exercise is to implement the seven functions listed above in the file `ethetnet_packet.cpp`. The headers of some of the functions are provided in the file.
|
|
|
|
|
173
|
+4. Your task in this exercise is to implement the seven functions listed above in the file `ethetnet_packet.cpp`. The headers of some of the functions are provided in the file.
|
172
|
|
174
|
|
173
|
-## Exercise 3: Construct the header of class ip_packet
|
|
|
|
|
175
|
+### Exercise 3 - Construct the header of class ip_packet
|
174
|
|
176
|
|
175
|
Study the definitions of the functions of the class `ip_packet` found in file `ip_packet.cpp`
|
177
|
Study the definitions of the functions of the class `ip_packet` found in file `ip_packet.cpp`
|
176
|
|
178
|
|
|
|
|
|
187
|
|
189
|
|
188
|
---
|
190
|
---
|
189
|
|
191
|
|
190
|
-### Deliverables
|
|
|
|
|
192
|
+## Deliverables
|
|
|
193
|
+
|
|
|
194
|
+1. Use "Deliverables" in Moodle to upload the file `ethernet_packet.cpp` and `ip_packet.h` that you defined.
|
191
|
|
195
|
|
192
|
-Use "Deliverables" in Moodle to upload the files `ethernet_packet.cpp` y `ip_packet.h` that you defined.
|
|
|
|
|
196
|
+---
|
|
|
197
|
+
|
|
|
198
|
+---
|
193
|
|
199
|
|
194
|
-### References
|
|
|
|
|
200
|
+## References
|
195
|
|
201
|
|
196
|
[1]http://en.wikipedia.org/wiki/Packet_analyzer
|
202
|
[1]http://en.wikipedia.org/wiki/Packet_analyzer
|