Agenda. Introduction to Sockets. Review. Host Byte Order vs. Network Byte Order. Review of Host Entry Structure. Network Socket Programming - 3

Similar documents
Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur

Socket Programming. Srinidhi Varadarajan

Tutorial on Socket Programming

Porting applications & DNS issues. socket interface extensions for IPv6. Eva M. Castro. ecastro@dit.upm.es. dit. Porting applications & DNS issues UPM

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm

Unix Network Programming

Introduction to Socket programming using C

TCP/IP - Socket Programming

Implementing Network Software

Network Programming with Sockets. Anatomy of an Internet Connection

INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens

ELEN 602: Computer Communications and Networking. Socket Programming Basics

NS3 Lab 1 TCP/IP Network Programming in C

TCP/IP Sockets in C. Practical Guide for Programmers

Network Programming with Sockets. Process Management in UNIX

CSE 333 SECTION 6. Networking and sockets

Elementary Name and Address. Conversions

Socket Programming in C/C++

Lab 4: Socket Programming: netcat part

Communication Networks. Introduction & Socket Programming Yuval Rochman

Introduction to Sockets Programming in C using TCP/IP. Professor: Panagiota Fatourou TA: Eleftherios Kosmas CSD - May 2012

UNIX Sockets. COS 461 Precept 1

Elementary Name and Address Conversions

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.

ICT SEcurity BASICS. Course: Software Defined Radio. Angelo Liguori. SP4TE lab.

Application Architecture

Overview. Socket Programming. Using Ports to Identify Services. UNIX Socket API. Knowing What Port Number To Use. Socket: End Point of Communication

UNIX. Sockets. mgr inż. Marcin Borkowski

VMCI Sockets Programming Guide VMware ESX/ESXi 4.x VMware Workstation 7.x VMware Server 2.0

Networks. Inter-process Communication. Pipes. Inter-process Communication

Client / Server Programming with TCP/IP Sockets

Windows Socket Programming & IPv6 Translation Middleware

Programmation Systèmes Cours 9 UNIX Domain Sockets

DESIGN AND IMPLEMENT AND ONLINE EXERCISE FOR TEACHING AND DEVELOPMENT OF A SERVER USING SOCKET PROGRAMMING IN C

A Client Server Transaction. Introduction to Computer Systems /18 243, fall th Lecture, Nov. 3 rd

Concurrent Server Design Alternatives

Review of Previous Lecture

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

Operating Systems Design 16. Networking: Sockets

Hostnames. HOSTS.TXT was a bottleneck. Once there was HOSTS.TXT. CSCE515 Computer Network Programming. Hierarchical Organization of DNS

BSD Sockets Interface Programmer s Guide

Networks class CS144 Introduction to Computer Networking Goal: Teach the concepts underlying networks Prerequisites:

A Client-Server Transaction. Systemprogrammering 2006 Föreläsning 8 Network Programming. Hardware Org of a Network Host.

IPv6 Enabling CIFS/SMB Applications

KATRAGADDA INNOVATIVE TRUST FOR EDUCATION NETWORK PROGRAMMING. Notes prepared by D. Teja Santosh, Assistant Professor, KPES, Shabad, R.R. District.

The POSIX Socket API

Computer Networks Network architecture

Programming guidelines on transition to IPv6

Domain Name System (1)! gethostbyname (2)! gethostbyaddr (2)!

Packet Sniffing and Spoofing Lab

Giving credit where credit is due

Carnegie Mellon. Internetworking : Introduc0on to Computer Systems 19 th Lecture, Oct. 28, Instructors: Randy Bryant and Dave O Hallaron

Lecture 17. Process Management. Process Management. Process Management. Inter-Process Communication. Inter-Process Communication

Writing a C-based Client/Server

sys socketcall: Network systems calls on Linux

Name and Address Conversions

System calls. Problem: How to access resources other than CPU

Writing Client/Server Programs in C Using Sockets (A Tutorial) Part I. Session Greg Granger grgran@sas. sas.com. SAS/C & C++ Support

IBM i Version 7.2. Programming Socket programming IBM

This tutorial has been designed for everyone interested in learning the data exchange features of Unix Sockets.

An Introductory 4.4BSD Interprocess Communication Tutorial

Network Programming. Chapter The Client-Server Programming Model

SMTP-32 Library. Simple Mail Transfer Protocol Dynamic Link Library for Microsoft Windows. Version 5.2

