Monday, May 24, 2010

Subnet Mask Calcualtions

For example, if the number of hosts(510) given and a sample IP(172.30.0.0) has given. How to find out the subnet mask?

=> Here in this case answers is
255.255.254.0

172.30.0.0 is an IP Address of type Class B. So the possible subnet mask will be 255.255.0.0

As per the problem only 510 hosts are allowed and 0,255 reserved for special purposes. So the total of 512 hosts possible.


i.e. 512(Decimal) = 2^9.

Means
only 9 bits will be used for IP and the remaining will be used for Sub net Masking.

As we know, each IP will have 4 Octets and each Octet will be represented by 8 bits. So out of 9 bits, 8 bits will be used by Fourth Octet and 1 bit will be used by Third Octet.

If you see the, Class B sub net mask, First and Second Octets will be represented by 255. Means all the bits are used for Sub net masking only.

First Octet - 1111 1111 - 255
Second Octet - 1111 1111 - 255
Third Octet - 1111 1110 - 254(only 7 bits)
Fourth Octet - 0000 0000 - 0


So, the final subnet mask will be 255.255.254. 0

For more details on Sub net mask calculations,
http://www.joshgentry.com/networking/subnet.htm


Any comments ? suggestions?

Tuesday, May 18, 2010

Real Time Clock (RTC) using C

This weekend while going through some of the forums, i saw a few posts on RTC using C. It's quiet interesting, so i worked on it written the following code.

#include "stdio.h"
#include "dos.h"
#include "conio.h"
#include "stdlib.h"
#include "time.h"
int main(void)
{
time_t now;
time(&now);
while(1)
{
time(&now);
clrscr();

printf("%s", ctime(&now));
sleep(1);
if(kbhit())
{
break;
}
}

return 0;
}

Any Comments and Suggestions?