Question

In: Computer Science

Implement the following in Classless IP Addressing in C programming using decimal number system (a) Compute...

Implement the following in Classless IP Addressing in C programming using decimal number system (a) Compute First Address, Last address and Number of address from given IP address and mask. Input is given by the user

Solutions

Expert Solution

code:

#include<stdio.h>
#include<math.h>
int main()
{
int f[4],l[4],m,g[4];
int t,z,n[4];
printf("enter the mask:");
scanf("%d",&m);
printf(" enter the ip address:");
scanf("%d",&g[0]);
scanf("%d",&g[1]);
scanf("%d",&g[2]);
scanf("%d",&g[3]);

t=32-m;
z=pow(2,t);//this is for calculating number of ips
if(t<=8)//this is for calculating subnet ip
{
n[0]=g[0];
n[1]=g[1];
n[2]=g[2];
n[3]=g[3]&255<<t;

}
if(t>8&&t<=16)//this is for calculating subnet ip
{
n[0]=g[0];
n[1]=g[1];
n[2]=g[2]&255<<t-8;
n[3]=0;

}
if(t>16&&t<=24)//this is for calculating subnet ip
{
n[0]=g[0];
n[1]=g[1]&255<<t-16;
n[2]=0;
n[3]=0;

}
if(t>24&&t<=32)//this is for calculating subnet ip
{
n[0]=g[0]&255<<t-24;
n[1]=0;
n[2]=0;
n[3]=0;

}
//this is for first ip address
f[3]=g[3]&n[3];
f[2]=g[2]&n[2];
f[1]=g[1]&n[1];
f[0]=g[0]&n[0];
//this is for last ip address
l[0]=(g[0])|!(n[0]);
l[1]=(g[1])|!(n[1]);
l[2]=(g[2])|!(n[2]);
l[3]=(g[3])|!(n[3]);
printf("Number of addresses:%d ",z);
printf("first address:%d . %d . %d . %d ",f[0],f[1],f[2],f[3]);
printf("last address:%d . %d . %d . %d",l[0],l[1],l[2],l[3]);
}

output:


Related Solutions

Compare classfull IP addressing with classless IP addressing. Why was classless IP addressing designed?
Compare classfull IP addressing with classless IP addressing. Why was classless IP addressing designed?
a. Explain with an example a scenario where both the class full and classless IP addressing...
a. Explain with an example a scenario where both the class full and classless IP addressing scheme can be used to configure the IP address for the network. [5Marks
a. Explain with an example a scenario where both the class full and classless IP addressing...
a. Explain with an example a scenario where both the class full and classless IP addressing scheme can be used to configure the IP address for the network. b. Suppose that a network has the IP network 192.168.10.0/27. Answer the following questions based on the IP arrangement. 1. Find the IP address of the second subnet. 2. Compute the number of valid hosts. 3. Find the usable IP address 4. Find the broadcast address.
Explain with an example a scenario where both the class full and classless IP addressing scheme...
Explain with an example a scenario where both the class full and classless IP addressing scheme can be used to configure the IP address for the network.
THE FOLLOWING QUESTION IS FOR C PROGRAMMING LANGUAGE Printing the decimal equivalent of a binary number....
THE FOLLOWING QUESTION IS FOR C PROGRAMMING LANGUAGE Printing the decimal equivalent of a binary number. Write a program that accepts an integer (5 digits or fewer) containing only 0s and 1s (i.e., binary) and prints out its decimal equivalent using the remainder and division operator to select the "binary" digits one at a time. Make sure your input is tested for multiple options: incorrect characters, too many, too few, etc. I need help making this program. No loops, if...
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
Implement the following socket programming in C (b) Chat Application using TCP
Implement the following socket programming in C (b) Chat Application using TCP
How does a router work? Please explain the IP addressing system.
How does a router work? Please explain the IP addressing system.
Implement a queue - C programming, please read the instruction carefully and implement queue.c using dynamic...
Implement a queue - C programming, please read the instruction carefully and implement queue.c using dynamic array structure given dynarray.h and dynarray.c below The second ADT you'll implement for this assignment is a queue. For this assignment, the interface for the queue (i.e. the structures and the prototypes of functions a user of the queue interacts with) is already defined for you in the file queue.h. Your first task in this assignment is to implement definitions for the functions that...
IP Addressing Subnet the following IP network: 160.1XY.0.0/16 (XY is the last two digits of your...
IP Addressing Subnet the following IP network: 160.1XY.0.0/16 (XY is the last two digits of your Student ID) to accommodate 5 subnets, each subnet will subsequently have 300, 180, 65, 30 and 4 PCs. For each subnet find the subnet mask, network ID, broadcast IP and valid host range and complete the below table:
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT