0% found this document useful (0 votes)
28 views9 pages

Manual 2 ND

The document discusses several key aspects of IPv6 including: - The main header fields of an IPv6 packet such as version, traffic class, flow label, payload length, next header, hop limit, source address, and destination address. - Specific header fields like version indicates IPv6, traffic class is for priority/QoS, flow label identifies packets of the same flow, payload length specifies size of payload, next header identifies subsequent headers or protocols, and hop limit limits packet hops. - IPv6 addresses are 128 bits to provide virtually unlimited unique addresses compared to 32-bit IPv4 addresses.

Uploaded by

gauravjhajharia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views9 pages

Manual 2 ND

The document discusses several key aspects of IPv6 including: - The main header fields of an IPv6 packet such as version, traffic class, flow label, payload length, next header, hop limit, source address, and destination address. - Specific header fields like version indicates IPv6, traffic class is for priority/QoS, flow label identifies packets of the same flow, payload length specifies size of payload, next header identifies subsequent headers or protocols, and hop limit limits packet hops. - IPv6 addresses are 128 bits to provide virtually unlimited unique addresses compared to 32-bit IPv4 addresses.

Uploaded by

gauravjhajharia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Bit Stuffing :

#include <stdio.h>
#include <string.h>
void bitStuffing(int N, int arr[])
{
int brr[30];
int i, j, k;
i = 0;
j = 0;
while (i < N) {
if (arr[i] == 1) {
int count = 1;
brr[j] = arr[i];
for (k = i + 1;
arr[k] == 1 && k < N && count < 5; k++) {
j++;
brr[j] = arr[k];
count++;
if (count == 5) {
j++;
brr[j] = 0;
}i = k;
}
}
else {
brr[j] = arr[i];
}
i++;
j++;
}
for (i = 0; i < j; i++)
printf("%d", brr[i]);
}
int main()
{
int N = 6;
int arr[] = { 1, 1, 1, 1, 1, 1 };
bitStuffing(N, arr);
return 0;
}

-------------------------------------------------------------------------
-------------------------------------------------------

BIT DESTUFFING

#include <stdio.h>
#include <string.h>
void bitDestuffing(int N, int arr[])
{
int brr[30];
int i, j, k;
i = 0;
j = 0;
int count = 1;
while (i < N) {
if (arr[i] == 1) {
brr[j] = arr[i];
for (k = i + 1;
arr[k] == 1
&& k < N
&& count < 5;
k++) {
j++;
brr[j] = arr[k];
count++;
if (count == 5) {
k++;
}
i = k;
}
}
else {
brr[j] = arr[i];
}
i++;
j++;
}
for (i = 0; i < j; i++)
printf("%d", brr[i]);
}
int main()
{
int N = 7;
int arr[] = { 1, 1, 1, 1, 1, 0, 1 };
bitDestuffing(N, arr);
return 0;
}
-------------------------------------------------------------------------
-----------------------------------------

BYTE STUFFING

#include <stdio.h>
#include <string.h>
void main()
{
char frame[50][50], str[50][50];
char flag[10];
strcpy(flag, "flag");
char esc[10];
strcpy(esc, "esc");
int i, j, k = 0, n;
strcpy(frame[k++], "flag");
printf("Enter length of String : \n");
scanf("%d", &n);
printf("Enter the String: ");
for (i = 0; i <= n; i++)
{
gets(str[i]);
}
printf("\nYou entered :\n");
for (i = 0; i <= n; i++)
{
puts(str[i]);
}
printf("\n");
for (i = 1; i <= n; i++)
{
if (strcmp(str[i], flag) != 0 && strcmp(str[i], esc) != 0)
{
strcpy(frame[k++], str[i]);
}
else
{
strcpy(frame[k++], "esc");
strcpy(frame[k++], str[i]);
}
}
strcpy(frame[k++], "flag");
printf("------------------------------\n\n");
printf("Byte stuffing at sender side:\n\n");
printf("------------------------------\n\n");
for (i = 0; i < k; i++)
{
printf("%s\t", frame[i]);
}
}
-------------------------------------------------------------------------
----------------------------------------------------------

