Professional Documents
Culture Documents
19bce0752 VL2020210504331 Ast03
19bce0752 VL2020210504331 Ast03
19bce0752 VL2020210504331 Ast03
Communication (L23+L24)
Logical Addressing
NAME: ANSH SHARMA
REG NO:19BCE0752
08-04-2021
C++ program:
#include <string>
#include<iostream>
#include<conio.h>
#include <vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
return true;
}
string str;
cout<<str<<endl;
cin>>str;
string ans=validIPAddress(str);
cout<<ans<<endl;
return 0;
}
Output:
2) Write a program to determine the class,network
id,host id, default mask.
Ans)
C program:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
i--;
int ipAddress = 0, j = 1;
while (i >= 0)
{
ipAddress = ipAddress + (string1[i] - '0') * j;
j = j * 10;
i--;
}
else
return 'E';
}
if (ipClass == 'A')
{
int i = 0, j = 0;
while (string1[j] != '.')
network[i++] = string1[j++];
i = 0;
j++;
while (string1[j] != '\0')
host[i++] = string1[j++];
printf("Network ID is %s\n", network);
printf("Host ID is %s\n", host);
}
else if (ipClass == 'B')
{
int i = 0, j = 0, dotCount = 0;
i = 0;
j++;
else
printf("In this Class, IP address is not divided into
Network and Host ID\n");
}
int main()
{
char string1[50];
scanf("%s",string1);
char ipClass = determineClass(string1);
printf("Given IP address belongs to Class %c\n",
ipClass);
IDFinder(string1, ipClass);
if(ipClass=='A')
{
printf("Default Mask is 255.0.0.0\n");
}
else if(ipClass=='B')
{
printf("Default Mask is 255.255.0.0\n");
}
else if(ipClass=='C')
{
printf("Default Mask is 255.255.255.0\n");
}
return 0;
}
Output: