0% found this document useful (0 votes)
51 views

Network Programming QBank

The document contains 15 questions about network programming protocols like TCP/IP and socket programming. The questions cover topics such as TCP/IP protocols, socket address structures, identifying connections between hosts, I/O models, byte ordering, and functions for address conversion and socket programming. Sample code is provided for some answers. The final question asks about designing an end-system multicast protocol with a rendezvous point to control the overlay topology between group members.

Uploaded by

Mohamed Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

Network Programming QBank

The document contains 15 questions about network programming protocols like TCP/IP and socket programming. The questions cover topics such as TCP/IP protocols, socket address structures, identifying connections between hosts, I/O models, byte ordering, and functions for address conversion and socket programming. Sample code is provided for some answers. The final question asks about designing an end-system multicast protocol with a rendezvous point to control the overlay topology between group members.

Uploaded by

Mohamed Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

‫بنك أسئلة‬

Network Programming
Q1. [17fm, 18f, 19fm, 20f] Draw Various protocols in TCP/IO model?

● ARP: Address Resolution Protocol


● RARP: Reserve Address Resolution Protocol
● ICMP: Internet Control Message Protocol
● IGMP: Internet Group Management Protocol
● IP: Internet Protocol
● TCP: Transmission Control Protocol
● UDP: User Datagram Protocol

Q2. [17fm, 18f, 19fm, 20f] Write the socket address data structure for IPv4

An IPv4 socket address structure, commonly called an “Intenet socket address


structure” is names sockaddr_in and is defined by including the <netinet/in.h>
header it is shown as the following:
struct in_addr {
in_addr_t s_addr; /* 32-bit IPv4 address */
/* network byte ordered */
};
struct sockaddr_in {
uint8_t sin_len; /* length of structure (16) */
sa_family_t sin_family; /* AF_INET */
in_port_t sin_port; /* 16-bit TCP or UDP port number */
/* network byte ordered */
struct in_addr sin_addr; /* 32-bit IPv4 address */
/* network byte ordered */
char sin_zero[8];
};

Q3. [17fm, 18f, 19fm, 20f] By what you can identify the connection between two hosts

We can identify the connection between two machines by IP address and port number
for each machine.

ID = {IPS, PortS, IPd, Portd}

Q4. [19f] What is this function do:

struct timeval tm; tm.tv_sec=2; tm.tv_usec=0


Tells the kernel how long to wait for one of the specified descriptors to become ready.
A timeval structure specifies the number of seconds (tm.tv_sec) and microseconds
(tm.tv_usec).

select(10, NULL, NULL, NULL, &tm);


Tells the kernel what descriptors we are interested in (for reading, writing, or an
exception condition) and how long to wait

void bzero(void *dest, uint_8 size);


Sets the specified number of bytes to zero in the destination

void bcopy(const void *src, void dest, uint_8 size);


Moves the specified number of bytes from the source to the destination

Q5. [17m, 18f, 19fm, 20f] Explain with drawing the socket functions for both TCP client

and server
● First, the server is started then sometime later, a client is started that connects
to the server
● We assume that the client sends a request to the server, the server process the
request, and the server sends a reply back to the client
● This continues until the client closes its end of the connection, which sends an
end-of-file notification to the server
● The server then closes its end of the connection and either terminate or waits
for a new client connection

Q6. [17fm, 18f, 19fm, 20f] Describe both little-endian byte order and big-endian byte

order

There are two ways to store bytes in memory:

● With the low-order byte at the starting address, known as little-endian byte
order
● Or with the high-order byte at the starting address, known as big-endian byte
order
Q7. [18f, 19f] Describe by drawing the I/O models

Blocking I/O

● The most prevalent model for I/O


● By default, all sockets are blocking

Nonblocking I/O

■ When an I/O operation that I request cannot be completed without putting the
processes to sleep, do not put the process to sleep, but return an error instead.
I/O Multiplexing

● Call select or poll and block in one of these two system calls, instead of blocking
in the actual I/O system call

Signal driven I/O


● Uses signals
● Telling the kernel to notify us with the SIGIO signal when the descriptor is ready

Asynchronous I/O

