Download File

bluegooseexchangeΔίκτυα και Επικοινωνίες

26 Οκτ 2013 (πριν από 3 χρόνια και 11 μήνες)

115 εμφανίσεις

Computer Department 5
th

Semester

1

Government Engineering College, Rajkot



Index




Sr.N
o

Title

Page No

Date

Sign

1

Tutorial
-
1
Computer
Networking

2



2

Tutorial
-
2

11



3

Tutorial
-
3

17



4

Tutorial
-
4

25



5

Tutorial
-
5

32








Computer Department 5
th

Semester

2

Government Engineering College, Rajkot



Tutorial
-
1
COMPUTER NETWORK

INTRODUCTION

A computer network is a collection of computers and
devices connected
to each other. The network allows computers to communicate with each other
and share resources and information. The Advanced Research Projects Agency
(
ARPA
) designed "Advanced
Research Projects Agency Network" (
ARPANET
) for
the United States Department of Defense. I t was the first computer network in
the world in late 1960s and early 1970s.

NETWORK CLASSIFICATION

The following list presents categories used for classifying networks.

CONNECTION METHOD

Computer networks can also be classified according to the hardware and
software technology that is used to interconnect the individual devices in the
network, such as
Optical fiber
,
Ethernet
,
Wireless
LAN
,
HomePNA
,
Power line
communication

or
G.hn
.



Ethernet uses physical wiring to connect devices. Frequently deployed
devices include hubs, switches, bridges and/or routers.



Wireless LAN technology is designed to connect devices without wiring.
These devices use
radio waves

or
infrared

signals as a transmission
medium.



I TU
-
T
G.hn

technology uses existing home wiring (
coaxial cable
, phone
lines and
power lines
) to create a high
-
speed (up to 1 Gigabit/s) local
area network.

SCALE

Networks are often classified as



Local Area Network
(LAN)
,



Wide Area Network
(WAN)
,



Metropolitan Area Network
(MAN)
,



Personal Area Network
(PAN)
,



Virtual Private Network
(VPN)
,



Campus Area Network
(CAN)
,



Storage Area Network
(SAN)
, etc.

Computer Department 5
th

Semester

3

Government Engineering College, Rajkot



This classification depending on their scale, scope and purpose.

Usage,
trust levels and access rights often differ between these types of network
-

for
example, LANs tend to be designed for internal use by an organization's internal
systems and employees in individual physical locations (such as a building),
while WAN
s may connect physically separate parts of an organization to each
other and may include connections to third parties.

FUNCTIONAL RELATIONSHIP (NETWORK ARCHITECTURE)

Computer networks may be classified according to the functional
relationships which exist
among the elements of the
network
, e.g.,
Active
Networking
,
Client
-
server

and
Peer
-
to
-
peer

(workgroup) architecture.

NETWORK TOPOLOGY

Computer networks may be classified according to the
network topology

upon which the network is based, such as
bus network
,
star network
,
ring
network
,
mesh network
,
st
ar
-
bus network
,
tree or hierarchical topology network
.
Network topology signifies the way in which devices in the network see their
logical relations
to one another. The use of the term "logical" here is significant.
That is, network topology is independent of the "physical" layout of the network.
Even if networked computers are physically placed in a linear arrangement, if
they are connected via a hub,

the network has a Star topology, rather than a
bus topology. I n this regard the visual and operational characteristics of a
network are distinct; the logical network topology is not necessarily the same as
the physical layout. Networks may be classified b
ased on the method of data
used to convey the data, these include digital and analog networks.

TYPES OF NETWORKS

Below is a list of the most common types of computer networks in order of scale.

PERSONAL AREA NETWORK

A
personal area network (PAN)

is a computer network used for
communication among computer devices close to one person. Some examples
of devices that are used in a PAN are printers, fax machines, telephones, PDAs
and scanners. The reach of a PAN is typically about 20
-
30 feet (approxima
tely 6
-
9 meters), but this is expected to increase with technology improvements.

LOCAL AREA NETWORK

Computer Department 5
th

Semester

4

Government Engineering College, Rajkot



A
local area network (LAN)

is a computer network covering a small
physical area, like a home, office, or small group of buildings, such as a school,
or an a
irport. Current wired LANs are most likely to be based on
Ethernet

technology, although new standards like
I TU
-
T
G.hn

