CNL Exp 1-4
CNL Exp 1-4
Repeater
Hub
Switch
Bridge
Router
Gate Way
Switches have many ports, and when data arrives at any port, the
destination address is examined first and some checks are also done
and then it is processed to the devices. Different types of
communication are supported here like unicast, multicast, and
broadcast communication.
RESULT:
PROCEDURE:
PROGRAM:
A) To generate IP address
#include<stdlib.h>
int main()
{
system("C:\\Windows\\System32\\ipconfig");
return 0;
}
OUTPUT:
#include<stdio.h>
#include<conio.h>
int main()
{
FILE *input,*out;
int c, counter=0;
//Source Add
char source[]="192.168.1.1";
//Destination Add
char dest[]="192.168.1.20";
input= fopen("input.txt","r");
out=fopen("output.txt","w");
if(input==NULL)
fclose(out);
return 0;
}
}
INPUT:
OUTPUT:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp1, *fp2, *fopen();
int i;
char c,cnt=49;
fp1 = fopen("input.txt","r");
// open for reading
fp2 = fopen("output.txt","w") ;
//open for writing
if ( fp1 == NULL )
{
printf("Cannot open input.txt." );
exit(1);
}
else if ( fp2 == NULL )
{
printf("Cannot open output.txt.");
exit(1);
}
else
{
c = getc(fp1) ;
while ( c != EOF)
{
putc(cnt++,fp2); # display on standard output or
write into a file (putc).
INPUT:
OUTPUT:
RESULT:
1. Fixed size – The frame is of fixed size and there is no need to provide
boundaries to the frame, length of the frame itself acts as delimiter.
PROGRAM:
CHARACTER COUNT
#include <stdio.h>
#include <string.h>
int main()
{
char str[50];
int i=0, chr=0;
printf("\nEnter Your String: ");
gets(str);
// The gets() function enables
the user to enter some
characters followed by the enter
key.
OUTPUT:
int main()
{
char *p,*q;
char in[MAXSIZE];
char stuff[MAXSIZE];
char destuff[MAXSIZE];
int count=0;
printf("Enter the input character string (0 & 1 only):\n");
scanf("%s",in);
p=in;
q=stuff;
while(*p!='\0')
{
if(*p=='0')
{
*q=*p;
q++;
p++;
}
else
{
while(*p=='1' && count!=3)
{
count++;
*q=*p;
q++;
p++;
}
if(count==3)
{
*q='0';
p=stuff;
q=destuff;
while(*p!='\0')
{
if(*p=='0')
{
*q=*p;
q++;
p++;
}
else
{
while(*p=='1' && count!=3)
{
count++;
*q=*p;
q++;
p++;
}
if(count==3)
{
p++;
}
count=0;
}
}
*q='\0';
printf("\nThe destuffed character string is:"); printf("\n%s\
n",destuff);
return 0;
}
For the IP addresses from Class A, the first 8 bits (the first decimal
number) represent the network part, while the remaining 24 bits represent the
host part. For Class B, the first 16 bits (the first two numbers) represent the
network part, while the remaining 16 bits represent the host part. For Class
C, the first 24 bits represent the network part, while the remaining 8 bits
represent the host part.
PROGRAM:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int i=0;
int ip=0;
char str[100];
printf("Enter IP Address (xxx.xxx.xxx.xxx): ");
gets(str);
while(str[i]!='.')
{ // The atoi() function converts a character string to an integer value
ip=atoi(str);
i++ ;
}
if(ip>=1 && ip<=127)
{
printf("class is A ");
OUTPUT: