Class net and host I'd

 #include<stdio.h>

int checking(char *ip)

{

 int i=0,c=0;

 while (ip[i]!='\0')

 {

 if (ip[i]=='.')

 {

 c++;

 }

 i++;

 }

 if (c==3)

 {

 return 1;

 }

 return -1;

}

int find_class(int a,char *ip)

{

 if (a>=0&&a<=127)

 {

 printf ("%s is Belongs to Class A",ip);

 return 'A';

 }

 else if (a>=128&&a<=191)

 {

 printf ("%s is Belongs to Class B",ip);

 return 'B';

 }

 else if (a>=192&&a<=223)

 {

 printf ("%s is Belongs to Class C",ip);

 return 'C';

 }

 else if (a>=224&&a<=239)

 {

 printf ("%s is Belongs to Class D",ip);

 return 'D';

 }

 else if (a>=240&&a<=255)

 { 

 printf ("%s is Belongs to Class E",ip);

 return 'E';

 }

}

int validity(int a,int b,int c,int d)

{

 if (a<=255&&b<=255&&c<=255&&d<=255)

 {

 return 1;

 }

 else

 {

 printf ("Check the Ip Address first");

 return -1;

 }

}

void find_net_id(int a,int b,int c,int d,char clas)

{

 if (clas=='A')

 {

 printf ("\nNet Id is : \t %d",a);

 printf ("\nHost Id is : \t%d.%d.%d",b,c,d);

 }

 if (clas=='B')

 {

 printf ("\nNet Id is : \t %d.%d",a,b);

 printf ("\nHost Id is : \t%d.%d",c,d);

 }

 if (clas=='C')

 {

 printf ("\nNet Id is : \t %d.%d.%d",a,b,c);

 printf ("\nHost Id is : \t%d",d);

 }

 if (clas=='D'||clas=='E')

 {

 printf ("\nThere is No Net Id and Host Id for Class %c",clas);

 }

}

void Default_mask(char clas) 

{

 if (clas=='A')

 {

 printf ("\nDefault Mask is : \t255.0.0.0");

 }

 if (clas=='B')

 {

 printf ("\nDefault Mask is : \t255.255.0.0");

 }

 if (clas=='C')

 {

 printf ("\nDefault Mask is : \t255.255.255.0");

 }

 if (clas=='D'||clas=='E')

 {

 printf ("\nThere is No Defaut Mask for class %c",clas);

 }

}

int main()

{

 char ip[16];

 int a,b,c,d,check;

 short choice=0;

 char clas;

 while(choice<2)

 {

 printf("\n\n1] find IP class.\n");

 printf("\n2] EXIT\n");

 printf("\n enter choice=\n");

 scanf("%d",&choice);

 switch(choice)

 {

 case 1:

 printf ("\nEnter the Ip Address : \t");

 scanf("%s",ip);

 check=checking(&ip[0]);

 if (check==-1)

 {

 printf ("Check the Ip Address.");

 continue;

 }

 sscanf (ip,"%d.%d.%d.%d",&a,&b,&c,&d);

 check=validity(a,b,c,d);

 if (check==-1) 

 {

 continue;

 }

 clas=find_class(a,&ip[0]);

 find_net_id(a,b,c,d,clas);

 Default_mask(clas);

 break;

 default : printf("\n enter proper choice.");

 }

}

Comments

Popular posts from this blog

Byte stuffing sending receiving

Bit stuffing sender

Ham