|
@@ -112,31 +112,31 @@ The task of the sniffer programmer to decode the raw stream into human readable
|
112
|
112
|
|
113
|
113
|
1. Study the file `ethernet_hdr.h`. This file contains the definition of the data structure that represents an Ethernet header.:
|
114
|
114
|
|
115
|
|
- ```
|
116
|
|
- #define ETHER_ADDR_LEN 6
|
|
115
|
+ ```
|
|
116
|
+ #define ETHER_ADDR_LEN 6
|
117
|
117
|
|
118
|
|
- struct sniff_ethernet {
|
|
118
|
+ struct sniff_ethernet {
|
119
|
119
|
u_char ether_dhost[ETHER_ADDR_LEN]; /* destination host address */
|
120
|
120
|
u_char ether_shost[ETHER_ADDR_LEN]; /* source host address */
|
121
|
121
|
u_short ether_type; /* IP? ARP? RARP? etc */
|
122
|
|
- };
|
123
|
|
- ```
|
|
122
|
+ };
|
|
123
|
+ ```
|
124
|
124
|
|
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
|
+ 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.
|
126
|
126
|
|
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
|
+ 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.
|
128
|
128
|
|
129
|
129
|
2. The following code is the definition of the class `ethernet_packet`, that can be found in file `ethernet_packet.h`:
|
130
|
|
-
|
131
|
|
- ```
|
132
|
|
- class ethernet_packet
|
133
|
|
- {
|
|
130
|
+
|
|
131
|
+ ```
|
|
132
|
+ class ethernet_packet
|
|
133
|
+ {
|
134
|
134
|
|
135
|
135
|
sniff_ethernet ethernet ;
|
136
|
136
|
// Returns a 6 bytes MAC address in string representation.
|
137
|
137
|
string mac2string(u_char []) ;
|
138
|
138
|
|
139
|
|
- public:
|
|
139
|
+ public:
|
140
|
140
|
ethernet_packet(); // Default constructor
|
141
|
141
|
|
142
|
142
|
// Set the ethernet variable member ether_dhost to the values
|
|
@@ -156,10 +156,10 @@ The task of the sniffer programmer to decode the raw stream into human readable
|
156
|
156
|
// Return the ethernet type
|
157
|
157
|
u_short getEtherType() ;
|
158
|
158
|
|
159
|
|
- };
|
160
|
|
- ```
|
|
159
|
+ };
|
|
160
|
+ ```
|
161
|
161
|
|
162
|
|
- 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`
|
163
|
163
|
|
164
|
164
|
3. The rest are methods that act as interface to the attribute:
|
165
|
165
|
|
|
@@ -174,16 +174,16 @@ The task of the sniffer programmer to decode the raw stream into human readable
|
174
|
174
|
|
175
|
175
|
### Exercise 3 - Construct the header of class ip_packet
|
176
|
176
|
|
177
|
|
-Study the definitions of the functions of the class `ip_packet` found in file `ip_packet.cpp`
|
|
177
|
+1. Study the definitions of the functions of the class `ip_packet` found in file `ip_packet.cpp`
|
178
|
178
|
|
179
|
|
-Your task is to create the *declaration* of the class `ip_packet` in the file `ip_packet.cpp`. The attributes of the class `ip_packet` must be:
|
|
179
|
+2. Your task is to create the *declaration* of the class `ip_packet` in the file `ip_packet.cpp`. The attributes of the class `ip_packet` must be:
|
180
|
180
|
|
181
|
|
-* two objects of the class `string`s to store the source and destination IP addresses
|
182
|
|
-* one variable of one byte (`char`) variable to store the IP protocol
|
183
|
|
-* two variables `unsigned short` to store the source and destination port
|
184
|
|
-* one object of the class `string` to store the packet payload.
|
|
181
|
+ * two objects of the class `string`s to store the source and destination IP addresses
|
|
182
|
+ * one variable of one byte (`char`) variable to store the IP protocol
|
|
183
|
+ * two variables `unsigned short` to store the source and destination port
|
|
184
|
+ * one object of the class `string` to store the packet payload.
|
185
|
185
|
|
186
|
|
-In the declaration of the class `ip_packet` you must especify that it is a **derived class** (inherits) of the class `ethernet_packet`.
|
|
186
|
+ In the declaration of the class `ip_packet` you must especify that it is a **derived class** (inherits) of the class `ethernet_packet`.
|
187
|
187
|
|
188
|
188
|
---
|
189
|
189
|
|