CN Lab Viva Questions
CN Lab Viva Questions
CN Lab Viva Questions
Definitions of Firewall ?
Firewalls are the most important aspect of the networkand its security in today's era. Due to maximization of attackson the
networks from various groups stealing data, denyingservices etc the firewall is playing a vital roles in
computernetworks.
What is ICMP?
ICMP is Internet Control Message Protocol, a network layer protocol of the TCP/IP suite used by hosts and gateways
to send notification of datagram problems back to the sender. It uses the echo test / reply to test whether a destination
is reachable and responding. It also handles both control and error messages.
What are the data units at different layers of the TCP / IP protocol suite?
The data unit created at the application layer is called a message, at the transport layer the data unit created is called
either a segment or an user datagram, at the network layer the data unit created is called the datagram, at the data link
layer the datagram is encapsulated in to a frame and finally transmitted as signals along the transmission media.
What is the minimum and maximum length of the header in the TCP segment and IP datagram?
The header should have a minimum length of 20 bytes and can have a maximum length of 60 bytes.
What is region?
When hierarchical routing is used, the routers are divided into what we will call regions, with each router knowing all
the details about how to route packets to destinations within its own region, but knowing nothing about the internal
structure of other regions.
The accept() call establishes a client-server connection on the server side. (The client requests the connection using the
connect() system call.) The server must have created the socket using socket(), given the socket a name using bind(),
and established a listen queue using listen().
int recvfrom(int s, char *msg, int len, int flags,struct sockaddr *from, int *fromlen)
This function allows a message msg of maximum length len to be read from a socket with descriptor s from the socket
named by from and fromlen, where fromlen is the actual length of from. The number of characters actually read from
the socket is the return value of the function. On error, -1 is returned and errno describes the error. flags may be 0, or
may specify MSG_PEEK to examine a message without actually receiving it from the queue.
If no message is available to be read, the process will suspend waiting for one unless the socket is set to nonblocking
mode (via an ioctl call).
The system I/O call read() can also be used to read data from a socket.
int sendto(int s, char *msg, int len, int flags, struct sockaddr *to, int tolen)
This function allows a message msg of length len to be sent on a socket with descriptor s to the socket named by to
and tolen, where tolen is the actual length of to. flags will always be zero for our purposes. The number of characters
sent is the return value of the function. On error, -1 is returned and errno describes the error.
Recall that, using socketpair(), sockets could only be shared between parent and child processes or children of the
same parent. With a name attached to the socket, any process on the system can describe (and use) it.
In a call to bind(), s is the file descriptor for the socket, obtained from the call to socket(). name is a pointer to a
structure of type sockaddr. If the address family is AF_UNIX (as specified when the socket is created), the structure is
defined as follows:
struct sockaddr {
u_short sa_family;
char sa_data[14];
};
name.sa_family should be AF_UNIX. name.sa_data should contain up to 14 bytes of a file name which will be
assigned to the socket. namelen gives the actual length of name, that is, the length of the initialized contents of the
data structure.
A value of 0 is return on success. On failure, -1 is returned with errno describing the error.
Two additional data transfer library calls, namely send() and recv(), are available if the sockets are connected. They
correspond very closely to the read() and write() functions used for I/O on ordinary file descriptors.
int send(int sd, char *buf, int len, int flags)
int recv(int sd, char * buf, int len, int flags)
In both cases, sd is the socket descriptor. For send(), buf points to a buffer containing the data to be sent, len is the
length of the data and flags will usually be 0. The return value is the number of bytes sent if successful. If not
successful, -1 is returned and errno describes the error.
For recv(), buf points to a data area into which the received data is copied, len is the size of this data area in bytes, and
flags is usually either 0 or set to MSG_PEEK if the received data is to be retained in the system after it is received.
The return value is the number of bytes received if successful. If not successful, -1 is returned and errno describes the
error.
read() is equivalent to recv() with a flags parameter of 0. Other values for the flags parameter change the behaviour
of recv().
Ans: First declare fd_set variables. so that this can be used in select call.
Depending on the (read/write) on socket you are using Add the socket to the corresponding fd_sets using
FD_SET() call. Before that you have to clear any garbage value there using FD_ZERO(). Then Select call requires
timeout ie. maximum time to wait for I/O arrival on fds. We are going to wait indefinetly so we make the timeval
structure ZERO by making any calls specified in the comments. Call the select call with First Argument as 1 greater
than the greater numbered file descriptor in the second , third or fourth argument. since we are going to read the socket
place it in the second argument fd_set (as already we done). and give the timeval structure as Last argument to select
so select will
wait indefinetly on the socket and if any I/O comes it will return with success value. Then check for the Existence of
the socket descriptor in the readfds fd_set using FD_ISSET() macro. if it returns
true then we can continue any further reading with that socket.
The basic difference is that select()'s fd_set is a bit mask and therefore has some fixed size. It would be possible for
the kernel to not limit this size when the kernel is compiled, allowing the application to define FD_SETSIZE to
whatever it wants (as the comments in the system header imply today) but it takes more work.
With poll(), however, the user must allocate an array of pollfd structures, and pass the number of entries in this array,
so there's no fundamental limit. As Casper notes, fewer systems have poll() than select, so the latter is more portable.
Also, with original implementations (SVR3) you could not set the descriptor to -1 to tell the kernel to ignore an entry
in the pollfd structure, which made it hard to remove entries from the array.