RPG Does TCP/IP (Socket Progamming in RPG IV)

Socket programming. Socket Programming. Languages and Platforms. Sockets. Rohan Murty Hitesh Ballani. Last Modified: 2/8/2004 8:30:45 AM

Generalised Socket Addresses for Unix Squeak

Internetworking / : Introduc2on to Computer Systems 20 th Lecture, Nov. 6, 2012

Software changes for Website and Application IPv6 Readiness

Lecture 7: Introduction to Sockets

Goal: learn how to build client/server application that communicate using sockets. An interface between application and network

Porting and Deploying VoIP to IPv6: Lessons Learned

First Workshop on Open Source and Internet Technology for Scientific Environment: with case studies from Environmental Monitoring

Network Programming using sockets

Application Development with TCP/IP. Brian S. Mitchell Drexel University

Implementing and testing tftp

TFTP Usage and Design. Diskless Workstation Booting 1. TFTP Usage and Design (cont.) CSCE 515: Computer Network Programming TFTP + Errors

Best practices in IPv6 enabled networking software development.

Limi Kalita / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 5 (3), 2014, Socket Programming

Interprocess Communication Message Passing

How To Write On A Non-Blocking File On A Thumbtongue (Windows) (Windows 2) (Macintosh) (Amd64) (Apple) (Powerpoint) (Networking) (Unix) (Program) (

Programming with TCP/IP Best Practices

Project 1: Implement a simple hosts framework using UNIX TCP Sockets to demonstrate the concept of Mobile Agents

DNS Domain Name System

System Calls and Standard I/O

Category: Standards Track August 1995

IP - The Internet Protocol

Programming With Sockets 2

Ethernet. Ethernet. Network Devices

What is CSG150 about? Fundamentals of Computer Networking. Course Outline. Lecture 1 Outline. Guevara Noubir noubir@ccs.neu.

15-441: Computer Networks Homework 1

Beej's Guide to Network Programming

An Overview of IPv6 CHAPTER

Linux/UNIX System Programming. POSIX Shared Memory. Michael Kerrisk, man7.org c February 2015

CS162 Operating Systems and Systems Programming Lecture 4. Introduction to I/O (Continued), Sockets, Networking. Recall: Fork and Wait

The exam has 110 possible points, 10 of which are extra credit. There is a Word Bank on Page 8. Pages 7-8 can be removed from the exam.

Hardware Prerequisites Atmel SAM W25 Xplained Pro Evaluation Kit Atmel IO1 extension Micro-USB Cable (Micro-A / Micro-B)

IPv4/IPv6 Transition for SIP VoIP Applications

Lecture 9: Network Security Introduction

Java Programming: Sockets in Java

Transcription:

Agenda Network Socket Programming - BUPT/QMUL 0--5 Basic concepts in NP Introduction to IP & TCP/UDP Introduction to Sockets Introduction to Sockets Review Reviews of some helpful points Sockets interface Major system calls Sample programs Introduction to Sockets Some Helpful Points Client-Server Model Data Structure of IP Address Host Byte Order vs. Network Byte Order Host Entry Structure of DNS Connections Socket Interface What is Socket? Types of Sockets SOCK_STREAM (TCP) and SOCK_DGRAM (UDP) Host Byte Order vs. Network Byte Order IP address is -byte long, while port number is -byte Two ways to store multi-byte integers Big-endian vs. little-endian Low-order byte High-order byte Address increasing High-order byte Low-order byte little-endian big-endian Host byte order is machine-dependent Network byte order is machine-independent ( big-endian) Review of Host Entry Structure /* Description of data base entry for a single host. */ struct hostent char *h_name; /* Official name of host. */ char **h_aliases; /* Alias list. */ int h_addrtype; / * Host address type. */ int h_length; / * Length of address. */ char **h_addr_list; /* List of addresses from name server. */ #define h_addr h_addr_list[0] / * The first address in the address list. */ ; 5 6

IP Addresses in the entry Structure of IP address and address h_name www.a.shifen.com *h_aliases h_addrtype AF_INET h_length *h_addr_list h_addr_list[0] 6.5.69.05 www.baidu.com null 6.5.69.5 6.5.69.05 null HBO: Little endian 5 69 5 6 /* IPv address. */ typedef uint_t in_addr_t; struct in_addr in_addr_t s_addr; ; struct sockaddr_in unsigned short sin_family; /* address family (always AF_INET) */ unsigned short sin_port; /* port num in network byte order */ struct in_addr sin_addr; /* IP addr in network byte order */ unsigned char sin_zero[8]; /* pad to sizeof(struct sockaddr) */ ; 7 8 Processes Connection and Port Number FTP (Client),5 random chosen by TCP ephemeral port number FTP (Server) A is identified by (Source IP address, Source Port Number, Destination IP address, Destination Port Number) 9 Well-known port number Understanding Socket An extension to OS s I/O system, enabling communication between processes and machines A host-local, application-created/owned, OScontrolled interface (a door ) into which application process can both send and receive messages to/from another (remote or local) application process A can be treated the same as a standard file descriptor except that It is created with the () Additional calls are needed to connect and activate it recv() and send() are also used as counterparts to read() and write() 0 Socket Programming using TCP controlled by application developer controlled by operating system Socket: a door between application process and endend-transport protocol (UDP or TCP) TCP service: reliable transfer of bytes from one process to another process TCP with buffers, variables Client Internet process TCP with buffers, variables Server controlled by application developer controlled by operating system Socket Address struct sockaddr Generic address unsigned short sa_family; /* PF_INET for IPv */ char sa_data[]; /* protocol-specific address, up to bytes. */ ; struct sockaddr_in Internet-specific address unsigned short sin_family; /* AF_INET */ unsigned short sin_port; /* 6-bit port number */ /* Network Byte Order*/ struct in_addr sin_addr; /* -bit IP Address */ /* Network Byte Order */ char sin_zero[8]; /* unused */

Socket Programming: Telephone Analogy Dissecting the Analogy A telephone call over a telephony network works as follows: Both parties have a telephone installed. A phone number is assigned to each telephone. Turn on ringer to listen for a caller. Caller lifts telephone and dials a number. Telephone rings and the receiver of the call picks it up. Both Parties talk and exchange data. After conversation is over they hang up the phone. A network application works as follows: An endpoint (telephone) for communication is created on both ends. An address (phone no) is assigned to both ends to distinguish them from the rest of the network. One of the endpoints (caller) initiate a to the other. The other endpoint(receiver) waits for the communication to start. Once a has been made, data is exchanged (talk). Once data has been exchanged the endpoints are closed (hang up). In the world of s Socket() Endpoint for communication Bind() - Assign a unique telephone number. Listen() Wait for a caller. Connect() - Dial a number. Accept() Receive a call. Send(), Recv() Talk. Close() Hang up. Introduction to Sockets Part III: major system calls 5 6 System Calls System Calls Socket Operation Socket operation Byte order operation Address formats conversion Socket option Name and address operation 7 ( ) : returns a descriptor bind( ) : What address I am on / what port to attach to connect( ) : Connect to a remote host listen( ) : Waiting for someone to connect to my port accept( ) : Get a file descriptor for a incoming send( ) and recv( ) Send and receive data over a sendto( ) and recvfrom( ) Send and receive data without close( ) and shutdown( ) Close a Two way / One way readn( ), writen( ), readline( ) Read / Write a particular number of bytes 8

System Calls Byte Order Operation System Calls Address Formats Conversion htonl() Convert long int from host byte order to network byte order htons() Convert short int from host byte order to network byte order ntohl() Convert long int from network byte order to host byte order ntohs() Convert short int from network byte order to host byte order 9 inet_aton() converts an IP address in numbers-and-dots notation (ASCII string) into unsigned long in network byte order If successful, is returned; otherwise, 0 is returned inet_addr() converts an IP address in numbers-and-dots notation (ASCII string) into unsigned long in network byte order If successful, the -bit address in network byte order is returned; otherwise, INADDR_NONE is returned inet_ntoa() Mapping a -bit integer (an IP address in network byte order) to an ASCII string in dotted decimal format If successful, pointer to ASCII string in dotted decimal format in a static buffer is returned; otherwise, NULL is returned inet_pton() Similar to inet_aton() but working with IPv and IPv6 If successful, is returned; if the IP address is invalid, 0 is returned; otherwise, - is returned when there is error inet_ntop() Similar to inet_ntoa() but working with IPv and IPv6 If successful, the ASCII string in dotted decimal format is returned; otherwise, NULL is returned 0 System Calls Socket Option getsockopt() Allow an application to require information about the setsockopt() Allow an application to set a option eg. get/set sending/receiving buffer size of a System Calls Name and Address Operation gethostbyname() retrieving host entries from DNS and the query key is a DNS domain name gethostbyaddr() retrieving host entries from DNS and the query key is an IP address gethostname() Obtaining the name of a host getservbyname() Mapping a named service onto a port number getservbyport() Obtaining an entry from the services database given the port number assigned to it Using UDP to query Local DNS Server Returns a pointer to struct hostent (host entry structure) on success Process of Socket Operation: TCP Operations Client initiate Server up, Waiting for Connection accepted Client initiate Server up, Waiting for Connection accepted Connection is setup Connection is setup

Client initiate Connection is setup Blocking call, waiting. Connection accepted Blocking call, waiting for server to accept. Connection is setup Connection accepted 5 6 Blocking call, waiting for server to accept. Connection is setup Unblock, connect( ) will return 7 8 5 Unblock, connect( ) will return send(sock-fd, ReqMessage, 5 Unblock, connect( ) will return send(sock-fd, ReqMessage, 6 recv(sock-fd, ReqMessage, 9 0

5 Unblock, connect( ) will return send(sock-fd, ReqMessage, 6 recv(sock-fd, ReqMessage, Connect(Sock-fd, Server_Addr, 5 Unblock, connect( ) will return send(sock-fd, ReqMessage, 6 recv(sock-fd, ReqMessage, 7 send(sock-fd, ResMessage, 8 recv(sock-fd, ResMessage, 7 send(sock-fd, ResMessage, System Calls () Socket descriptor success An application calls () to create a new that can be used for network communication The call returns a descriptor for the newly created int (int family, int type, int protocol ); Protocol family PF_INET PF_INET6 PF_UNIX Socket type SOCK_STREAM SOCK_DGRAM SOCK_RAW Specific protocol Often be set as 0 Be not 0 in raw System Calls bind() 0 success An application calls bind() to specify the local endpoint address (a local IP address ) for a For TCP/IP, the endpoint address uses the sockaddr structure Servers use bind to specify the well-known port at which they will await s int bind (int sockfd, const struct sockaddr *myaddr, socklen_t addrlen); Socket descriptor to be bound The local address to which the should be bound structure (bytes) System Calls connect() After creating a, a client calls connect() to establish an active to a remote server int connect (int sockfd, const struct sockaddr *servaddr, socklen_t addrlen); 0 success Socket to connect The destination address to which the should be bound destination address (bytes) System Calls send() Both clients (to transmit request) and servers (to transmit replies) used send() to transfer data across a TCP The application passes the descriptor to which the data should be sent, the address of the data to be sent, and the length of the data Usually, send() copies outgoing data into buffers in the OS kernel ssize_t send (int sockfd, const void *buff, size_t nbytes, int flags); 5 Number of bytes that are sent successfully descriptor to send data to The address of the data to be sent The number of bytes to be sent The flag controlling the, usually 0 6

System Calls recv() Both clients (to receive a reply) and servers (to receive a request) use recv to receive data from a TCP If the buffer cannot hold an incoming user datagram, recv fills the buffer and discards the remainder ssize_t recv (int sockfd, void *buff, size_t nbytes, int flags); Number of bytes that are received successfully descriptor to read from The address in memory into which the data to be placed The length of the buffer area The flag controlling the reception, usually 0 7 System Calls sendto() & recvfrom() Allow the caller to send or receive a message over a UDP sendto() require the caller to specify a destination recvfrom() uses an argument to specify where to record the sender s address Destination address ssize_t sendto (int sockfd, const void *buff, size_t nbytes, int flags, const struct sockaddr *to, socklen_t addrlen); Number of bytes that are sent and received successfully destination address ssize_t recvfrom (int sockfd, void *buff, size_t nbytes, int flags, struct sockaddr *from, socklen_t *addrlen ); Where to record the sender s address sender s address 8 Using Read and Write with s Other System Calls for sending and receiving data through a In Linux, as in most other UNIX systems, programmers can use read instead of recv, and write instead of send int read (sockfd, bptr, buflen) int write (sockfd, bptr, buflen) The chief advantage of send and recv is that they are easier to spot in the code Sending data writev () sendmsg () writen() Receiving data readv () recvmsg () readn() readline() 9 0 System Calls listen() Connection-oriented servers call listen to place a in passive mode and make it ready to accept incoming s Listen also sets the number of incoming requests that the protocol software should enqueue for a given while the server handles another request It only applies to used with TCP 0 success int listen (int sockfd, int qlength); Socket that should be prepared for use by a server request queue for that System Calls accept() The server calls accept to extract the next incoming request Accept creates a new for each new request, and return the descriptor of the new to its caller Accept fills in the structure (sockaddr) with the IP address and protocol port number of the remote machine int accept (int sockfd, struct sockaddr *cliaddr, socklen_t *addrlen); Descriptor (nonzero) success Socket on which to wait The address of the client that placed the request client address

System Calls close() Once a client or server finishes using a, it calls close to deallocate it If several processes share a, close decrements a reference count and deallocates the when the reference count reaches zero Any unread data waiting at the will be discarded 0 success #include <unistd.h> int close (int sockfd); Socket to be closed System Calls inet_aton() & inet_addr() valid string 0 error converts an IP address in numbers-and-dots notation into unsigned long in network byte order #include <arpa/inet.h> int inet_aton (const char *string, struct in_addr *address); Pointer to the string that contains the address in numbers-and-dots notation #include <arpa/inet.h> in_addr_t inet_addr (const char *string,); When success: return the -bit address in network byte order When failed: return INADDR_NONE Pointer to a long integer into which the binary value is placed Pointer to the string that contains the address in numbers-and-dots notation System Calls inet_ntoa() Mapping a -bit integer (an IP address in network byte order) to an ASCII string in dotted decimal format #include <arpa/inet.h> char * inet_ntoa ( struct in_addr inaddr ); Pointer to the resulting ASCII version -bit IP address in network byte order Introduction to Sockets Part IV: sample programs 5 6 Overview of TCP-based s API Overview of UDP-based s API TCP Client TCP Server UDP Client UDP Server () () () () bind() listen() bind() connect() Connection request accept() sendto() data recvfrom() send() recv() close() data data EOF recv() send() read() close() Await request from next client 7 recvfrom() close() data sendto() 8

Sample programs Basic flow of UDP-based echo service UDP-based echo service An echo service simply sends back to the originating source any data it receives A very useful debugging and measurement tool UDP Based Echo Service:be defined as a datagram based application on UDP. A server listens for UDP datagrams on UDP port 7. When a datagram is received, the data from it is sent back in an answering datagram. stdin stdout fgets fputs UDP Client sendto recvfrom recvfrom sendto UDP Server Sample programs udpechoclt.c udpechosvr.c 9 50 Head part of UDP EchoClient #include <stdio.h> /* for printf() and fprintf() */ /* for (), sendto() and recvfrom() */ #include <arpa/inet.h> /* for sockaddr_in and inet_addr() */ #include <stdlib.h> /* for atoi() and exit() */ #include <string.h> /* for memset() */ #include <unistd.h> /* for close() */ 5 Initial part of UDP EchoClient #define ECHOMAX 55 /* Longest string to echo */ int main(int argc, char *argv[]) int sock; /* Socket descriptor */ struct sockaddr_in echoservaddr; /* Echo server address */ struct sockaddr_in fromaddr; /* Source address of echo */ unsigned short echoservport; /* Echo server port */ unsigned int fromsize; /* In-out of address size for recvfrom() */ char *servip; /* IP address of server */ char *echostring; /* String to send to echo server */ char echobuffer[echomax+]; /* Buffer for receiving echoed string */ int echostringlen; /* Length of string to echo */ int respstringlen; /* Length of received response */ 5 Argument check part of UDP EchoClient if ((argc < ) (argc > )) /* Test for correct number of arguments */ printf("usage: %s <Server IP> <Echo Word> [<Echo Port>]\n", argv[0]); exit(); servip = argv[]; /* First arg: server IP address (dotted quad) */ echostring = argv[]; /* Second arg: string to echo */ if ((echostringlen = strlen(echostring)) > ECHOMAX) /* Check input length */ printf("echo word too long.\n"); ASCII to if (argc == ) integer echoservport = atoi(argv[]); /* Use given port, if any */ else echoservport = 7; /* 7 is the well-known port for echo service */ 5 I/O part of UDP EchoClient /* Create a datagram/udp */ if ((sock = (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) printf("() failed.\n"); /* Construct the server address structure */ memset(&echoservaddr, 0, sizeof(echoservaddr));/*zero out structure*/ echoservaddr.sin_family = AF_INET; /* Internet addr family */ echoservaddr.sin_addr.s_addr = inet_addr(servip);/*server IP address*/ echoservaddr.sin_port = htons(echoservport); /* Server port */ /* Send the string to the server */ if ((sendto(sock, echostring, echostringlen, 0, (struct sockaddr *) &echoservaddr, sizeof(echoservaddr)))!= echostringlen) printf("sendto() sent a different number of bytes than expected.\n"); /* Recv a response */ Generic address fromsize = sizeof(fromaddr); if ((respstringlen = recvfrom(sock, echobuffer, ECHOMAX, 0, (struct sockaddr *) &fromaddr, &fromsize))!= echostringlen) printf("recvfrom() failed\n"); 5

Last part of UDP EchoClient Head part of UDP EchoServer if (echoservaddr.sin_addr.s_addr!= fromaddr.sin_addr.s_addr) printf("error: received a packet from unknown source.\n"); exit(); /* null-terminate the received data */ echobuffer[respstringlen] = '\0'; printf("received: %s\n", echobuffer); /*Print the echoed message*/ close(sock); exit(0); #include <stdio.h> /* for printf() and fprintf() */ /* for (), bind(), sendto() and recvfrom() */ #include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */ #include <stdlib.h> /* for atoi() and exit() */ #include <string.h> /* for memset() */ #include <unistd.h> /* for close() */ 55 56 Initial part of UDP EchoServer Argument check part of UDP EchoServer #define ECHOMAX 55 /* Longest string to echo */ int main(int argc, char *argv[]) int sock; /* Socket */ struct sockaddr_in echoservaddr; /* Local address */ struct sockaddr_in echoclntaddr; /* Client address */ unsigned int cliaddrlen; /* Length of client address */ char echobuffer[echomax]; /* Buffer for echo string */ unsigned short echoservport; /* Server port */ int recvmsgsize; /* Size of received message */ if (argc!= ) printf("usage: %s <UDP SERVER PORT>\n", argv[0]); exit(); 57 58 Socket part of UDP EchoServer echoservport = atoi(argv[]); /* First arg: local port */ /* Create for sending/receiving datagrams */ if ((sock = (PF_INET, SOCK_DGRAM, 0)) < 0) printf("() failed.\n"); /* Construct local address structure */ Any address, memset(&echoservaddr, 0, sizeof(echoservaddr)); usually all 0s echoservaddr.sin_family = AF_INET; echoservaddr.sin_addr.s_addr = htonl( INADDR_ANY); echoservaddr.sin_port =htons(echoservport); /* Bind to the local address */ if ((bind(sock, (struct sockaddr *) &echoservaddr, sizeof(echoservaddr))) < 0) printf("bind() failed.\n"); 59 Main loop of UDP EchoServer for (;;) /* Run forever */ /* Set the size of the in-out parameter */ cliaddrlen = sizeof(echoclntaddr); /* Block until receive message from a client */ if ((recvmsgsize = recvfrom(sock, echobuffer, ECHOMAX, 0,(struct sockaddr *) &echoclntaddr, &cli) < 0) printf("recvfrom() failed.\n"); printf("handling client %s\n", inet_ntoa(echoclntaddr.sin_addr)); /* Send received datagram back to the client */ if ((sendto(sock, echobuffer, recvmsgsize, 0, (struct sockaddr *) &echoclntaddr, sizeof(echoclntaddr)))!= recvmsgsize) printf("sendto() sent a different number of bytes than expected.\n"); 60

Run the Sample Programs () Run the Sample Programs () Give correct arguments Use correct username Server process window [shiyan@localhost 0070]$./udpechosvr Usage:./udpechosvr <UDP SERVER PORT> Server process window [shiyan@localhost 0070]$./udpechosvr 7 bind() failed. Note: binding the port number less than 0 requires root authority Client process window [shiyan@localhost 0070]$./udpechoclt Usage:./udpechoclt <Server IP> <Echo Word> [<Echo Port>] Client process window [shiyan@localhost 0070]$./udpechoclt 9.68..5 hello 6 6 Run the Sample Programs () Run the Sample Programs () Successful running using root Successful running using other username Server process window [root@localhost 0070]#./udpechosvr 7 Handling client 9.68..5 Server process window [shiyan@localhost 0070]$./udpechosvr 500 Handling client 9.68..5 Client process window [root@localhost 0070]#./udpechoclt 9.68..5 hello Received: hello [root@localhost 0070]# Client process window [shiyan@localhost 0070]$./udpechoclt 9.68..5 hello 500 Received: hello [shiyan@localhost 0070]$ 6 6 Summary: Conceptual View of Socket 65