Sunday, April 12, 2015

Saturday, April 11, 2015

Reversing String using RPC


It seems that last year, everyone got 2 questions each, and that almost everyone got one question as - Ping / RPC / NS2

Learn Ping too :P
And do check the possible questions pdf

Networks Lab Possible Questions

Below is the code ( all the files ) for string reverse using RPC.And check the README

String Reverse using RPC



Character Stuffing Code



Below is the code for character stuffing.
Client is the sender.
Server is the receiver.

Character Stuffing Code



Friday, April 10, 2015

Bit Stuffing Code


Below is the code for bit stuffing.
Client is the sender.
Server is the receiver.

Bit Stuffing Code



Thursday, April 9, 2015

MASM and DOSBOX

For MPMC, I hear a lot of stuff about MASM. Saying that it's highly probable to get a MASM question in the semester lab exam, since there are not much kits etc :P

However, it's always good to learn and know as much as possible. So, if you don't have MASM, get it!


The above link also has DOSBOX installation files. And the 8086 folder will also have a simple asm code to display a string, along with it's obj and exe files.

Below is a video that will help you with the basics on how to use DOSBOX and MASM. Start soon!


Images for the Bind Error situation.


The above picture shows a server running, and in a terminal, this command has been executed :

netstat -a -tulpn

and it shows the process id and name of the processes and the ports they are using and their states, then it shows the type of connection - udp,tcp and all.

Now, below are two images to show how server was close unexpectedly using Ctrl+C ( you should actually use Ctrl+Z ) and client is also close unexpectedly.



Now, here, I closed server first, then the client. Both in an unexpected manner using Ctrl+C.

If you use the netstat command, you will see this :


I used grep with the port number, to get processes that have the port number. Actually, now, the port number is being used by the kernel and not by any process and if you try the server program now, you will get bind error. [ Error occurs only if the netstat command shows "TIME_WAIT" as the state of the socket associated with port 6700 (the one on left). And note that socket associated with 6700 occurs at the left (local port) and another port number 36594 on the right(remote port), which is of the client, here.]

But if you close the client first, then the server. Both in an unexpected manner, and then use netstat command, you will see this :


Here, the socket associated with port 36595 (the one on left ) is in TIME_WAIT state and socket with port 6700 does not happen to be in that state. Now, if you run server, listening at port 6700, you won't get bind errors.

And this happens in TCP, where there are states like "TIME_WAIT"  "CLOSED" "FIN_WAIT" and stuff in the connection termination phase. I don't think there is any possibility of bind error in UDP, due to unexpected closing of the server / client. Thought it may occur due to some other fault.

Bind Error : Familiar ?

This has been a big trouble to people.

There can be many causes for this error.

To detect any error in networks, use perror() function. This function will tell the error based on the error number (errno) set by the recently called function.

After calling the bind() function, and checking the return value as -1, you would have used perror() to print the error. Mostly you would have seen the perror() printing : "Address already in use". This is caused by some unexpected closing of the server program and client program, when you executed it the last time. This is because of some concept of connection termination which is a 4 - way handshake.

The "address" in the error, refers to the socket address. Socket address is a combination of port address and ip address. "Address already in use". The ip address is not being used by anyone, but the port address can be open because of the unexpected closing, that I mentioned. So, now you got to check for open ports. And you will have to change the port number in your program.

To check if the port used in your program is in use, try this statement

netstat -tulpn | grep <port number>

for eg

netstat -tulpn | grep 5678

you can use an extra option -a

netstat -tulpn -a | grep 5678

And other causes for bind error may be because of undefined socket descriptor.
May be you didn't check the socket descriptor value, and may be it's value is -1, because of some error in socket() system call. So, when you use this invalid socket descriptor value in bind() function as argumnet, you will get errors.

If you still have other related problems, just comment.

Bit Stuffing in Networks


Bit stuffing happens in Data Link Layer.

The start and stop flag is indicated by the 8 bits : 01111110

The process of adding one extra 0 whenever five consecutive 1s follow a 0 in
the data, so that the receiver does not mistake the pattern 01111110 for a flag.