HAMMING CODE

#include<stdio.h>
void main() {
int data[10];
int dataatrec[10],c,c1,c2,c3,i;
printf("Enter 4 bits of data one by one\n");
scanf("%d",&data[0]);
scanf("%d",&data[1]);
scanf("%d",&data[2]);
scanf("%d",&data[4]);
data[6]=data[0]^data[2]^data[4];
data[5]=data[0]^data[1]^data[4];
data[3]=data[0]^data[1]^data[2];

printf("\nEncoded data is\n");


for(i=0;i<7;i++)
printf("%d",data[i]);

printf("\n\nEnter received data bits one by one\n");


for(i=0;i<7;i++)
scanf("%d",&dataatrec[i]);

c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
c=c3*4+c2*2+c1 ;
if(c==0) {
printf("\nNo error while transmission of data\n");
}
else {
printf("\nError on position %d",c);
printf("\nData sent : ");
for(i=0;i<7;i++)
printf("%d",data[i]);
printf("\nData received : ");
for(i=0;i<7;i++)
printf("%d",dataatrec[i]);
printf("\nCorrect message is\n");
if(dataatrec[7-c]==0)
dataatrec[7-c]=1;
else
dataatrec[7-c]=0;
for (i=0;i<7;i++) {
printf("%d",dataatrec[i]);
}
}
}
-------------------------------------------------------------------------
-------------------------------------------------------------------------

Client sends a text and server receives and prints it.


__________________________________________

MyServer.java

import java.io.*;
import java.net.*;
public class MyServer {
public static void main(String[] args){
try{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}catch(Exception e){System.out.println(e);}
}
}

