|
|
|
|
6
|
|
6
|
|
7
|
*Object Oriented Programming* (OOP) is a programming paradigm that promotes the design of programs by having different objects interacting together to solve a problem. C++ is one of the programming languages that promotes object oriented programming, allowing programmers to create their own classes from scratch or derive them from other existing classes. Other languages that promote OOP are Java, Python, JavaScript and PHP.
|
7
|
*Object Oriented Programming* (OOP) is a programming paradigm that promotes the design of programs by having different objects interacting together to solve a problem. C++ is one of the programming languages that promotes object oriented programming, allowing programmers to create their own classes from scratch or derive them from other existing classes. Other languages that promote OOP are Java, Python, JavaScript and PHP.
|
8
|
|
8
|
|
9
|
-In OOP, each object encapsulates within itself certain properties about the entity being modeled. For example, an object that models a *point* encapsulates the coordinates *x* and *y* of the point being represented. Furthermore, each object allows certain actions to be carried out on itself with the *methods* that the object contains. For example, an object of class *point* could carry out the action of changing the value of the *x* coordinate.
|
|
|
|
|
9
|
+In OOP, each object encapsulates within itself certain properties about the entity being modeled. For example, an object that models a *point* encapsulates the coordinates *x* and *y* of the point being represented. Furthermore, each object allows certain actions to be carried out on itself with the *methods* that the object contains. For example, an object of the class *point* could carry out the action of changing the value of the *x* coordinate.
|
|
|
10
|
+
|
|
|
11
|
+When the object class we need to use in our program has not been predefined in a library, we need to declare and implement our own class. To do this, we define *classes* that contain data with certain *properties* or *attributes*, and actions that we want to carry out with this data through the use of *methods* or *member functions*. This way, we can organize the information and processes in *objects* that have the properties and methods of a class. In today's laboratory experience, you will practice defining a class and implementing some of its methods by completing a simple network sniffer. The sniffer captures all the internet protocol (IP) packets that flow through your computer in the lab, and some other packet information.
|
10
|
|
12
|
|
11
|
-When an object class we need to use in our program has not been predefined in a library, we need to declare and implement our own class. To do this, we define *classes* that contain data with certain *properties* or *attributes*, and actions that we want to carry out with this data through the use of *methods* or *member functions*. This way, we can organize the information and processes in *objects* that have the properties and methods of a class. In today's laboratory experience you will practice defining a class and implementing some of its methods by completing a simple network sniffer. The sniffer captures all the internet protocol (IP) packets that flow through your computer in the lab, and some other packet information.
|
|
|
12
|
|
13
|
|
13
|
## Objectives
|
14
|
## Objectives
|
14
|
|
15
|
|
15
|
1. Practice the implementation and declaration of classes in C++.
|
16
|
1. Practice the implementation and declaration of classes in C++.
|
16
|
2. Implement methods in a class.
|
17
|
2. Implement methods in a class.
|
17
|
|
18
|
|
|
|
19
|
+
|
18
|
## Pre-Lab:
|
20
|
## Pre-Lab:
|
19
|
|
21
|
|
20
|
Before you get to the laboratory you should have:
|
22
|
Before you get to the laboratory you should have:
|
|
|
|
|
27
|
|
29
|
|
28
|
---
|
30
|
---
|
29
|
|
31
|
|
30
|
-##Classes and Objects in C++
|
|
|
|
|
32
|
+
|
|
|
33
|
+## Classes and Objects in C++
|
31
|
|
34
|
|
32
|
An *object* is an entity that contains data and procedures to manipulate them. Similar to how each variable has a *type* of data associated to it, each object has a *class* associated to it, which describes the properties of the the objects: its data (*attributes*), and the procedures that can be used to manipulate its data (*methods*).
|
35
|
An *object* is an entity that contains data and procedures to manipulate them. Similar to how each variable has a *type* of data associated to it, each object has a *class* associated to it, which describes the properties of the the objects: its data (*attributes*), and the procedures that can be used to manipulate its data (*methods*).
|
33
|
|
36
|
|
34
|
-It is not necessary to know all of the details about the methods of the object to define and use an object, but you must know how to create it and how to interact with it. The necessary information is available in the class' documentation. Before creating objects of any class, we should familiarize ourselves with its documentation. The documentation indicates, among other things, what entity is trying to be represented in the class, and its interface or methods available to manipulate the objects of the class.
|
|
|
|
|
37
|
+It is not necessary to know all of the details about the methods of the object to define and use an object, but you must know how to create it and how to interact with it. The necessary information is available in the class's documentation. Before creating objects of any class, we should familiarize ourselves with its documentation. The documentation indicates, among other things, what entity is trying to be represented in the class, and its interface or methods available to manipulate the objects of the class.
|
35
|
|
38
|
|
36
|
-Take a look at the documentation of the `Bird` class which can be found in [this link.](http://ada.uprrp.edu/~ranazario/bird-html/class_bird.html).
|
|
|
|
|
39
|
+So you can see an example of a class, take a look at the documentation of the `Bird` class which can be found in [this link.](http://ada.uprrp.edu/~ranazario/bird-html/class_bird.html).
|
37
|
|
40
|
|
38
|
-###Classes
|
|
|
39
|
|
41
|
|
40
|
-A class is a description of the data and processes of an object. The class’ declaration establishes the attributes that each of the objects of the class will have, and the methods that it can invoke.
|
|
|
|
|
42
|
+### Classes
|
|
|
43
|
+
|
|
|
44
|
+A class is a description of the data and processes of an object. The class’s declaration establishes the attributes that each of the objects of the class will have, and the methods that it can invoke.
|
41
|
|
45
|
|
42
|
If it isn't specified otherwise, the attributes and methods defined in a class will be private. This means that the variables can only be accessed and changed by the methods of the class (*constructors*, *setters*, and *getters*, among others).
|
46
|
If it isn't specified otherwise, the attributes and methods defined in a class will be private. This means that the variables can only be accessed and changed by the methods of the class (*constructors*, *setters*, and *getters*, among others).
|
43
|
|
47
|
|
|
|
|
|
72
|
|
76
|
|
73
|
---
|
77
|
---
|
74
|
|
78
|
|
75
|
-## Communication among computers
|
|
|
|
|
79
|
+
|
|
|
80
|
+## Communication Among Computers
|
76
|
|
81
|
|
77
|
Computers communicate with each other through the Internet Protocol (IP). When a computer sends information to another computer, the information is sent via *Internet packets* that contain the *source address*, which is the Internet address of the computer sending the information, and the *destination address*, which is the Internet address of the computer that receives the message. The Internet addresses are used to guide the information from one computer to another, but once the arrives to its destination, who is supposed to receive the information? Which application must receive the information?
|
82
|
Computers communicate with each other through the Internet Protocol (IP). When a computer sends information to another computer, the information is sent via *Internet packets* that contain the *source address*, which is the Internet address of the computer sending the information, and the *destination address*, which is the Internet address of the computer that receives the message. The Internet addresses are used to guide the information from one computer to another, but once the arrives to its destination, who is supposed to receive the information? Which application must receive the information?
|
78
|
|
83
|
|
79
|
The Internet packets must also specify the application that is sending the information and the application that must receive it. We can think of the Internet addresses like home postal mail addresses, and that the applications that send and receive the information are the persons that send and receive postal letters. To send a letter via postal mail, the recipient of the letter must be specified. This corresponds to the application that receives the information. To identify the source and destination application, the Internet protocol uses what is known as *port numbers*. This way, looking the packet information, the source and destination addresses and ports can be identified.
|
84
|
The Internet packets must also specify the application that is sending the information and the application that must receive it. We can think of the Internet addresses like home postal mail addresses, and that the applications that send and receive the information are the persons that send and receive postal letters. To send a letter via postal mail, the recipient of the letter must be specified. This corresponds to the application that receives the information. To identify the source and destination application, the Internet protocol uses what is known as *port numbers*. This way, looking the packet information, the source and destination addresses and ports can be identified.
|
80
|
|
85
|
|
81
|
-For instance, when your lab computer communicates with the server for Moodle, the packets that carry the information from your computer to the web server contains the source address, which is the address of the lab computer, and the destination address which is the Moodle server. The source port is the port of your web browser and the destination port is of the Moodle web server.
|
|
|
|
|
86
|
+For instance, when your lab computer communicates with the server for Moodle, the packets that carry the information from your computer to the web server contains the source address, which is the address of the lab computer, and the destination address which is the Moodle server. The source port is the port of your web browser and the destination port is the port of the Moodle web server.
|
82
|
|
87
|
|
83
|
-The Internet addresses are represented on 4 bytes (32 bits), and usually are presented to users as strings of 4 decimal values. Each decimal value is the decimal representation of one of the 4 bytes: "(0-255).(0-255).(0-255).(0-255)". Some examples of IP addresses are: 10.0.1.10, 192.168.10.11, 136.145.54.10.
|
|
|
|
|
88
|
+The Internet addresses occupy 4 bytes (32 bits), and usually are presented to users as strings of 4 decimal values. Each decimal value between 0 and 255 is the decimal representation of one of the 4 bytes: "(0-255).(0-255).(0-255).(0-255)". Some examples of IP addresses are: `10.0.1.10`, `192.168.10.11`, `136.145.54.10`.
|
84
|
|
89
|
|
85
|
-Port numbers are composed of 2 bytes or 16 bits. Therefore port numbers range from 0-65535. There are ports numbers assigned to known application services such as number 22 for ssh, 23 for telnet, 25 smtp, 80 for http, and so on.
|
|
|
|
|
90
|
+Port numbers are composed of 2 bytes or 16 bits. Therefore port numbers range from 0-65535. There are ports numbers assigned to known application services such as number 22 for ssh, 23 for telnet, 25 for smtp, 80 for http, and so on.
|
86
|
|
91
|
|
87
|
-To complicate things a little bit, each computer network card has an unique identifier that is used for the communication between you computer and the network device that routes the network traffic from the Internet and local network to your computer and vice-versa (Ethernet protocol). This unique identifier is known as the Hardware address (a.k.a Multiple Access Controll (MAC) addres), is represented on 6 bytes (48 bits), and is presented to users as strings of 6 hexadecimal values. Each hex value is the hex representation of the 6 bytes: "(00-ff):(00-ff):(00-ff):(00-ff):(00-ff):(00-ff)". Examples of MAC addresses are: e0:f8:47:01:e9:90, 70:ad:60:ff:fe:dd:79:d8 , and so on.
|
|
|
|
|
92
|
+To complicate things a little bit, each computer network card has an unique identifier that is used for the communication between you computer and the network device that routes the network traffic from the Internet and local network to your computer and vice-versa (*Ethernet protocol*). This unique identifier is known as the Hardware address (a.k.a *Multiple Access Controll (MAC) address*), is represented using 6 bytes (48 bits), and is presented to the users as strings of 6 hexadecimal values (each pair of hexadecimal digits corresponds to 1 byte). Each hex value is the hex representation of the 6 bytes: "(00-ff):(00-ff):(00-ff):(00-ff):(00-ff):(00-ff)". Some examples of MAC addresses are: `e0:f8:47:01:e9:90` and `70:ad:60:ff:fe:dd:79:d8`.
|
88
|
|
93
|
|
89
|
---
|
94
|
---
|
90
|
|
95
|
|
|
|
96
|
+
|
91
|
## Simple Packet Sniffer
|
97
|
## Simple Packet Sniffer
|
92
|
|
98
|
|
93
|
-A packet sniffer (also known as packet analyzer, protocol analyzer, or network analyzer) is a computer program that can intercept and log traffic passing over a digital network, or network device. As data flows across the network, the sniffer captures each packet and, if needed, decodes the packet's raw data[1].
|
|
|
|
|
99
|
+A packet sniffer (also known as packet analyzer - protocol analyzer - or network analyzer) is a computer program that can intercept and log traffic passing over a digital network, or network device. As data flows across the network, the sniffer captures each packet and, if needed, decodes the packet's raw data[1].
|
94
|
|
100
|
|
95
|
Each packet captured by a sniffer has a structure similar to the ilustrated in Figure 1.
|
101
|
Each packet captured by a sniffer has a structure similar to the ilustrated in Figure 1.
|
96
|
|
102
|
|
|
|
|
|
109
|
2. **Ether type**: is used to indicate the type of protocol used in the **payload**. One of the possible **payloads** is an IP packet.
|
115
|
2. **Ether type**: is used to indicate the type of protocol used in the **payload**. One of the possible **payloads** is an IP packet.
|
110
|
3. **Payload**: contains an IP packet (in reality it can contain other protocols, but for this laboratory experience we will asume that it contains only IP).
|
116
|
3. **Payload**: contains an IP packet (in reality it can contain other protocols, but for this laboratory experience we will asume that it contains only IP).
|
111
|
|
117
|
|
|
|
118
|
+
|
112
|
Inside the payload, the IP packet contains various field, among them:
|
119
|
Inside the payload, the IP packet contains various field, among them:
|
113
|
|
120
|
|
114
|
1. The **source and destination IP** addresses
|
121
|
1. The **source and destination IP** addresses
|
|
|
|
|
116
|
3. The IP packet **payload**. Inside this payload the data that wants to be communicated is contained.
|
123
|
3. The IP packet **payload**. Inside this payload the data that wants to be communicated is contained.
|
117
|
|
124
|
|
118
|
|
125
|
|
119
|
-In this laboratory experience, you will complete a simple packet sniffer that captures all the IP packets that flow through your laboratory computer, and some additional information of the packets. Additionally, it detects the non encrypted requests of images in the web, and displays the images in a GUI.
|
|
|
|
|
126
|
+In this laboratory experience, you will complete a simple packet sniffer that captures all the IP packets that flow through your laboratory computer, and some additional information of the packets. Additionally, it detects the non encrypted requests of images in the web, and displays the images in the GUI.
|
120
|
|
127
|
|
121
|
---
|
128
|
---
|
122
|
|
129
|
|
123
|
---
|
130
|
---
|
124
|
|
131
|
|
125
|
-!INCLUDE "../../eip-diagnostic/simple-sniffer/en/diag-simple-sniffer-01.html"
|
|
|
126
|
-<br>
|
|
|
127
|
-
|
|
|
128
|
----
|
|
|
129
|
-
|
|
|
130
|
----
|
|
|
131
|
|
132
|
|
132
|
-## Laboratory session:
|
|
|
|
|
133
|
+## Laboratory Session:
|
133
|
|
134
|
|
134
|
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.
|
135
|
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.
|
135
|
|
136
|
|
|
|
|
|
148
|
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.
|
149
|
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.
|
149
|
|
150
|
|
150
|
|
151
|
|
151
|
-### Exercise 1 - Familiarize yourself with the application
|
|
|
|
|
152
|
+### Exercise 1 - Familiarize Yourself with the Application
|
152
|
|
153
|
|
153
|
-#### Instructions:
|
|
|
|
|
154
|
+#### Instructions
|
154
|
|
155
|
|
155
|
|
156
|
|
156
|
1. Load the project `SimpleSniffer` into `QtCreator`. There are two ways to do this:
|
157
|
1. Load the project `SimpleSniffer` into `QtCreator`. There are two ways to do this:
|
|
|
|
|
163
|
2. Configure the project. 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`.
|
164
|
2. Configure the project. 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`.
|
164
|
|
165
|
|
165
|
|
166
|
|
166
|
-### Exercise 2 - Complete the class ethernet_packet
|
|
|
|
|
167
|
+### Exercise 2 - Complete the Class ethernet_packet
|
167
|
|
168
|
|
168
|
1. Study the file `ethernet_hdr.h`. This file contains the definition of the data structure that represents an Ethernet header.:
|
169
|
1. Study the file `ethernet_hdr.h`. This file contains the definition of the data structure that represents an Ethernet header.:
|
169
|
|
170
|
|
|
|
|
|
222
|
|
223
|
|
223
|
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.
|
224
|
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.
|
224
|
|
225
|
|
225
|
-### Exercise 3 - Build the header of the class ip_packet
|
|
|
|
|
226
|
+### Exercise 3 - Build the Header of the Class ip_packet
|
226
|
|
227
|
|
227
|
1. Study the definitions of the functions of the class `ip_packet` found in file `ip_packet.cpp`
|
228
|
1. Study the definitions of the functions of the class `ip_packet` found in file `ip_packet.cpp`
|
228
|
|
229
|
|
|
|
|
|
241
|
|
242
|
|
242
|
## Deliverables
|
243
|
## Deliverables
|
243
|
|
244
|
|
244
|
-1. Use "Deliverables" in Moodle to upload the file `ethernet_packet.cpp` and `ip_packet.h` that you defined. Remember to use good programming techniques, by including the names of the programmers involved, and documenting your program.
|
|
|
|
|
245
|
+1. Use "Deliverables" in Moodle to upload the file `ethernet_packet.cpp` and `ip_packet.h` that you defined. Remember to use good programming techniques, include the names of the programmers involved, and document your program.
|
245
|
|
246
|
|
246
|
---
|
247
|
---
|
247
|
|
248
|
|
|
|
|
|
249
|
|
250
|
|
250
|
## References
|
251
|
## References
|
251
|
|
252
|
|
252
|
-[1] http://en.wikipedia.org/wiki/Packet_analyzer
|
|
|
|
|
253
|
+[1] http://en.wikipedia.org/wiki/Packet_analyzer
|