also provide a way to create
a wired LAN using existing home wires (coaxial cables, phone lines and power
lines.

For example, a library may have a wired or wireless LAN for users to
interconnect local devi
ces (e.g., printers and servers) and to connect to the
internet. On a wired LAN, PCs in the library are typically connected by
category
5 (Cat5) cable
, running the I EEE 802
.3 protocol through a system of
interconnected devices and eventually connect to the I nternet. The cables to
the servers are typically on Cat 5e enhanced cable, which will support I EEE 802.3
at 1 Gbit/s. A wireless LAN may exist using a different I EEE prot
ocol, 802.11b,
802.11g or possibly 802.11n. The staff computers (bright green in the figure) can
get to the color printer, checkout records, and the academic network
and

the
I nternet. All user computers can get to the I nternet and the card catalog. Each
wo
rkgroup can get to its local printer. Note that the printers are not accessible
from outside their workgroup.



Typical library network, in a branching tree topology and controlled
access to resources

All interconnected devices must understand the network layer (layer 3),
because they are handling multiple subnets (the different colors). Those inside
the library, which have only 10/100 Mbit/s Ethernet connections to the user
device and a Gigabit Etherne
t connection to the central router, could be
called "layer 3 switches" because they only have Ethernet interfaces and must
understand
I P
. I t would be more correct to call

them access routers, where the
router at the top is a distribution router that connects to the I nternet and
academic networks' customer access routers.

The defining characteristics of LANs, in contrast to WANs (wide area
networks), include their higher da
ta transfer rates, smaller geographic range,
and lack of a need for leased telecommunication lines. Current Ethernet or
other
I EEE 802.3

LAN technologies operate at speeds up to 10 Gbi
t/s. This is the
Computer Department 5
th

Semester

5

Government Engineering College, Rajkot



data transfer rate.
I EEE

has projects investigating the standardization of 100
Gbit/s, and possibly 400 Gbit/s.

CAMPUS AREA NETWORK

A
campus area network

(CAN) is a computer netwo
rk made up of an
interconnection of local area networks (LANs) within a limited geographical
area. I t can be considered one form of a metropolitan area network, specific to
an academic setting.

I n the case of a university campus
-
based campus area network,
the
network is likely to link a variety of campus buildings including; academic
departments, the university library and student residence halls. A campus area
network is larger than a local area network but smaller than a wide area
network (WAN) (in some c
ases).

The main aim of a campus area network is to facilitate students accessing
internet and university resources. This is a network that connects two or more
LANs but that is limited to a specific and contiguous geographical area such as
a college campus
, industrial complex, office building, or a military base. A CAN
may be considered a type of MAN (metropolitan area network), but is generally
limited to a smaller area than a typical MAN. This term is most often used to
discuss the implementation of netwo
rks for a contiguous area. This should not be
confused with a
Controller Area Network
. A LAN connects network devices over
a relatively short distance. A networked office building, school, or home usually
contains a single LAN, though sometimes one building will contain a few small
LANs (perhaps one per room), and occasionally a LAN will s
pan a group of
nearby buildings. I n
TCP/I P

networking, a LAN is often but not always
implemented as a single I P subnet.

METROPOLITAN AREA NETWORK

A
metropolitan area network

(MAN)
is a network that connects two or
more local area networks or campus area networks together but does not
extend beyond the boundaries of the immediate town/city. Routers, switches
and hubs are connected to create a metropolitan area network.

WIDE AREA NETW
ORK

A
wide area network

(WAN) is a computer network that covers a broad
area (i.e. any network whose communications links cross metropolitan, regional,
or national boundaries [1]). Less formally, a WAN is a network that uses routers
and public communicatio
ns links [1]. Contrast with personal area networks
(PANs), local area networks (LANs), campus area networks (CANs), or
Computer Department 5
th

Semester

6

Government Engineering College, Rajkot



metropolitan area networks (MANs), which are usually limited to a room,
building, campus or specific metropolitan area (e.g., a city) res
pectively. The
largest and most well
-
known example of a WAN is the I nternet. A WAN is a data
communications network that covers a relatively broad geographic area (i.e.
one city to another and one country to another country) and that often uses
transmissio
n facilities provided by common carriers, such as telephone
companies. WAN technologies generally function at the lower three layers of
the
OSI reference model
: the
physical layer
, the
data link layer
, and the
network
layer
.

GLOBAL AREA NETWORK

A
global area networks (GAN)

specification is in development by several
groups, and there is no common definition. I n general, however, a GAN is a
model for supporting mobile communications across an arbitrary num
ber of
wireless LANs, satellite coverage areas, etc. The key challenge in mobile
communications is "handing off" the user communications from one local
coverage area to the next. I n I EEE Project 802, this involves a succession of
terrestrial
WI RELESS local area networks (WLAN)
.
[3]

VIRTUAL PRIVATE NETWORK

A
virtual private netw
ork (VPN)

is a computer network in which some of
the links between nodes are carried by open connections or virtual circuits in
some larger network (e.g., the I nternet) instead of by physical wires. The link
-
layer protocols of the virtual network are said
to be tunneled through the larger
network when this is the case. One common application is secure
communications through the public I nternet, but a VPN need not have explicit
security features, such as authentication or content encryption. VPNs, for
exampl
e, can be used to separate the traffic of different user communities over
an underlying network with strong security features.

A VPN may have best
-
effort performance, or may have a defined service
level agreement (SLA) between the VPN customer and the VPN
service
provider. Generally, a VPN has a topology more complex than point
-
to
-
point.

A VPN allows computer users to appear to be editing from an I P address
location other than the one which connects the actual computer to the
I nternet.

INTERNETWORK

I nternet
working

involves connecting two or more distinct computer
networks or network segments via a common routing technology. The result is
Computer Department 5
th

Semester

7

Government Engineering College, Rajkot



called an internetwork (often shortened to internet). Two or more networks or
network segments connected using devices tha
t operate at layer 3 (the
'network' layer) of the OSI Basic Reference Model, such as a router. Any
interconnection among or between public, private, commercial, industrial, or
governmental networks may also be defined as an internetwork.

I n modern practice
, the interconnected networks use the I nternet
Protocol. There are at least three variants of internetwork, depending on who
administers and who participates in them:



I ntranet



Extranet



I nternet

I ntranets and extranets may or may not have connections to the

I nternet.
I f connected to the I nternet, the intranet or extranet is normally protected from
being accessed from the I nternet without proper authorization. The I nternet is
not considered to be a part of the intranet or extranet, although it may serve as
a
portal for access to portions of an extranet.

(1)
Intranet

An
intranet

is a set of networks, using the
I nternet Protocol

and I P
-
based tools such as web browsers and file transfer applications, that is
under the control of a single administrative entity. That administrative
entity closes the intranet to all but specific, authorized users. Most
commonly, an intranet is the in
ternal network of an organization. A large
intranet will typically have at least one web server to provide users with
organizational information.

(2)
Extranet

An
extranet

is a network or internetwork that is limited in scope to a
single organization or enti
ty but which also has limited connections to the
networks of one or more other usually, but not necessarily, trusted
organizations or entities (e.g., a company's customers may be given
access to some part of its intranet creating in this way an extranet, w
hile
at the same time the customers may not be considered 'trusted' from a
security standpoint). Technically, an extranet may also be categorized as
a CAN, MAN, WAN, or other type of network, although, by definition, an
extranet cannot consist of a single
LAN; it must have at least one
connection with an external network.

(3)
Internet

Computer Department 5
th

Semester

8

Government Engineering College, Rajkot



The I nternet is a specific internetwork. I t consists of a worldwide
interconnection of governmental, academic, public, and private
networks based upon the networking technologi
es of the
I nternet Protocol
Suite
. I t is the successor of the
Advanced Research Projects Age
ncy
Network

(ARPANET) developed by
DARPA

of the
U.S. Department of
Defense
. The I nternet is also the communications backbone underlying
the
World Wide Web

(WWW). The 'I nternet'

is most commonly spelled with
a capital 'I' as a proper noun, for historical reasons and to distinguish it
from other generic internetworks.

Participants in the I nternet use a diverse array of methods of several
hundred documented, and often standardized,

protocols compatible
with the
I nternet Protocol Suite

and an addressing system (
I P Ad
dresses
)
administered by the
I nternet Assigned Numbers Authority

and
address
registries
. Service providers and large enterprises exchange information
about the
reach ability

of their address spaces through the
Border
Gateway Protocol

(BGP), forming a redundant worldwide mesh of
transmission paths.

BASIC HARDWARE COMPONENTS

All networks are made up of basic hardware building blocks to
interconnect network
nodes
, such as Network I nterface Cards (NI Cs), Bridges,
Hubs, Switches, and Routers
. I n addition, some method of connecting these
building blocks is required, usually in the form of galvanic cable (most commonly
Category 5 cable
). Less common are microwav
e links (as in
I EEE 802.12
) or
optical cable ("
optical fiber
"). An Ethernet card may also be required.


NETWORK INTERFACE CARDS

A
network card
,
network adapter

or
NI C

(network interface card) is a
piece of
computer hardware

designed to allow computers to communicate
over a
computer network
. I t provides physical access to a networking medium
and often provides a low
-
level addressing system through the use of
MAC
addresses
.

REPEATERS

A
repeater

is an
electronic

device that receives a
signal

and
retransmits

it
at a higher power level, or to the other side of an obstruction, so that the signal
can cover longer distances without degradation. I n most twisted pair Ethernet
Computer Department 5
th

Semester

9

Government Engineering College, Rajkot



configura
tions, repeaters are required for cable which runs longer than 100
meters.

HUBS

A hub contains multiple ports. When a packet arrives at one port, it is
copied unmodified to all ports of the hub for transmission. The destination
address in the frame is not
changed to a broadcast address.

BRIDGES

A
network bridge

connects multiple
network segments

at the
data link
layer

(layer 2) of the
OSI model
. Bridges do not promiscuously copy traffic to all
ports, as hubs do, but learn which
MAC addresses

are reachable through
specific ports. Once the bridge associates a port and an address, it will send
traffic for that address only to that port. Bridges do send broadcasts to all ports
except the one on which the broad
cast was received.

Bridges learn the association of ports and addresses by examining the
source address of frames that it sees on various ports. Once a frame arrives
through a port, its source address is stored and the bridge assumes that MAC
address is as
sociated with that port. The first time that a previously unknown
destination address is seen, the bridge will forward the frame to all ports other
than the one on which the frame arrived.

Bridges come in three basic types:

1.

Local bridges: Directly connect
local area networks (LANs)

2.

Remote bridges: Can be used to create a wide area network (WAN)
link between LANs. Remote bridges, where the connecting link is slower
than the end networks, largely have been replaced by routers.

3.

Wireless bridges: Can be used to

join LANs or connect remote stations
to LANs.


SWITCHES

switch is a device that forwards and filters
OSI layer 2
datagrams

(chunk of
data communication) between ports (connected cables) based on the MAC
addresses in the packets.
[5]

This is distinct from a hub in that it only forwards the
packets to the ports involved in the communications rather than all ports
connected. Strictly speaking, a switch is not capable of routing traffic based on
I P address (OSI Layer 3) which is necessar
y for communicating between network
Computer Department 5
th

Semester

10

Government Engineering College, Rajkot



segments or within a large or complex LAN. Some switches are capable of
routing based on I P addresses but are still called switches as a marketing term. A
switch normally has numerous ports, with the intention being that

most or all of
the network is connected directly to the switch, or another switch that is in turn
connected to a switch.
[6]

Switch is a marketing t
erm that encompasses routers and bridges, as well
as devices that may distribute traffic on load or by application content (e.g., a
Web
URL

identifier). Swi
tches may operate at one or more
OSI model

layers,
including
physical
,
data link
,
network
, or
transport (i.e., end
-
to
-
en
d)
. A device
that operates simultaneously at more than one of these layers is called a
multilayer switch
.

Overemphasizing the ill
-
defined term "switch" often leads to
confusion
when first trying to understand networking. Many experienced network designers
and operators recommend starting with the logic of devices dealing with only
one protocol level, not all of which are covered by OSI. Multilayer device
selection is an

advanced topic that may lead to selecting particular
implementations, but multilayer switching is simply not a real
-
world design
concept.

ROUTERS

Routers

are networking devices that forward data packets between
networks using headers and forwarding tables

to determine the best path to
forward the packets. Routers work at the
network layer
.

Computer Department 5
th

Semester

11

Government Engineering College, Rajkot



Tutorial
-
2

1:

Write a program to implement encryption & decryption using addition.

#include<conio.h>

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

char * encrypt(char [],char []);

char * decrypt(char [],char []);



void main()

{

char data[50],key[50],key1[50],*en,*dc;

clrscr();


printf("
----------------
ENCRYPTION
---------------
");

printf("
\
n ***Enter String:
-
");

gets(data);

printf("
\
n ***Enter Key:
-
");

gets(key);

strcpy(key1,key);

en=encrypt(data,key);

printf("
\
n***Encrypted Data:
-
%s",en);

printf("
\
n
\
n
----------------
DECRYPTION
---------------
");

dc=decrypt(en,key1);

printf(
"
\
n****decrypted Data:
-
%s",dc);

getch();

}

char * encrypt(char data[],char key1[])

{


intclm,row,i,j,k=0,l,mat[6][6],inp[20],temp,z,pos;


char *enc;



clm=strlen( key1 );


row = strlen(data)/strlen(key1);


i=strlen(data)%strlen(key1);


if(i!=0)



{



row++
;



}



printf("
\
n
\
n ** Number of row is %d
\
n ** Number of column is %d
\
n ",row , clm);





for(i=0;i<row;i++)



{

Computer Department 5
th

Semester

12

Government Engineering College, Rajkot





for(j=0;j<clm;j++)




{




mat[i][j]=data[k];




k++;




if(mat[i][j] == '
\
0')





{





mat[i][j] = '_';





}




}



}


printf(
"
\
n
\
n::::::::::MATRIX:::::::::::
\
n
\
n");


for(l=0;l<clm;l++)



{



inp[l] = l;



printf("%c
\
t",key1[l]);



}


printf("
\
n");


printf("
------------------------------
\
n");


for(i=0;i<row;i++)



{



for(j=0;j<clm;j++)




{



printf("%c
\
t", mat[i][j]);




}



pr
intf("
\
n");



}


for(i=clm
-
1;i>0;i
--
)



{


for(j=0;j<i;j++)



{


if(key1[j]>key1[j+1])





{




z=key1[j];



key1[j]=key1[j+1];



key1[j+1]=z;



temp=inp[j];



inp[j]=inp[j+1];



inp[j+1]=temp;



}



}


}



puts(key1);



enc= (char *)
malloc (sizeof(char)*(row*clm+1));




l=0;



k=0;



for(j=0;j<clm;j++)


{

Computer Department 5
th

Semester

13

Government Engineering College, Rajkot





pos=inp[k];



k++;




for(i=0;i<row;i++)



{




enc[l] = mat[i][pos];




l++;



}



}


enc[l] = '
\
0';



returnenc;


}




char * decrypt(char data[],char key1[])

{


intclm,row,i,j,k
=0,l=0,inp[15],temp,m;


char *dec,z,mat[6][6];



printf("
\
n
\
nEncry data:
-
");


puts(data);



clm=strlen( key1 );


row = strlen(data)/strlen(key1);


i=strlen(data)%strlen(key1);


if(i!=0)



{



row++;



}


printf("
\
n
\
n");


for(l=0;l<clm;l++)



{



inp[l] = l
;



printf("%c
\
t",key1[l]);



}


for(i=clm
-
1;i>0;i
--
)



{


for(j=0;j<i;j++)



{


if(key1[j]>key1[j+1])



{




z=key1[j];



key1[j]=key1[j+1];



key1[j+1]=z;



temp=inp[j];



inp[j]=inp[j+1];



inp[j+1]=temp;

Computer Department 5
th

Semester

14

Government Engineering College, Rajkot





}



}


}



l=0;



k=0;



for(m=0;m<clm;m++)


{



j=inp[k];



k++;



for(i=0;i<row;i++)



{




if(data[l] == '_')




{





mat[i][j] = ' ';





l++;





}




else




{





mat[i][j] = data[l];





l++;




}




}



}




dec = (char *) malloc (sizeof(char)*(row*clm+1));


l=0;


for(
i=0;i<row;i++)


{



for(j=0;j<clm;j++)



{




dec[l] = mat[i][j];




l++;



}


}


dec[l] = '
\
0';



returndec;

}




Computer Department 5
th

Semester

15

Government Engineering College, Rajkot



2
:
Write a program to implement encryption
&
decryption

using

X
-
OR


#include<stdio.h>

#include<conio.h>

void main()

{



int i;


char

a[10],b[10];


clrscr();


printf("Eneter any string for encryption:
-
");


scanf("%s",&a);


for(i=0;i<10 ;i++)


{



if(a[i] != '
\
0')



{




a[i]=a[i]^1;




}


}


printf("After encryption ur string is:
-

%s",a);


for(i=0;i<10 ;i++)


{



if(a[i] != '
\
0')



{




a[i]=a[i]^1;




}


}


printf("
\
n After decryption ur string is:
-

%s",a);




getch();

}

Computer Department 5
th

Semester

16

Government Engineering College, Rajkot



3
:
Write a program to implement encryption &
decryption

using Transposition

#include<stdio.h>

#include<conio.h>

void main()

{



int i;


char a[10],b[10];


clrscr();


printf("Eneter any string for encryption:
-
");


scanf("%s",&a);


for(i=0;i<10 ;i++)


{



if(a[i] != '
\
0')



{




a[i]=a[i]+1;




}


}


printf("After encryption ur string is:
-

%s",a);


for(i=0;i<10 ;i++)


{



if(a[i] != '
\
0')



{




a[i]=a[i]
-
1;




}


}


printf("
\
n After decryption ur string is:
-

%s",a);




getch();

}




Computer Department 5
th

Semester

17

Government Engineering College, Rajkot



Tutorial
-
3

1.Write a program to implement
Simplex
communication

Programm
-
1: Simplex(
sender
)

#include <bios.h>

#include <conio.h>

#define COM1 0

#define DATA_READY 0x100

#define TRUE

1

#define FALSE 0

#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)

//This program initializes the com1 port and then keeps on sending the

// ASCII of pressed key on that until user presses Esc key


int main(void)

{

int in, out, status, DONE =
FALSE,flag=0;

clrscr();

bioscom(0, SETTINGS, COM1);

cprintf("... BIOSCOM [ESC] to exit ...
\
n");

while (!DONE)


{


status = bioscom(3, 0, COM1);


if (status & DATA_READY)


{



//Checks whether any key is pressed


or not



if (kbhit())



{




//If pres
sed then stores its ASCII


in 'in' variable




//and compares it with ASCII of


Esc. If same then




//comes out of infinite loop



if ((in = getch()) == '
\
x1B')




DONE = TRUE;




//Else the pressed key ASCII is


sent to com1 port



bios
com(1,in,COM1);



}


}


}

return 0;

}

Computer Department 5
th

Semester

18

Government Engineering College, Rajkot



Programm
-
2
:
Simplex(
r
eceiver
)

#include <bios.h>

#include <conio.h>


//COM1 is defined as a constant for port com1 with id 0

#define COM1 0


//DATA_READY is defined as a constant for checking status
000100000000

//Here 1 is set for the bit corresponding to data ready

#define DATA_READY 0x100


#define TRUE 1

#define FALSE 0


/*
for initialization,
no. of character
s,baud rate,no. of start
-
stop
b
itsare to be set. For this XOR of them is assigned

to SETTINGS
constant
*/

#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)



/
*
After initialization, this program keeps on receiving one by one
charaterand displays on the screen until the user presses Esc.
*/


int main(void)

{

int in, out, status, DONE = FALSE,
flag=0;

clrscr();



//Initializes port COM1 with command 0 and setting options SETTINGS

bioscom(0, SETTINGS, COM1);



//Instructs users to press Esc to terminate communication

cprintf("... BIOSCOM [ESC] to exit ...
\
n");



//sets an infinite loop

while (!DONE)


{


//receives status of com1 and stores in variable 'status'


status = bioscom(3, 0, COM1);


//ANDs status with DATA_READY to check whether com1 port is ready or
//
not


if (status & DATA_READY)




/
*
receives 7 or 8 bits character in variab
le 8as SETTINGS
specifies 7 bit character, content of out isANDed with 0111 1111 to
separate 7 bits of charactersand checked whether its 0 or not

*/



if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)





//If not 0, then the character is displayed

Computer Department 5
th

Semester

19

Government Engineering College, Rajkot






putch(out
);




//Checkes whether any key is pressed



if (kbhit())



{




//if pressed then, its ASCII is stored in 'in' variable




//and if it is of Esc then comes out of infinite loop



if ((in = getch()) == '
\
x1B')




DONE = TRUE;



}


}


return 0;

}



Computer Department 5
th

Semester

20

Government Engineering College, Rajkot



2.Write a program to implement
Half Duplex
communication

Programm
-
3
:
Half Duplex(
sender
)

#include <bios.h>

#include <conio.h>


#define COM1 0

#define DATA_READY 0x100

#define TRUE 1

#define FALSE 0


#define SETTINGS ( 0x80 | 0x02 | 0x0
0 | 0x00)


//This program can do data transmission and reception, but not both at

//
the
same time. Depending upon flag tr value does either of them at.

//
a time
Keeps on switching between two until Esc is pressed.


int main(void)

{

int

in, out, status, DONE = FALSE;



//Takes tr variable as flag that represents the kind of operation


//
to be
performed. If 0 then sending, if 1 then receiving.


//Initialized to 1, so starts with receiving

inttr=1;


bioscom(0, SETTINGS, COM1);

cprintf("... BIOSCOM [ESC] to exit ...
\
n");

while (!DONE)


{

if(tr==1)


{


status = bioscom(3, 0, COM1);

if (status & DATA_READY)


if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)



{



putch(out);



if(out=='D')



tr=0;



}


}


if(tr==0)



{


if (kbhit())



{


if((in = getch())=='
\
x1B')



DONE=TRUE;


Computer Department 5
th

Semester

21

Government Engineering College, Rajkot




bioscom(1, in, COM1);


if(in=='D')



tr=1;



}


}


}

return 0;

}



Computer Department 5
th

Semester

22

Government Engineering College, Rajkot



Programm
-
4
:
Half Duplex
(
receiver
)


#include <bios.h>

#include <conio.h>


#define COM1 0

#define
DATA_READY 0x100

#define TRUE 1

#define FALSE 0


#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)


//This program can do data transmission and reception, but not both at
the

//same time. Depending upon flag tr value does either of them at a
time.

/
/Keeps on switching between two until Esc is pressed.


int main(void)

{

int in, out, status, DONE = FALSE;



//Takes tr variable as flag that represents the kind of operation
to be


//performed. If 0 then sending, if 1 then receiving.


//Initialized
to 0, so starts with sending

inttr=0;


bioscom(0, SETTINGS, COM1);

cprintf("... BIOSCOM [ESC] to exit ...
\
n");

while (!DONE)


{


//Does receiving operation until 'D' character is received. Then


//switches to sending by setting tr to 0.

if(tr==1)


{


status = bioscom(3, 0, COM1);

if (status & DATA_READY)


if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)



{



putch(out);



if(out=='D')



tr=0;



}


}



//Does sending operation until 'D' character is pressed and sent.
Then


//swit
ches to receiving by setting tr to 1.

Computer Department 5
th

Semester

23

Government Engineering College, Rajkot




if(tr==0)


{


if (kbhit())



{


if((in = getch())=='
\
x1B')



DONE=TRUE;



bioscom(1, in, COM1);


if(in=='D')



tr=1;



}


}


}

return 0;

}



Computer Department 5
th

Semester

24

Government Engineering College, Rajkot



3.Write a program to implement
Full Duplex
communication

Programm
-
4
:
Full Duplex


#include <bios.h>

#include <conio.h>


#define COM1 0

#define DATA_READY 0x100

#define TRUE 1

#define FALSE 0


#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)


//This program does both transmission and reception operations
parallely.

//Receives one character, displays it. Then presses a key and sends
its

//ASCII. Repeates this until Esc is pressed.


int main(void)

{

int in, out, status, DONE = FALSE;


bioscom(0,
SETTINGS, COM1);

cprintf("... BIOSCOM [ESC] to exit ...
\
n");

while (!DONE)


{

status = bioscom(3, 0, COM1);

if (status & DATA_READY)

if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)

putch(out);

if (kbhit())


{

if ((in = getch()) == '
\
x1B')



DONE = TRUE;


bioscom(1, in, COM1);


}


}

return 0;

}



Computer Department 5
th

Semester

25

Government Engineering College, Rajkot



Tutorial
-
4

1.Write a program to implement file transfer

Programm
-
1
:
File Transfer(
read
)


#include <bios.h>

#include <conio.h>

#include<stdio.h>



#define COM1 0

#define DATA_READY

0x100

#define TRUE 1

#define FALSE 0


#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)


void main(void)

{

int status;

char in;


FILE *fp;

fp=fopen("d:
\
\
ab.txt","r");


if(fp==NULL)

printf("Unable to open");


bioscom(0, SETTINGS, COM1);


while(!fe
of(fp))


{


in=getc(fp);


putch(in);


bioscom(1, in, COM1);


if(in==EOF)


break;




}

printf("File transfered");

in=EOF;

bioscom(1,in,COM1);


}



Computer Department 5
th

Semester

26

Government Engineering College, Rajkot



Programm
-
2
:
File Transfer(
write
)

#include <bios.h>

#include <conio.h>

#include<stdio.h>


#define COM1

0

#define DATA_READY 0x100

#define TRUE 1

#define FALSE 0


#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)


void main(void)

{

int status;


FILE *fp;

char out;


fp=fopen("d:
\
\
hello1.txt","w");

if(fp==NULL)

printf("can not open file");


bioscom
(0, SETTINGS, COM1);

while (fp!=NULL)


{


if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)



{






if(out==EOF)



break;.




putc(out,fp);



}




}

getch();

}



Computer Department 5
th

Semester

27

Government Engineering College, Rajkot



2
.Write a program to implement file transfer enc
ryption

&
decryption

Programm
-
3
:
File

Transfer(
encode
)


#include <bios.h>

#include <conio.h>

#include<stdio.h>



#define COM1 0

#define DATA_READY 0x100

#define TRUE 1

#define FALSE 0


#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)


void main(void)

{

int status;

char in;


FILE *fp;

fp=fopen("d:
\
\
ab.txt","r");


if(fp==NULL)

printf("Unable to open");


bioscom(0, SETTINGS, COM1);


while(!feof(fp))


{


in=getc(fp);


putch(in+3);


bioscom(1, in, COM1);


if(in==EOF)


break;




}



}



Computer Department 5
th

Semester

28

Government Engineering College, Rajkot



Programm
-
4
:
File Transfer(
decode
)

#include <bios.h>

#include <conio.h>

#include<stdio.h>


#define COM1 0

#define DATA_READY 0x100

#define TRUE 1

#define FALSE 0


#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)


void main(void)

{

int status;


FILE *fp;

char out;


fp=fopen
("d:
\
\
hello1.txt","w");

if(fp==NULL)

printf("can not open file");


bioscom(0, SETTINGS, COM1);

while (fp!=NULL)


{


if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)



{






if(out==EOF)



break;.




putc(out
-
3,fp);



}




}

getch();

}



Computer Department 5
th

Semester

29

Government Engineering College, Rajkot



3.Write

a program to implement
Bit stuffing

method

Programm
-
5
:
Bit Stuff

// bit stuffing & destuffing

// flag is 0111 1110


void main()


{


char str[100],stuff[200]="01111110 ",destff[200];


int i,j,count=0,flag=1;


clrscr();


printf("
\
n enter bit stream : ");


scanf("%s",str);



// stuffing



i=9;j=0;


while(str[j] != '
\
0')



{



stuff[i]=str[j];



i++;



if(str[j]=='1')




{




count++;




}



else




{




count=0;




}

Computer Department 5
th

Semester

30

Government Engineering College, Rajkot





if(count==5)




{




stuff[i]='0';




i++;




count=0;




}



j++;



}



strcat(stuff," 01111110");



printf("stuffed string is : %s",stuff);




// destuffing




i=9;j=0;



count=0;



while(flag)



{



if(stuff[i]=='0' && stuff[i+1]=='1' && stuff[i+2] == '1'&&




stuff[i+3]=='1' && stuff[i+4]=='1' && stuff[i+5]=='1' &&




stuff[i+6]=='1' && stuff[i+7]=='0')




{




flag=0;




goto out;




}



destff[j]=stuff[i];



j++;




if(stuff[i]=='1')




{

Computer Department 5
th

Semester

31

Government Engineering College, Rajkot






count++;




}



else




{




count=0;




}



if(count==5)




{




i=i+1;




count=0;




}



i=i+1;



out:



}



destff[j]='
\
0';



printf("
\
n destuffed string is : %s ",destff);




getch();



}



Computer Department 5
th

Semester

32

Government Engineering College, Rajkot



Tutorial
-
5

1
.
Explain color code scheme for cross & straight through connection

The TI A/EI A 568
-
A standard which was ratified in 1995, was replaced by the
TI A/EI A
568
-
B standard in 2002 and has been updated since. Both standards
define the T
-
568A and T
-
568B pin
-
outs for using Unshielded Twisted Pair cable
and RJ
-
45 connectors for Ethernet connectivity. The standards and pin
-
out
specification appear to be related and

interchangeable, but are not the same
and should not be used interchangeably.

T
-
568B Straight
-
Through Ethernet Cable



Both the T
-
568A and the T
-
568B standard Straight
-
Through cables are used most
often as patch cords
for your Ethernet connections. I f you require a cable to
connect two Ethernet devices directly together without a hub or when you
connect two hubs together, you will need to use a Crossover cable instead.

RJ
-
45 Crossover Ethernet Cable




Computer Department 5
th

Semester

33

Government Engineering College, Rajkot



A good way of remembering how to wire a Crossover Ethernet cable is to wire
one end using the T
-
568A standard and the other end using the T
-
568B standard.
Another way of remembering the color coding is to simply switch the Green set
of
wires in place with the Orange set of wires. Specifically, switch the solid Green
(G) with the solid Orange, and switch the green/white with the orange/white.

Ethernet Cable Instructions:

1.

Pull the cable off the reel to the desired length and cut. I f you ar
e pulling
cables through holes, its easier to attach the RJ
-
45 plugs after the cable is
pulled. The total length of wire segments between a PC and a hub or
between two PC's cannot exceed 100 Meters (328 feet) for 100BASE
-
TX
and 300 Meters for 10BASE
-
T.

2.

Sta
rt on one end and strip the cable jacket off (about 1") using a stripper
or a knife. Be extra careful not to nick the wires, otherwise you will need to
start over.

3.

Spread, untwist the pairs, and arrange the wires in the order of the desired
cable end. Flat
ten the end between your thumb and forefinger. Trim the
ends of the wires so they are even with one another, leaving only 1/2" in
wire length. I f it is longer than 1/2" it will be out
-
of
-
spec and susceptible to
crosstalk. Flatten and insure there are no sp
aces between wires.

4.

Hold the RJ
-
45 plug with the clip facing down or away from you. Push the
wires firmly into the plug. I nspect each wire is flat even at the front of the
plug. Check the order of the wires. Double check again. Check that the
jacket is fit
ted right against the stop of the plug. Carefully hold the wire
and firmly crimp the RJ
-
45 with the crimper.

5.

Check the color orientation, check that the crimped connection is not
about to come apart, and check to see if the wires are flat against the
front

of the plug. I f even one of these are incorrect, you will have to start
over. Test the Ethernet cable.

Ethernet Cable Tips
:



A straight
-
thru cable has identical ends.



A crossover cable has different ends.



A straight
-
thru is used as a patch cord in Ethernet

connections.



A crossover is used to connect two Ethernet devices without a hub or for
connecting two hubs.



A crossover has one end with the Orange set of wires switched with the
Green set.



Odd numbered pins are always striped, even numbered pins are alway
s
solid colored.



Looking at the RJ
-
45 with the clip facing away from you, Brown is always
on the right, and pin 1 is on the left.

Computer Department 5
th

Semester

34

Government Engineering College, Rajkot





No more than 1/2" of the Ethernet cable should be untwisted otherwise it
will be susceptible to crosstalk.



Do not deform, do n
ot bend, do not stretch, do not staple, do not run
parallel with power cables, and do not run Ethernet cables near noise
inducing components.

Basic Theory:





By looking at a T
-
568A UTP Ethernet straight
-
thru cable and an Ethern
et crossover
cable with a T
-
568B end, we see that the TX (transmitter) pins are connected to
the corresponding RX (receiver) pins, plus to plus and minus to minus. You can
also see that both the blue and brown wire pairs on pins 4, 5, 7, and 8 are not
used

in either standard. What you may not realize is that, these same pins 4, 5, 7,
and 8 are not used or required in 100BASE
-
TX as well. So why bother using these
wires, well for one thing its simply easier to make a connection with all the wires
grouped toge
ther. Otherwise you'll be spending time trying to fit those tiny little
wires into each of the corresponding holes in the RJ
-
45 connector.




Computer Department 5
th

Semester

35

Government Engineering College, Rajkot



2.Explain of each pin in RJ
-
45

connector.

The RJ
-
45 connector is commonly used for network
cabling and for
telephony applications.


I t's also
used for serial connections in special cases.


Here's a
look at it:


Pinout for Ethernet:

Although used for a variety of purposes, the RJ
-
45 connector is probably most
commonly used for 10Base
-
T and 100Base
-
TX Ethernet co
nnections.

Pin #

Ethernet
10BASE
-
T

100BASE
-
TX

EIA/TIA 568A

EIA/TIA 568B or AT&T
258A

1

Transmit +

Whit e wit h green
st rip

Whit e wit h orange
st ripe

2

Transmit
-

Green wit h whit e
st ripe or solid
green

Orange wit h whit e
st ripe or solid orange

3

Receive +

Whit e wit h orange
st ripe

Whit e wit h green
st ripe

4

N/A

Blue wit h whit e
st ripe or solid blue

Blue wit h whit e st ripe
or solid blue

5

N/A

Whit e wit h blue
st ripe

Whit e wit h blue
st ripe

6

Receive
-

Orange wit h white
st ripe or solid
orange

Green wit h whit e
st ripe or solid

7

N/A

Whit e wit h brown
st rip or solid brown

Whit e wit h brown
st rip or solid brown

8

N/A

Brown wit h whit e
st ripe or solid
brown.

Brown wit h whit e
st ripe or solid brown.

Because only t wo pairs of wires in t he eight
-
pin RJ
-
45 connect or are used t o
carry Et hernet signals, and bot h 10BASE
-
T and 100BASE
-
TX use t he same pins, a
crossover cable

made for one will also

work wit h t he ot her.

Also, please not e t hat it is very import ant t hat a single pair be used for pins 3 and
6.


If one conductor from one pair is used for pin 3 and a conductor from
Computer Department 5
th

Semester

36

Government Engineering College, Rajkot



another pair is used for pin 6, performance will degrade.


See the
following
figure.



RJ
-
45 Pinout for RocketPort
:

The following chart shows the pinout for RJ
-
45 connectors used on certain
RocketPort serial interface cards (manufactured by
Comtrol
).

Pin

Name/Description

1


Request To Send

2

Data Terminal Ready

3

Ground

4

Transmit Data

5

Receive Data

6

Data Carrier Detect

7

Data Set Ready

8

Clear To Send

Computer Department 5
th

Semester

37

Government Engineering College, Rajkot



Pinouts for ISDN
:

Here's an I SDN BRI U port pinout for a Cisco 750 series router:

Pin

Function

1


Not used

2


Not used

3


Not used

4


U interface network connection (tip)

5


U interface network connection (ring)

6


Not used

7


Power (pass
-
through to S connector)

8


Ground (pass
-
through to S connector)




The following chart shows the pinout

for RJ
-
45 connectors used on certain ISDN
S/T interfaces.


For more info, see ANSI T1.605.

Pin

Color

Name/Description

1


White/Orange


N/A

2


Orange


N/A

3


White/Green


Receive+

4


Blue


Transmit +

5


White/Blue


Transmit
-

6


Green


Receive
-

7


White/Brown



-
48VDC (optional)

8


Brown


-
48VDC Return (optional)