MyClient.java
import java.io.*;
import java.net.*;
public class MyClient {
public static void main(String[] args) {
try{
Socket s=new Socket("localhost",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e){System.out.println(e);}
}
}
-------------------------------------------------------------------------
---------------------------------------------

Read-Write both side


_________________

MyServer.java

import java.net.*;
import java.io.*;
class MyServer{
public static void main(String args[])throws Exception{
ServerSocket ss=new ServerSocket(3333);
Socket s=ss.accept();
DataInputStream din=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

String str="",str2="";
while(!str.equals("stop")){
str=din.readUTF();
System.out.println("client says: "+str);
str2=br.readLine();
dout.writeUTF(str2);
dout.flush();
}
din.close();
s.close();
ss.close();
}}

MyClient.java

import java.net.*;
import java.io.*;
class MyClient{
public static void main(String args[])throws Exception{
Socket s=new Socket("localhost",3333);
DataInputStream din=new DataInputStream(s.getInputStream());
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

String str="",str2="";
while(!str.equals("stop")){
str=br.readLine();
dout.writeUTF(str);
dout.flush();
str2=din.readUTF();
System.out.println("Server says: "+str2);
}

dout.close();
s.close();
}}

-------------------------------------------------------------------------
---------------------------------------------------------------------

Client Server model using UDP


___________________________

Server side

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
public class udpBaseServer_2
{
public static void main(String[] args) throws IOException
{
DatagramSocket ds = new DatagramSocket(1234);
byte[] receive = new byte[65535];
DatagramPacket DpReceive = null;
while (true)
{
DpReceive = new DatagramPacket(receive, receive.length);
ds.receive(DpReceive);
System.out.println("Client:-" + data(receive));
if (data(receive).toString().equals("bye"))
{
System.out.println("Client sent bye.....EXITING");
break;
}
receive = new byte[65535];
}
}
public static StringBuilder data(byte[] a)
{
if (a == null)
return null;
StringBuilder ret = new StringBuilder();
int i = 0;
while (a[i] != 0)
{
ret.append((char) a[i]);
i++;
}
return ret;
}
}

Client side

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;
public class udpBaseClient_2
{
public static void main(String args[]) throws IOException
{
Scanner sc = new Scanner(System.in);
DatagramSocket ds = new DatagramSocket();
InetAddress ip = InetAddress.getLocalHost();
byte buf[] = null;
while (true)
{
String inp = sc.nextLine();
buf = inp.getBytes();
DatagramPacket DpSend =
new DatagramPacket(buf, buf.length, ip, 1234);
ds.send(DpSend);
if (inp.equals("bye"))
break;
}
}
}
-------------------------------------------------------------------------
-------------------------------------------------------------------------
--------------------------------------------------------------

IPV6
_________

Version (4-bits): Indicates version of Internet Protocol which contains


bit sequence 0110.

Traffic Class (8-bits): The Traffic Class field indicates class or


priority of IPv6 packet which is similar to Service Field in IPv4 packet.
It helps routers to handle the traffic based on the priority of the
packet. If congestion occurs on the router then packets with the least
priority will be discarded.

Flow Label (20-bits): Flow Label field is used by a source to label the
packets belonging to the same flow in order to request special handling
by intermediate IPv6 routers, such as non-default quality of service or
real-time service. In order to distinguish the flow, an intermediate
router can use the source address, a destination address, and flow label
of the packets.

Payload Length (16-bits): It is a 16-bit (unsigned integer) field,


indicates the total size of the payload which tells routers about the
amount of information a particular packet contains in its payload. The
payload Length field includes extension headers(if any) and an upper-
layer packet

Next Header (8-bits): Next Header indicates the type of extension


header(if present) immediately following the IPv6 header. Whereas In some
cases it indicates the protocols contained within upper-layer packets,
such as TCP, UDP.

Hop Limit (8-bits): Hop Limit field is the same as TTL in IPv4 packets.
It indicates the maximum number of intermediate nodes IPv6 packet is
allowed to travel. Its value gets decremented by one, by each node that
forwards the packet and the packet is discarded if the value decrements
to 0. This is used to discard the packets that are stuck in an infinite
loop because of some routing error.

Source Address (128-bits): Source Address is the 128-bit IPv6 address of


the original source of the packet.

Destination Address (128-bits): The destination Address field indicates


the IPv6 address of the final destination(in most cases). All the
intermediate nodes can use this information in order to correctly route
the packet.

Extension Headers: In order to rectify the limitations of the IPv4 Option


Field, Extension Headers are introduced in IP version 6. The extension
header mechanism is a very important part of the IPv6 architecture. The
next Header field of IPv6 fixed header points to the first Extension
Header and this first extension header points to the second extension
header and so on.

-------------------------------------------------------------------------
-------------------------------------------------------------------------
--------------------------------------------------------------

IPV4
________

VERSION: Version of the IP protocol (4 bits), which is 4 for IPv4 HLEN:


IP header length (4 bits), which is the number of 32 bit words in the
header.
Type of service: Low Delay, High Throughput, Reliability (8 bits)

Total Length: Length of header + Data (16 bits), which has a minimum
value 20 bytes and the maximum is 65,535 bytes.

Identification: Unique Packet Id for identifying the group of fragments


of a single IP datagram (16 bits)

Flags: 3 flags of 1 bit each : reserved bit (must be zero), do not


fragment flag, more fragments flag (same order)

Fragment Offset: Represents the number of Data Bytes ahead of the


particular fragment in the particular Datagram. Specified in terms of
number of 8 bytes, which has the maximum value of 65,528 bytes.

Time to live: Datagram’s lifetime (8 bits), It prevents the datagram to


loop through the network by restricting the number of Hops taken by a
Packet before delivering to the Destination.

Protocol: Name of the protocol to which the data is to be passed (8 bits)

Header Checksum: 16 bits header checksum for checking errors in the


datagram header

Source IP address: 32 bits IP address of the sender


Destination IP address: 32 bits IP address of the receiver
Option: Optional information such as source route, record route. Used by
the Network administrator to check whether a path is working or not.

-------------------------------------------------------------------------
-------------------------------------------------------------------------
--------------------------------------------------------------

You might also like