October 16, 18, 20

Server

 

after fork

parent closes sd2(slave)

child closes sd(master)

 

void sig_chld(int signo)

{

    pid_t pid;

    int stat;

    while((pid=waitpid(-1,&stat,WNOHANG)))

    {

        printf("child exited\n");

        signal(SIGCHLD, &sigchld);

    }

}

 

main()

{

....

struct sigactionact;

act.sa_handler=sigchld;

sigempty(&act.sa_mask);

}

 

The while loop for the server should look something like that:

#include <errno.h>

...

while(1)

{

   ss=accpet(s1,....);

   if (errono==EINTR)

        continue;

   else

        perror();

}

Stage 3

 

Your server has to build a list of files in the directory with hyperlinks.

 

int fstat (int fileds, struct stat *buf) obtains info about an open file descriptor.

 

struct stat {

   mode_t st_mode;

   off_t     st_size;     //size

   time_t   st_mtime; //time last modified

}

 

Use S_ISDIR to check if a file descriptor is a directory or a file.

 

Stage 4

 

http://...cgi-bin/hello?a=b%c=d

1) putenv("name=value");

2)"QUERY_STRING=a=b%c=d"

3)"REQUEST_METHOD=GET"

4) The header must be changed so that the server stops sending information before the content type is sent. The CGI script will tell the client what the content type is.

5)Redirect the output to socket using dup2(ss,1);

6)execvp("http_root_dor/cgi-bin/exe");

 

 

Local Loop

 

- Standard  connection between home/business and central office

 

Frequency Spectrum in Phone Lines

- Frequency response of a phone line for high frequency is irregular

- A DSL modem looks for places in the frequency spectrum where the response is food and use those channels

- ADSL:

Cable Modems

- use cable TV

- uses FDM

- group of subscribers in neighborhood share the same bandwidth

- neighborhoods are connected to central office using optical fiber

 

 

All computers look like they have the same IP address. This allows multiple computers to share internet connection. HUB/Address Translation/Firewall

 

Wide Area Networks

- Span large distance

- Connect multiple LANs and MANs using routers (also called packet switches)

- The router connects different networks and forwards packets using destination

- Different between bridge and router

A router:

A host address is divided into two parts (Network #, Host #)

The router uses the Network # for routing the packet. The router has information on how to route a packet to its destination.

 

Routing Algorithms

Next Hop Forwarding - most popular

- each router has a routing table that gives the next router necessary to reach destination

 

 

R1 Routing Table

Net Router/Interface
N1 i1
N2 R1,i2
N3 i2
N4 R2,i2
N5 R2,i2

 

R2 Routing Table

Net Router/Interface
N1 R1,i1
N2 R3,i2
N3 i1
N4 i2
N5 i3

 

R3 Routing Table

Net Router/Interface
N1 R2,i2
N2 i1
N3 R2,i2
N4 i2
N5 R2,i2

 

Next Hop Forwarding

 

- Routing table gives next router necessary to reach  destination network

 

R2 Routing Table

Net Router/Interface

If R2 receives a packet for destination (N1, H1) it will forward it to R1. If R2 receives a packet for (N5,H5) it will directly deliver the packet through interface i3

N1 R1,i1
N2 R3,i2
N3 i1
N4 i2
N5 i3

 

- Forward table can be abbreviated:

 

Routing Table

Net Router/Interface
N1 i1
N3 i2
default R2

 

- protocol use in groups of LAN to exchange route information is called RIP (Routing Internet Protocol)

- to get routing table from a router you can use the command /usr/local/bin/ripquery

 

- The source of routing info can be:

- We can represent routers/nets using graphs

- Edges represent distances or how slow/fast the connection is.

-What is the best route?

 

 

- The shortest path is not always the one that has the less number of router

- To find/build routing table

 

Link State Routing

- All Routers exchange routing information

- Every single router has the whole picture of the network

- Each router runs Dijkstra's shortest path algorithm

- Routers build their own table using this information

- Optimal

- Distavantages:

Distance Vector Algorithm

 

- Each router sends information to neighbor routers with the networks they can reach

- A router will change a route if the new information contains a better route considering the distance between the two routers.

Example:

 

 

- Current routing table:

For R3 For R4
N1 5 N1 3
N2 3 N2 6
N3 2 N3 2

 

Routing update from R3 to R4

N1 5
N2 3
N3 2

 

- R4 receives update and check if it is better to update route entries

- >From R4 reaching N1 currently costs 3. If N3 is used the cost is 5+2=7. Do not change rout to N1.

- >From R4 reaching N2 currently costs 6. If R3 is used the cost is 3+2 =5. Change route to R3.

- >From R4 reaching N3 currently costs 2. If R3 is used the cost is 2+2=4. Do not change route. 

 

- Advantage:

- Disadvantage:

- RIP uses Distance Vector Routing

Examples of WAN:

- Arpanet:

- X.25

- Frame Relay

- ATM