Hey folks!
Good to be back after a long time.
The topic I want to tell you about today is "internet".
well let me clear this first. The word "internet" has been created from - "interconnection of networks".
Any interconnection of networks is termed as an internet.
There is a slight difference between "internet" and THE "Internet" ( notice the capital I). The Internet is the World Wide Web (WWW) as we know of. This is also a interconnection of networks, but this consists of interconnection of a number of networks spread throughout the world.
The internet I am talking about is any general interconnection of networks.
The internet is logically divided into a number of layers, with the layers arranged in a stack like fashion. The layers are namely -
(from the top to the bottom)
1. Application layer
2. Transport layer.
3. Datalink layer.
4. The host to network layer.
The tasks and roles of each layers are well defined and so is the interface between any two layers are well defined. This make is easier to change or modify any layer without disturbing of effecting any other layer.
The Host to Network layer is the layer that is made up of the electrical signals that pass through the wires and make up the 1s and the 0s.
In the data link layer, the information moves in the form of 'packets' - which are units of data. The have a header as well as a trailer attached to it.
The transport layer is the layer that takes up teh responsibility of setting up a connection and ensuring that the data arrives in order and is dutyfully acknowledged (in case of connection oriented protocols) and is ultimately brought down gracefully.
All the network based programs reside in the application layer.
Will talk more about the layers in details later on. Till then, enjoy !!
Friday, July 6, 2007
Monday, December 25, 2006
Inetd
Recently while dabbling over socket programming, I came across a nifty feature known as inetd. It is basically a daemon that "listens" to the ports of the some well known servers and starts the server when it detects some request coming at that port.
For the uninitiated, a class of programs that work on the network are classified as "server-client" paradigm. The basic idea behind it is there would be a remote server program which would serve any request a client may send at it. For this kind of communication, a form of address is required. The address in this case is specified in the form of IP address and port number. Each Server has a port number and an IP address of the computer it is running on. The port number is pre determined and known by the client. The Server listens on the specified port for incoming requests. Whenever a client program sends any request to the server program (via its IP address, portnumber), the server processes the request and sends back the data to the client with the address specified by IP addres, portnumber.
Nowadays, a computer may run a number of servers, from http servers, mail servers and ftp servers. These servers need to running since the booting of the computer, listening for requests
Now the server uses up computer resources even when it is not performming any thing useful work instead just listening on its alloted port for incoming request.
The inetd deamon was built to address this situation. What the inetd does is instead of starting all the servers at boot time, only the inetd daemon is started. The inetd listens to all the ports that there are servers. It uses a API called SELECT, which allows a program to listen to a number of sockets simultaneously. The inetd runs in a loop and waits until the SELECT call returns. Whenever it detects an incoming connection, the SELECT call returns with the port number on which the incoming connection came. The inetd then understands which server to start based on the port number on which the request arrived.
What the inetd does is it "forks" and create a child process. The child process then exec the server process. Then the server process starts running. The server process uses the API getpeername() to get the address of the client process that is calling it. The inetd redirects the port of the incoming request to act as the standard input and standard output of the server process. It is to be noted that the file descriptors survive even across a exec call.
The server runs as an independent process, and when the server finishes serving the client, it ends and returns to the inetd process. The inetd again starts listenning to that port again and repeats the process for any incoming request.
Each server that runs are runned in the form of a deamon. So that it is detached from any terminal and runs independently. The process of making an running program into a daemon involves two forks and some clearn-up work. The process remains the same for all programs. Before inetd was introduced, all the servers had to independently make itself in to a daemon and then run. But with inetd, it is not required. Since inetd makes itself a daemon, all it child processes are not attached to any terminal, hence they are daemons automatically. So the programmer needs not worry about making there porgram into a daemon. The servers can now read and write as if it is reading and writing for the standard input and output. This makes the task of coding the servers eaiser.
This is just an introduction of inetd. This is intended for beginners. Please Write your comments telling me how you feel about this peice and how you want it to be improved. I would really appreciate you taking time out and writing your views
Thanks
For the uninitiated, a class of programs that work on the network are classified as "server-client" paradigm. The basic idea behind it is there would be a remote server program which would serve any request a client may send at it. For this kind of communication, a form of address is required. The address in this case is specified in the form of IP address and port number. Each Server has a port number and an IP address of the computer it is running on. The port number is pre determined and known by the client. The Server listens on the specified port for incoming requests. Whenever a client program sends any request to the server program (via its IP address, portnumber), the server processes the request and sends back the data to the client with the address specified by IP addres, portnumber.
Nowadays, a computer may run a number of servers, from http servers, mail servers and ftp servers. These servers need to running since the booting of the computer, listening for requests
Now the server uses up computer resources even when it is not performming any thing useful work instead just listening on its alloted port for incoming request.
The inetd deamon was built to address this situation. What the inetd does is instead of starting all the servers at boot time, only the inetd daemon is started. The inetd listens to all the ports that there are servers. It uses a API called SELECT, which allows a program to listen to a number of sockets simultaneously. The inetd runs in a loop and waits until the SELECT call returns. Whenever it detects an incoming connection, the SELECT call returns with the port number on which the incoming connection came. The inetd then understands which server to start based on the port number on which the request arrived.
What the inetd does is it "forks" and create a child process. The child process then exec the server process. Then the server process starts running. The server process uses the API getpeername() to get the address of the client process that is calling it. The inetd redirects the port of the incoming request to act as the standard input and standard output of the server process. It is to be noted that the file descriptors survive even across a exec call.
The server runs as an independent process, and when the server finishes serving the client, it ends and returns to the inetd process. The inetd again starts listenning to that port again and repeats the process for any incoming request.
Each server that runs are runned in the form of a deamon. So that it is detached from any terminal and runs independently. The process of making an running program into a daemon involves two forks and some clearn-up work. The process remains the same for all programs. Before inetd was introduced, all the servers had to independently make itself in to a daemon and then run. But with inetd, it is not required. Since inetd makes itself a daemon, all it child processes are not attached to any terminal, hence they are daemons automatically. So the programmer needs not worry about making there porgram into a daemon. The servers can now read and write as if it is reading and writing for the standard input and output. This makes the task of coding the servers eaiser.
This is just an introduction of inetd. This is intended for beginners. Please Write your comments telling me how you feel about this peice and how you want it to be improved. I would really appreciate you taking time out and writing your views
Thanks
Subscribe to:
Posts (Atom)