user datagram protocol
Download
Skip this Video
Download Presentation
User Datagram Protocol

Loading in 2 Seconds...

play fullscreen
1 / 12

User Datagram Protocol - PowerPoint PPT Presentation


  • 112 Views
  • Uploaded on

User Datagram Protocol. An initial look at using the UDP transport protocol for sending and receiving network packets. The Client/Server Paradigm. A great many network applications employ this asymmetrical program-design idea:. client application runs on station B. server

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'User Datagram Protocol' - khuyen


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
user datagram protocol

User Datagram Protocol

An initial look at using the UDP transport protocol for sending and receiving network packets

the client server paradigm
The Client/Server Paradigm
  • A great many network applications employ this asymmetrical program-design idea:

client

application

runs on

station B

server

application

runs on

station A

request

time

response

the sockets api for server
The sockets API for server

struct sockaddr_in saddr = {0};

int salen = sizeof( saddr );

saddr.sin_family = AF_INET;

saddr.sin_port = htons( port );

saddr.sin_addr = htonl( INADDR_ANY );

sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );

bind( sock, (sockaddr*)&saddr, salen );

struct sockaddr_in peer = {0};

int plen = sizeof( peer );

char buf[ BUFSIZ ] = {0};

recvfrom( sock, buf, BUFSIZ, 0, (sockaddr*)&peer, &plen );

sendto( sock, buf, BUFSIZ, 0, (sockaddr*)&peer, plen );

close( sock );

server

slide4
The sockets API for client

struct hostent *pp = gethostbyname( peername, NLEN );

struct sockaddr_in peer = {0};

int plen = sizeof( peer );

peer.sin_family = AF_INET;

peer.sin_port = htons( port );

peer.sin_addr.s_addr = *(uint32_t*)pp->h_addr;

sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );

char msg[ MSGSIZ ] = “Hello, world! \n”;

sendto( sock, msg, MSGSIZ, 0, (sockaddr*)&peer, plen );

char buf[ BUFSIZ ] = {0};

recvfrom( sock, buf, BUFSIZ, 0, (sockaddr*)&peer, &plen );

close( sock );

client

udpserver cpp and udpclient cpp
‘udpserver.cpp’ and ‘udpclient.cpp’
  • This pair of network application-programs provides us with a simple illustration of the basic paradigm:
    • First, launch ‘udpserver’ on station A
    • Then launch ‘udpclient’ on station B
  • We can watch the ethernet frames being sent and received using our ‘nicwatch’
the packet format
The packet format

Ethernet

Frame Header

Internet Protocol

Header

UDP

Header

application’s

message

This message is

written to the socket

by the application

This header is added

by the transport layer

This header is added

by the network layer

This header is added

by the link layer

the udp header
The UDP header

32 bits

Source port

Destination port

UDP Length

UDP Checksum

The UDP Length field is the total number of bytes of data,

plus the 8 bytes that comprise this UDP Header structure

The UDP Checksum field is computed using an algorithm

based upon ones-complement addition of the 16-bit words

in the entire UDP segment (its data and its header), along

with an extra structure known as the UDP Pseudo-Header

the ip header
The IP header

32 bits

IP

version

Header

length

Type of

Service

Total Length

(in bytes)

Identification

D

M

Fragment offset

Time-to-Live

Protocol

ID-number

Header Checksum

Source IP-address

Destination IP-address

Options

the frame header
The Frame header

14 bytes

Destination MAC-address

(6 bytes)

Source MAC-address

(6 bytes)

Type/Length

(2 bytes)

An integer which

describes the type

of this packet, or

its length in bytes

The unique hardware-address

for the network interface which

should receive this packet

The unique hardware-address

for the network interface which

is transmitting this packet

Used for ‘filtering’ packets

that are not intended for

a particular host interface

Needed when sending back replies to

requests, and for error-notifications

algorithm
Algorithm

# Rough idea for a simplified ‘traceroute’ algorithm

int ttl = 1;

do {

send UDP message toward host using ttl;

receive response from router or from host;

if ‘Resource temporarily unavailable’, break;

if ‘No route to Host’, then show who sent it;

}

while ( ++ttl < 30 );

Implementing this basic ‘traceroute’ algorithm would require us to modify

the value of the ‘Time-to-Live’ field in an outgoing packet’s IP-header,

but doing that directly is prohibited by our lack of access to kernel data

using setsockopt
Using ‘setsockopt()’
  • There is a socket-option at the IP-Level which allows an application program to adjust the ‘Time-to-Live’ value assigned to any outgoing UDP packet’s IP header

unsigned char ttl = 5; // maximum of five ‘hops’

int tlen = sizeof( ttl ); // length of the option data

if ( setsockopt( sock, SOL_IP, IP_TTL, &ttl, tlen ) < 0 )

{ perror( “setsockopt TTL” ); exit(1); }

demo tweakttl cpp
Demo: ‘tweakttl.cpp’
  • This program allows a user to specify the destination hostname, the port-number, and the desired ‘Time-to-Live’ value
  • For example:

$./tweakttl stargate 54321 5

  • You can watch the outgoing packet, and any ICPM reply-message, with ‘nicwatch’
ad