● Defined by the POSIX specification


● These function work by telling the kernel to start the operation and to notify us
when the entire operation is complete
● With signal-driven I/O, the kernel tells us when an I/O operation can be initiated.
● But with asynchronous I/O, the kernel tells us when an I/O operation is complete

Q8. [17m, 18f, 19fm] What is the function of the following functions with write its

declarations:

★ inet_aton(...)
Converts an IPv4 address from dotted-decimal string “192.168.1.1” to its
32-bit network byte ordered binary value
// Declaration:
// Returns: 1 if string was valid, 0 on error
int inet_aton(const char *strptr, struct in_addr *addrptr);
● int_addr(...)
Converts an IPv4 address from 32-bit network byte ordered binary value to
its dotted-decimal string “192.168.1.1”
// Declaration:
// Returns: 32bit binary network byte ordered IPv4 address;
INADDR_NONE if error
in_addr_t inet_addr(const char *strptr);

● ntohs(...)
Convert from network byte order to host byte order
// return: value in host byte order
uint16_t ntohs(uint16_t net16bitvalue);

● htons(...)
Convert from host byte order to network byte order
// return: value in network byte order
uint16_t htons(uint16_t host16bitvalue);

Q9. [19fm, 20f] Explain by drawing the socket address structure passed from process to

kernel and vice versa

The three functions bind, connect, and sendto pass a socket address structure from
the processed to the kernel.

One argument to these functions is the pointer to the socket address structure and
another argument is the integer size of the structure.

Since the kernel is passed both the pointer and the size of what the pointer points to, it
knows exactly how much data to copy from the process to the kernel.
Q10. [17f, 18f, 19fm, 20f] How to implement the client program and server program that
shown in the following figure

The above diagram is for an echo server that performs the following steps:
1. The client reads a line of text from its standard input and writes the line to the
server
2. The server reads the line from its network input and echoes the line back to the
client.
3. The client reads the echoed line and prints it on its standard output.
Q11. [18f] Explain I/O multiplexing (select function), and how to be used in the
connection of TCP? Give a simple example

Allows the process to instruct the kernel to wait for any one of multiple events to
occur and to wake up the process

Q12. [17f, 18f, 19f, 20f] In the TCP connection, the receiver has to know the number of
bytes which it receives, it is a problem of the synchronization, how to solve this
problem?

We determine a fixed size to the segment and add it to its TCP header so the receiver
is notified by the number of bytes that will be received.

A 32-bit sequence number is used to keep track of how much data is sent. THis
sequence number is included on each transmitted packet and acknowledged by the
opposite host as an acknowledgment number to inform the sending host that the
transmitted data was received successfully.

Q13. [17f, 18f, 19f, 20f] Design and implement a network chatting program with
exchanging files among a group of clients, How to think about it aby by using
drawing show the connectivity between the clients. Your answer has to consist of
functions prototype, the message format, write python code of both client and
server sides codes
Q14. [17fm, 18f, 19f] If you have a customer needs a program to use in his company that
have many branches in the world. Any branch needs to know the time of another
branches. Design and write the necessary code for that.
Q15. [17f, 18f, 19f, 20f] Design and implement a protocol in the application layer that
introduces one source to many destinations (one-to-many) service, this protocol is
called End-System Multicase (ESM). ESM is by nature centralized, everything
begins controlled by a single host, called Rendezvous Point (RP). Everything is
under control of RP. write python code of both Member and RP sides code.

★ Note: in 19f Host-based Multicast (HBM) is used instead of ESM

● The End-System Multicast (ESM) protocol automatically creates an overlay


topology between the various group members (source and receivers), using
point-to-point UDP tunnels between them
● Everything is under control by either a single RP called centralized ESM

RP:
● Knows members, their features, and communication costs between them.
● It’s responsible for overlay topology communication and its setup at each
member
UDP Tunnel:
● RP makes tunnels between nodes to make tree and create group of nodes
according to metrics between them
Evaluation Metrics
● Every node evaluate metrics between itself and other nodes and send them to
RP
● RP calculates the metrics between nodes and decides which nodes will connect
together and form a group of member od its neighnbors

You might also like