Professional Documents
Culture Documents
NetworkProgramming CH 01
NetworkProgramming CH 01
kcc.edu.np
NETWORK
PROGRAMMING
BCA
-‐
VI
SEMESTER
iSaroz
sarojpandey.com.np
sarojpandey.com.np
-‐
1
kcc.edu.np
Network
Programming
-‐
BCA
352
CS
-‐
Year:
III
Semester:
II
Contents:
1.
Introduction
to
Network
Programming:
[5
Hrs.]
Introduction
to
Computer
Network:
Client
/Server
Model,
Protocol
Suite
(ISO/OSI,
TCP/IP),
Unix
Standards
(POSIX,
Open
Group,
IETF),
Network
Utilities
(telnet,
netstat,
ifconfig,
ping,
ftp)
UDP
(User
Datagram
Protocol):
features,
uses,
comparison
with
TCP.
TCP
and
UDP
Buffer
sizes
and
limitations.
4.
Elementary
Socket
Calls:
[4
Hrs.]
Socket
Address
Structure:
for
IPV4,
IPV6,
UNIX
domain
socket
and
Generic
socket
address
structure,
Value-‐result
argument.
Byte
Ordering
and
manipulating
function:
htonl,
htons,
ntohl,
ntohs,
inet_addr,
inet_aton,
inet_ntoa,
inet_pton.
5.
TCP
Socket
Calls:
[4
Hrs.]
Socket,
function,
connect
function,
bind
function,
listen
function,
accept
function,
close
function,
getsock_name
and
get_peer_name
function
(Example:
echo
server
and
client).
6.
I/O
multiplexing
withSelect
&
Poll:
[3
Hrs.]
I/O
models:
Blocking
I/O,
non-‐blocking
I/O,
I/O
multiplexing,
signal
driven
I/O
(SIGIO)
and
Asynchronous
I/O
model.
Other
I/O
functions:
recv,
send,
readv,
writev,
recvmsgsndmsg,
socket
timeouts
and
data
handling.
10.
Unix
Domain
Protocol:
[3
Hrs.]
Unix
Domain
socket
address
structure,
socket
pair
function,
socket
functions,
UDP
Stream
Client/Server,
Unix
domain
datagram,
passing
descriptor.
11.Client
and
Server
Design
Alternative:
[2
Hrs.]
TCP
Client
Alternative,
Iteration
Server,
Concurrent
server,
Networked
servers.
12.
Daemon
processes,
inetd
super
servers:
[2
Hrs.]
Sysloged
(syslog
function),
daemon_init
function,
inetd
daemon.
13.Broadcast
and
Multicast:
[3
Hrs.]
Introduction,
Broadcast
and
Multicast
addresses,
comparison
between
broadcast,
unicast
and
Multicast
socket
options.
14.
IP
Layers
and
Raw
Socket:
[3
Hrs.]
Introduction,
Raw
socket
creation,
Input
and
Output
(ping
example).
Lab
Exercise:
Laboratories
of
elementary
or
system
calls,
TCP
and
UDP
socket
including
select
and
poll,
socket
options
and
name
conversion
strictly
using
C/C++
and
Linux.
Class
project:
Project
class
includes
the
project
covering
the
advanced
topics
in
Windows
/
Linux
/
Unix
Environment
using
Java/C/C++.
Textbooks:
1.
Stevens
W.R.,
"Unix
Network
Programming",
Vol-‐1.
2.
Stevens
W.R.,
"Unix
Network
Programming",
Vol-‐II
3.
Doglous
E.
Comer,
"Internetworking
with
TCP/IP",
Vol
-‐
III
sarojpandey.com.np
-‐
3
kcc.edu.np
CHAPTER
01:
Introduction
to
Network
Programming
Introduction
to
Computer
Network
A
computer
network,
or
simply
a
network,
is
a
collection
of
computers
and
other
hardware
interconnected
by
communication
channels
that
allow
sharing
of
resources
and
information.
Where
at
least
one
process
in
one
device
is
able
to
send/receive
data
to/from
at
least
one
process
residing
in
a
remote
device,
then
the
two
devices
are
said
to
be
in
a
network.
A
network
is
a
group
of
devices
connected
to
each
other.
Networks
may
be
classified
into
a
wide
variety
of
characteristics,
such
as
the
medium
used
to
transport
the
data,
communication
protocol
used,
scale,
topology,
benefit,
and
organizational
scope.
Client
/Server
Model
The
term
client-‐server
refers
to
a
popular
model
for
computer
networking
that
utilizes
client
and
server
devices
each
designed
for
specific
purposes.
The
client-‐server
model
can
be
used
on
the
Internet
as
well
as
local
area
networks
(LANs).
Examples
of
client-‐server
systems
on
the
Internet
include
Web
browsers
and
Web
servers,
FTP
clients
and
servers,
and
the
DNS.
The
model
assigns
one
of
two
roles
to
the
computers
in
a
network:
Client
or
server.
A
server
is
a
computer
system
that
selectively
shares
its
resources;
a
client
is
a
computer
or
computer
program
that
initiates
contact
with
a
server
in
order
to
make
use
of
a
resource.
Data,
CPUs,
printers,
and
data
storage
devices
are
some
examples
of
resources.
This
sharing
of
computer
resources
is
called
time-‐sharing,
because
it
allows
multiple
people
to
use
a
computer
(in
this
case,
the
server)
at
the
same
time.
Because
a
computer
does
a
limited
amount
of
work
at
any
moment,
a
time-‐sharing
system
must
quickly
prioritize
its
tasks
to
accommodate
the
clients.
Clients
and
servers
exchange
messages
in
a
request-‐response
messaging
pattern:
The
client
sends
a
request,
and
the
server
returns
a
response.
To
communicate,
the
computers
must
have
a
common
language,
and
they
must
follow
rules
so
that
both
the
client
and
the
server
know
what
to
expect.
The
language
and
rules
of
communication
are
defined
in
a
communications
protocol.
All
client-‐server
protocols
operate
in
the
application
layer.
Whether
a
computer
is
a
client,
a
server,
or
both,
it
can
serve
multiple
functions.
For
example,
a
single
computer
can
run
web
server
and
file
server
software
at
the
same
time
to
serve
different
data
to
clients
making
different
kinds
of
requests.
Client
software
can
also
communicate
with
sarojpandey.com.np
-‐
4
kcc.edu.np
server
software
on
the
same
computer.
Communication
between
servers,
such
as
to
synchronize
data,
is
sometimes
called
inter-‐server
or
server-‐to-‐server
communication.
• After
connection
establishment,
receive
commands
from
the
user,
perform
necessary
translation
as
per
the
protocol
and
send
them
to
the
server.
• Receive messages from the server, translate them to human readable form and display them.
form a working address that can be used to talk over Internet.
wait until there's either information from the server, or from the
user.
parse information
parse command
done
sarojpandey.com.np
-‐
5
kcc.edu.np
this
forms
the
main
loop
a
Multi-‐Client
Server
performs:
bind a port on the computer, so Clients will be able to connect
forever do:
handle request
done
else
done
sarojpandey.com.np
-‐
6
kcc.edu.np
if
(this
is
an
un-‐authorized
Client)
close
the
connection
else
if
(this
is
a
connection
close
request)
close
the
connection
else
{
this
is
a
request
from
an
existing
Client
connection}
receive
request
from
client
handle
request
send
results
of
request,
or
error
messages
done
Client
Server
• Process
that
request
for
a
service
• Process
that
accepts
the
client
request,
handles
them
and
provides
the
service
• Initiates
the
connection
• Do
not
initiate
the
connection,
rather
establishment
responds
to
the
connection
request
from
the
clients.
• Runs
for
comparatively
short
time
• Runs
for
longer
time;
some
server
never
terminate
Protocol
Suite
(ISO/OSI,
TCP/IP)
ISO/OSI
REFERENCE
MODEL
Transferring
of
data
between
different
communications
devices
is
divided
into
logical
layers
called
OSI
layers;
these
layers
are
seven
in
number.
OSI
model
stands
for
Open
Systems
Interconnection,
Xerox
Corporation
and
Intel
designed
it
in
1984
and
later
ISO
(International
Standard
Organization)
standardized
it.
OSI
is
logical
framework
for
standards
for
computer
networks
and
data
communication.
OSI
model
is
used
as
set
standards
for
computer
networking
worldwide.
Major
networking
protocols
are
specifically
designed
keeping
OSI
model
in
view.
Their
principles
are
as
follows:
1.
A
layer
should
be
created
where
a
different
level
of
abstraction
is
needed.
2.
Each
layer
should
perform
a
well-‐defined
function.
3.
The
function
of
each
layer
should
be
defined
by
internationally
standardized
protocols.
4.
The
layer
boundaries
should
be
chosen
to
reduce
the
information
flow
across
the
interfaces.
sarojpandey.com.np
-‐
7
kcc.edu.np
5.
The
number
of
layers
should
be
large
enough
that
some
distinct
functions
not
be
thrown
t o g e t h e r
i n
t h e
s a m e
l a y e r
o f
necessity
a n d
s m a l l
e n o u g h
t h a t
t h e
architecture
does
not
become
bulky.
The
OSI’s
7-‐layer
reference
model
is
an
attempt
to
abstract
features
common
to
all
approaches
to
data
communications,
and
organize
them
into
layers
or
modules
such
that
each
layer
only
worries
about
the
layer
directly
above
it
and
the
one
directly
below
it.
Those
7
layers
are
as
follows:
1. Physical
layer
3. Network layer
4. Transport layer
5. Session layer
6. Presentation layer
7. Application layer
sarojpandey.com.np
-‐
8
kcc.edu.np
These
layers
helps
dividing
different
tasks
of
communication
and
transferring
data
within
the
network
into
subtasks,
that’s
how
one
completes
cycle
of
communications
between
network(s)
is
completed.
Each
layer
completes
its
tasks
independently.
These
layers
are
also
divided
into
upper
and
lower
layers.
Physical
Layer:
Layer
1
As
the
name
suggests,
Physical
layer
handles
all
sorts
of
physical
aspects
including,
networking
cables,
networking
cards/adaptors
and
other
physical
devices
require
for
networking.
It
defines
bit
steam
on
physical
media.
It
is
responsible
for
providing
interfaces
between
networks
and
network
communication
devices.
Physical
layer
also
handles
mechanical,
electrical
and
optical
aspects
on
the
network.
It
is
concerned
w i t h
transmitting
r a w
b its
o ver
a
communication
channel.
Data
Link
Layer:
Layer
2
Communication
links
and
its
procedures
are
handled
by
data
link
layers.
The
main
function
of
the
data
-‐link
layer
is
to
take
a
raw
transmission
facility
and
transform
it
into
a
line
that
appears
free
of
undetected
transmission
errors
to
the
network
layer.
It
is
done
by
breaking
the
input
data
into
data
frames
(typically
a
few
hundred
or
a
few
thousand
bytes),
transmit
the
frames
subsequently
and
process
the
acknowledgement
frames
sent
back
by
the
receiver.
The
physical
layer
merely
accepts
and
transmits
a
stream
of
bits
without
any
concern
with
meaning
or
structure.
It
is
up
to
the
data
link
layer
to
create
and
recognize
frame
boundaries.
This
can
be
done
by
attaching
special
bit
patterns
the
beginning
and
end
of
the
frame.
A
noise
burst
on
the
line
can
destroy
a
frame
completely.
In
such
cases,
the
data
link
layer
software
on
the
source
machine
can
retransmit
the
frame.
A
duplicate
frame
could
be
sent
if
the
acknowledgement
frame
from
the
receiver
back
to
the
sender
were
lost.
It
is
up
to
this
layer
to
solve
the
problems
caused
by
damaged,
lost
and
duplicate
frames.
Another
issue
that
arises
in
the
data
link
layer
is
how
to
keep
a
fast
transmitter
from
drawing
a
slow
receiver
in
data.
Some
traffic
regulation
mechanism
must
be
employed
to
let
the
transmitter
known
how
much
buffer
space
the
receiver
has
at
the
moment.
sarojpandey.com.np
-‐
9
kcc.edu.np
enough
for
the
second
network,
protocols
may
differ
and
so
on.
Hence
network
layer
has
to
overcome
all
these
problems
to
allow
heterogeneous
networks
to
be
interconnected.
Network
layer
also
translate
logical
address
into
actual
physical
address
for
example,
converting
computer
name
in
to
MAC
address.
The
layer
is
held
responsible
for
controlling
the
core
processes
of
networking,
for
example,
routing,
managing
network
and
its
problem,
addressing
etc.
Router/Switches
are
the
hardware
which
work
on
network
layers,
if
sending
devices
are
unable
to
break
down
data
into
packets
similar
to
receiving
devices
then
network
layer
comes
in
and
breakdown
the
data
into
smaller
unites
and
then
re-‐assemble
the
data
at
receiving
end.
It
handles
the
core
processes
of
networking,
network
layer
routes
data
in
form
of
packets
according
to
network
address.
It
is
responsible
to
send
all
the
data
to
specific
destination
with
in
the
network.
Protocols
used
are
RIP,
ARP,
and
ICMP
etc.
Transport
Layer:
Layer
4
Transport
layer
handles
the
delivery
of
data
packets
at
their
respective
ends
and
destinations.
It
is
also
responsible
for
identifying
errors
and
duplication
of
data
through
out
with
in
the
network.
Once
data
is
transferred
to
their
respective
ends
successfully
it
provides
acknowledgement
about
it
and
resends
the
data
on
receiving
errors
during
transferring.
Transport
layer
keep
the
connection
alive
during
the
data
transmission
and
also
handles
error
during
the
course
of
transferring
of
data
within
the
network.
It’s
basic
function
is
to
accept
data
from
the
session
layer,
split
it
up
into
smaller
units
if
need
be,
pass
these
to
the
network
layer
and
ensure
that
the
pieces
all
arrive
correctly
at
the
o t h e r
e n d .
Under
normal
conditions,
the
transport
layer
creates
a
distinct
network
connection
for
each
transport
connection
required
by
the
session
layer.
If
the
transport
connection
requires
a
high
throughput,
the
transport
layer
might
create
multiple
network
connections,
dividing
the
data
among
the
network
connections
to
improve
throughput.
But
if
it
sounds
expensive,
the
transport
layer
might
multiplex
several
transport
connections
on
the
same
network
to
reduce
c o s t .
Overall,
t h e
tr a n s p o r t
l a y e r
i s
required
to
make
t h e
m u ltip lex in g
transparent
to
the
session
layer.
The
transport
layer
also
determines
what
type
of
service
to
be
provided
to
the
session
layer,
and
ultimately
the
users
of
the
network.
The
most
popular
type
of
transport
connections
is
an
error
-‐free
-‐p oint-‐t o-‐point
channels
that
delivers
message
or
bytes
in
the
order
in
which
they
were
sent.
Session
Layer:
Layer
5
Session
layer
is
designed
to
manage
established
sessions
between
two
different
nodes
(users)
within
the
network.
Session
layer
is
also
responsible
to
establish
connection
then
identifies
who
and
how
much
data
is
to
be
sent
how
much
time
is
required
for
it.
Session
layers
keeps
the
connection
alive,
incase
if
it
is
disconnection
during
the
transfer,
it
reconnects
and
continues
the
session.
It
allows
users
on
different
machines
to
establish
sessions
between
them.
A
session
allows
ordinary
data
transport
like
transport
layer
do,
but
also
provides
enhanced
services
useful
in
some
The
TCP/IP
reference
model.
[ASSIGNMENT 01]
There are two types of Internet Protocol (IP) traffic. They are TCP or Transmission Control Protocol and UDP or
User Datagram Protocol. TCP is connection oriented – once a connection is established, data can be sent
bidirectional. UDP is a simpler, connectionless Internet protocol. Multiple messages are sent as packets in chunks
using UDP.
Comparison chart
TCP
UDP
Acronym
for:
Transmission
Control
Protocol
User
Datagram
Protocol
or
Universal
Datagram
Protocol
Function:
As
a
message
makes
its
way
across
UDP
is
also
a
protocol
used
in
message
the
internet
from
one
computer
to
transport
or
transfer.
This
is
not
another.
This
is
connection
based.
connection
based
which
means
that
one
program
can
send
a
load
of
packets
to
another
and
that
would
be
the
end
of
the
relationship.
Usage: TCP is used in case of non-‐time UDP is used for games or applications that
Examples: HTTP, HTTPs, FTP, SMTP Telnet etc. DNS, DHCP, TFTP, SNMP, RIP, VOIP etc.
Ordering of data TCP rearranges data packets in the UDP has no inherent order as all packets are
packets:
order
specified.
independent
of
each
other.
If
ordering
is
required,
it
has
to
be
managed
by
the
application
layer.
Speed
of
transfer:
The
speed
for
TCP
is
slower
than
UDP.
UDP
is
faster
because
there
is
no
error-‐
checking
for
packets.
Reliability:
There
is
absolute
guarantee
that
the
There
is
no
guarantee
that
the
messages
data
transferred
remains
intact
and
or
packets
sent
would
reach
at
all.
arrives
in
the
same
order
in
which
it
was
sent.
TCP UDP
Header Size: TCP header size is 20 bytes UDP Header size is 8 bytes.
Common
Header
Source
port,
Destination
port,
Check
Source
port,
Destination
port,
Check
Sum
Fields:
Sum
Streaming
of
data:
Data
is
read
as
a
byte
stream,
no
Packets
are
sent
individually
and
are
distinguishing
indications
are
checked
for
integrity
only
if
they
arrive.
transmitted
to
signal
message
Packets
have
definite
boundaries,
which
(segment)
boundaries.
are
honored
upon
receipt,
meaning
a
read
operation
at
the
receiver
socket
will
yield
an
entire
message
as
it
was
originally
sent.
Weight:
TCP
requires
three
packets
to
set
up
UDP
is
lightweight.
There
is
no
ordering
a
socket
connection,
before
any
user
of
messages,
no
tracking
connections,
etc.
data
can
be
sent.
TCP
handles
It
is
a
small
transport
layer
designed
on
reliability
and
congestion
control.
top
of
IP.
Data
Flow
Control:
TCP
does
Flow
Control.
TCP
UDP
does
not
have
an
option
for
flow
requires
three
packets
to
set
up
a
control
socket
connection,
before
any
user
data
can
be
sent.
TCP
handles
reliability
and
congestion
control.
Error
Checking:
TCP
does
error
checking
UDP
does
error
checking,
but
no
recovery
options.
Fields:
1.
Sequence
Number,
2.
AcK
1.
Length,
2.
Source
port,
3.
Destination
number,
3.
Data
offset,
4.
Reserved,
port,
4.
Check
Sum
5.
Control
bit,
6.
Window,
7.
Urgent
Pointer
8.
Options,
9.
Padding,
10.
Check
Sum,
11.
Source
port,
12.
Destination
port
sarojpandey.com.np
-‐
14
kcc.edu.np
Differences
in
Data
Transfer
Features
TCP
ensures
a
reliable
and
ordered
delivery
of
a
stream
of
bytes
from
user
to
server
or
vice
versa.
UDP
is
not
dedicated
to
end
to
end
connections
and
communication
does
not
check
readiness
of
receiver.
Reliability
TCP
is
more
reliable
since
it
manages
message
acknowledgment
and
retransmissions
in
case
of
lost
parts.
Thus
there
is
absolutely
no
missing
data.
UDP
does
not
ensure
that
communication
has
reached
receiver
since
concepts
of
acknowledgment,
time
out
and
retransmission
are
not
present.
Ordering
TCP
transmissions
are
sent
in
a
sequence
and
they
are
received
in
the
same
sequence.
In
the
event
of
data
segments
arriving
in
wrong
order,
TCP
reorders
and
delivers
application.
In
the
case
of
UDP,
sent
message
sequence
may
not
be
maintained
when
it
reaches
receiving
application.
There
is
absolutely
no
way
of
predicting
the
order
in
which
message
will
be
received.
Connection
TCP
is
a
heavy
weight
connection
requiring
three
packets
for
a
socket
connection
and
handles
congestion
control
and
reliability.
UDP
is
a
lightweight
transport
layer
designed
atop
an
IP.
There
are
no
tracking
connections
or
ordering
of
messages.
Unix
Standards
(POSIX,
Open
Group,
IETF)
POSIX
POSIX,
an
acronym
for
"Portable
Operating
System
Interface",
is
a
family
of
standards
specified
by
the
IEEE
for
maintaining
compatibility
between
operating
systems.
POSIX
defines
the
application
programming
interface
(API),
along
with
command
line
shells
and
utility
interfaces,
for
software
compatibility
with
variants
of
Unix
and
other
operating
systems.
POSIX
defines
a
standard
operating
system
interface
and
environment,
including
a
command
interpreter
(or
“shell”),
and
common
utility
programs
to
support
applications
portability
at
the
source
code
level.
It
is
intended
to
be
used
by
both
application
developers
and
system
implementers
and
comprises
four
major
components
(each
in
an
associated
volume):
• General
terms,
concepts,
and
interfaces
common
to
all
volumes
of
this
standard,
including
utility
conventions
and
C-‐language
header
definitions,
are
included
in
the
Base
Definitions
volume.
• Definitions
for
system
service
functions
and
subroutines,
language-‐specific
system
services
for
the
C
programming
language,
function
issues,
including
portability,
error
handling,
and
error
recovery,
are
included
in
the
System
Interfaces
volume.
• Definitions
for
a
standard
source
code-‐level
interface
to
command
interpretation
services
(a
“shell”)
and
common
utility
programs
for
application
programs
are
included
in
the
Shell
and
Utilities
volume.
The
POSIX
specifications
for
Unix-‐like
operating
system
environments
originally
consisted
of
a
single
document
for
the
core-‐programming
interface,
but
eventually
grew
to
19
separate
documents
(E.g.
POSIX.1,
POSIX.2
etc.).
The
standardized
user
command
line
and
scripting
interface
were
based
on
the
Korn
shell.
Many
user-‐level
programs,
services,
and
utilities
including
awk,
echo,
ed
were
also
standardized,
along
with
required
program-‐level
services
including
basic
I/O
(file,
terminal,
and
network)
services.
POSIX
also
defines
a
standard
threading
library
API
which
is
supported
by
most
modern
operating
systems.
• POSIX.1-‐2008:
POSIX
Base
Definitions,
System
Interfaces,
and
Commands
and
Utilities
(which
include
POSIX.1,
extensions
for
POSIX.1,
Real-‐time
Services,
Threads
Interface,
Real-‐time
Extensions,
Security
Interface,
Network
File
Access
and
Network
Process-‐to-‐Process
Communications,
User
Portability
Extensions,
Corrections
and
Extensions,
Protection
and
Control
Utilities
and
Batch
System
Utilities)
• POSIX
Conformance
Testing:
A
test
suite
for
POSIX
accompanies
the
standard:
PCTS
or
the
POSIX
Conformance
Test
Suite.
[The
development
of
the
POSIX
standard
takes
place
in
the
Austin
Group,
a
joint
working
group
linking
the
Open
Group
and
the
ISO
organization.]
POSIX.1
• POSIX.1,
Core
Services
(incorporates
Standard
ANSI
C)
(IEEE
Std.
1003.1-‐1988)
• Process
Creation
and
Control
• Signals
• Floating
Point
Exceptions
• Segmentation
/
Memory
Violations
• Illegal
Instructions
• Bus
Errors
• Timers
• File
and
Directory
Operations
• Pipes
• C
Library
(Standard
C)
• I/O
Port
Interface
and
Control
POSIX.1b
POSIX.1-‐2001
POSIX.1-‐2001 or IEEE Std 1003.1-‐2001 equates to the Single UNIX Specification version 3
POSIX.1-‐2001
POSIX.1-‐2008
As
of
2009
POSIX.1-‐2008
or
IEEE
Std
1003.1-‐2008
represents
the
current
version.
A
free
online
copy
is
available.
The
Internet
Engineering
Task
Force
(IETF)
develops
and
promotes
Internet
standards,
cooperating
closely
with
the
W3C
and
ISO/IEC
standards
bodies
and
dealing
in
particular
with
standards
of
the
Internet
protocol
suite
(TCP/IP).
It
is
an
open
standards
organization,
with
no
formal
membership
or
membership
requirements.
All
participants
and
managers
are
volunteers,
though
their
employers
or
sponsors
usually
fund
their
work;
for
instance,
the
current
chairperson
is
funded
by
VeriSign
and
the
U.S.
government's
National
Security
Agency.
Network
Utilities
(telnet,
netstat,
ifconfig,
ping,
ftp)
• telnet
A
terminal
emulation
program
for
TCP/IP
networks
such
as
the
Internet.
The
Telnet
program
runs
on
your
computer
and
connects
your
PC
to
a
server
on
the
network.
You
can
then
enter
telnet [-‐8] [-‐E] [-‐L] [-‐c] [-‐d] [-‐r] [ -‐e escape_char ] [ -‐l user ] [-‐n file ] [ host [ port ] ]
-‐8
Specifies
an
8-‐bit
data
path.
Negotiating
the
TELNET
BINARY
option
is
attempted
for
both
input
and
output.
-‐E Stops any character from being recognized as an escape character.
-‐L Specifies an 8-‐bit data path on output. This causes the BINARY option to be negotiated on output.
-‐d Sets the initial value of the debug toggle to TRUE.
-‐r
Specifies
a
user
interface
similar
to
rlogin.
In
this
mode,
the
escape
character
is
set
to
the
tilde
(~)
character,
unless
modified
by
the
-‐e
option.
The
rlogin
escape
character
is
only
recognized
when
it
is
preceded
by
a
carriage
return.
In
this
mode,
the
telnet
escape
character,
normally
'^]',
must
still
precede
a
telnet
command.
The
rlogin
escape
character
can
also
be
followed
by
'.\r'
or
'^Z',
and,
like
rlogin,
closes
or
suspends
the
connection,
respectively.
This
option
is
an
uncommitted
inter-‐
face
and
may
change
in
the
future.
-‐e
escape_char
Sets
the
initial
escape
character
to
escape_char.
escape_char
may
also
be
a
two
character
sequence
consisting
of
'^'
followed
by
one
character.
If
the
second
character
is
'?',
the
DEL
character
is
selected.
Otherwise,
the
second
character
is
converted
to
a
control
character
and
used
as
the
escape
character.
If
the
escape
character
is
the
null
string
(that
is,
-‐e
''),
it
is
disabled.
-‐l
user
When
connecting
to
a
remote
system
that
understands
the
ENVIRON
option,
then
user
will
be
sent
to
the
remote
system
as
the
value
for
the
ENVIRON
variable
USER.
• netstat
Print
network
connections,
routing
tables,
interface
statistics,
masquerade
connections,
and
multicast
memberships.
netstat
[-‐a]
[-‐b]
[-‐e]
[-‐f]
[-‐n]
[-‐o]
[-‐p
protocol]
[-‐r]
[-‐s]
[-‐t]
[-‐x]
[-‐y]
[time_interval]
[/?]
-‐b
=
This
netstat
switch
is
very
similar
to
the
-‐o
switch
listed
below,
but
instead
of
displaying
the
PID,
will
display
the
process's
actual
file
name.
Using
-‐b
over
-‐o
might
seem
like
it's
saving
you
a
step
or
two
but
using
it
can
sometimes
greatly
extend
the
time
it
takes
netstat
to
fully
execute.
-‐e
=
Use
this
switch
with
the
netstat
command
to
show
statistics
about
your
network
connection.
This
data
includes
bytes,
unicast
packets,
non-‐unicast
packets,
discards,
errors,
and
unknown
protocols
received
and
sent
since
the
connection
was
established.
-‐f
=
The
-‐f
switch
will
force
the
netstat
command
to
display
the
Fully
Qualified
Domain
Name(FQDN)
for
each
foreign
IP
addresses
when
possible.
-‐n
=
Use
the
-‐n
switch
to
prevent
netstat
from
attempting
to
determine
host
names
for
foreign
IP
addresses.
Depending
on
your
current
network
connections,
using
this
switch
could
considerably
reduce
the
time
it
takes
for
netstat
to
fully
execute.
…
…
…
• ifconfig
ifconfig
(short
for
interface
configuration)
is
a
system
administration
utility
in
Unix-‐like
operating
systems
to
configure,
control,
and
query
TCP/IP
network
interface
parameters
from
a
command
line
interface
(CLI)
or
in
system
configuration
scripts.
ifconfig
[interface]
ifconfig
interface
[aftype]
options
|
address
...
Options
interface
The
name
of
the
interface.
This
is
usually
a
driver
name
followed
by
a
unit
number,
for
example
eth0
for
the
first
Ethernet
interface.
up
This
flag
causes
the
interface
to
be
activated.
It
is
implicitly
specified
if
an
address
is
assigned
to
the
interface.
down
This
flag
causes
the
driver
for
this
interface
to
be
shut
down.
…
…
…
E.g.
ifconfig
eth0
:
View
the
network
settings
on
the
first
Ethernet
adapter
installed
in
the
computer.
• ping
Short
for
Packet
InterNet
Groper,
ping
is
a
utility
used
to
verify
if
a
network
data
packet
is
capable
of
being
distributed
to
an
address
without
errors.
The
ping
utility
is
commonly
used
to
check
for
network
errors.
It
sends
ICMP
ECHO_REQUEST
packets
to
network
hosts.
Syntax
ping -‐s [-‐d] [-‐l] [-‐L] [-‐n] [-‐r] [-‐R] [-‐v] [ -‐i interface_address ] [-‐I interval] [-‐t ttl] host [packetsize] [count]
-‐l
Loose
source
route.
Use
this
option
in
the
IP
header
to
send
the
packet
to
the
given
host
and
back
again.
Usually
specified
with
the
-‐R
option.
-‐L
Turn
off
loopback
of
multicast
packets.
Normally,
if
there
are
members
in
the
host
group
on
the
out-‐
going
interface,
a
copy
of
the
multicast
packets
will
be
delivered
to
the
local
machine.
-‐r
Bypass
the
normal
routing
tables
and
send
directly
to
a
host
on
an
attached
network.
If
the
host
is
not
on
a
directly
attached
network,
an
error
is
returned.
This
option
can
be
used
to
ping
a
local
host
through
an
interface
that
has
been
dropped
by
the
router
daemon.
-‐R
Record
route.
Sets
the
IP
record
route
option,
which
will
store
the
route
of
the
packet
inside
the
IP
header.
-‐v
Verbose
output.
List
any
ICMP
packets,
other
than
ECHO_RESPONSE,
that
are
received.
-‐i
interface_address
Specify
the
outgoing
interface
address
to
use
for
multicast
packets.
The
default
interface
address
for
multicast
packets
is
determined
-‐I
interval
Specify
the
interval
between
successive
transmissions.
The
default
is
one
second.
-‐t
ttl
Specify
the
IP
time
to
live
for
unicast
and
multicast
packets.
The
default
time
to
live
for
multicast
is
one
hop.
Examples
ping
google.com
• ftp
&
its
commands
[SELF
STUDY
01.
Ref:
Web
Technology]
Mkfifo(“/usr/bin/myinfo.fifo”, S_IRDWR);
fd=open(“/usr/bin/myfifo.fifo”,O_RDONLY);
n=Read(fd, buff, 100);
buff[n]=’\0’;
sarojpandey.com.np
-‐
25
kcc.edu.np
printf(“%s”,buff);
return 0;
}
int Mkinfo (const char *pname, mode_t mode)
{
int err;
err=mkfifo(pname,mode);
if(err==-1)
{
switch(errno)
{
case E_ACCESS: printf(“Access Violation.”);
exit(0);
• System
header
files
declare
the
interfaces
to
parts
of
the
operating
system.
You
include
them
in
your
program
to
supply
the
definitions
and
declarations
you
need
to
invoke
system
calls
and
libraries.
o <sys/types.h>
o <unistd.h>
o
<sys/uio.h>
o
<errno.h>
o
<sys/ioctl.h>
o
<fcntl.h>
o
<sys/socket.h>
o
<netdb.h>
o
<netinet/in_systm.h>
o
<netinet/ip_icmp.h>
o
<netinet/udp.h>
o
<netinet/ip.h>
o
<netinet/in.h>
o
<arpa/inet.h>
o
<arpa/nameser.h>
o
<resolv.h>
o
<net/if.h>
o
<strings.h>