Network Programming / : Introduc2on to Computer Systems 21 st Lecture, April. 4, Instructors: Todd Mowry and Anthony Rowe

Similar documents
Network Programming November 3, 2008

Network Programming /18-243: Introduc3on to Computer Systems 22 nd Lecture, 13 April Instructors: Bill Nace and Gregory Kesden

Client-server model The course that gives CMU its Zip! Network programming Nov 27, Using ports to identify services.

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

PA #2 Reviews. set_name, get_name, del_name. Questions? Will be modified after PA #4 ~

Internet protocol stack. Internetworking II: Network programming. April 20, UDP vs TCP. Berkeley Sockets Interface.

Internetworking II: Network programming. April 20, 2000

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Network Programming September 6, 2005

Sockets and Parallel Computing. CS439: Principles of Computer Systems April 11, 2018

Network Programming: Part I

A Client-Server Exchange

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Interprocess Communication Mechanisms

Interprocess Communication Mechanisms

Concurrent Programming

Concurrent Programming

CS 640: Computer Networking

Concurrent programming

Concurrent Programming November 28, 2007

Concurrent Servers Dec 2, 2009"

ECE 435 Network Engineering Lecture 2

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

CONCURRENT PROGRAMMING. Lecture 5

Application Programming Interfaces

Lecture 3 Overview! Last Lecture! TCP/UDP and Sockets introduction!

Concurrent Programming is Hard! Concurrent Programming. Reminder: Iterative Echo Server. The human mind tends to be sequential

Socket Programming TCP UDP

Socket Programming. CSIS0234A Computer and Communication Networks. Socket Programming in C

UNIX Network Programming. Overview of Socket API Network Programming Basics

Networks and Their Abstractions. CS439: Principles of Computer Systems April 9, 2018

Introduction to Socket Programming

CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo

ECE 435 Network Engineering Lecture 2

CS321: Computer Networks Introduction to Application Layer

Network Programming Worksheet 2. Simple TCP Clients and Servers on *nix with C.

Three Basic Mechanisms for Creating Concurrent Flows. Systemprogrammering 2009 Föreläsning 10 Concurrent Servers. Process-Based Concurrent Server

Introduction to Client-Server Model

CSE 333 SECTION 6. Networking and sockets

Concurrent Programming April 21, 2005

#include <sys/socket.h> int listen(int socket, int backlog); socket. socket. backlog

Context. Distributed Systems: Sockets Programming. Alberto Bosio, Associate Professor UM Microelectronic Departement

CSE 333 Lecture 16 - network programming intro

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

Lecture #23 Concurrent Programming

Session NM056. Programming TCP/IP with Sockets. Geoff Bryant Process software

Department of Computer Science

Network Socket Programming - 2 BUPT/QMUL

CSE 124 Discussion Section Sockets Programming 10/10/17

Tutorial on Socket Programming

Iterative Servers The course that gives CMU its Zip! Iterative servers process one request at a time. Concurrent Servers

CSE 333 SECTION 8. Sockets, Network Programming

CS321: Computer Networks Socket Programming

Announcement (1) Due date for PA3 is changed (~ next week) PA4 will also be started in the next class. Not submitted. Not scored

Network Socket Programming - 3 BUPT/QMUL

CS 43: Computer Networks. 05: Socket Programming September 12-14, 2018

Network Socket Programming - 3 BUPT/QMUL

CLIENT-SIDE PROGRAMMING

CS118 Discussion 1B, Week 1. Taqi Raza BUNCHE 1209B, Fridays 12:00pm to 1:50pm

TCP: Three-way handshake

Computer Systems Laboratory Sungkyunkwan University

Types (Protocols) Associated functions Styles We will look at using sockets in C Java sockets are conceptually quite similar

Concurrent Programming

Ports under 1024 are often considered special, and usually require special OS privileges to use.

Network Programming: Part II

Concurrent Programming

UNIX Sockets. COS 461 Precept 1

Lecture 24. Thursday, November 19 CS 375 UNIX System Programming - Lecture 24 1

call connect call read call connect ret connect call fgets Client 2 blocks waiting to complete its connection request until after lunch!

CSE 333 SECTION 7. Client-Side Network Programming

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

CSE 333 SECTION 7. Client-Side Network Programming

CSE 333 SECTION 7. C++ Virtual Functions and Client-Side Network Programming

Hybrid of client-server and P2P. Pure P2P Architecture. App-layer Protocols. Communicating Processes. Transport Service Requirements

Concurrent Programming

Lab 0. Yvan Petillot. Networks - Lab 0 1

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets

Networked Applications: Sockets. End System: Computer on the Net

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions

ICT 6544 Distributed Systems Lecture 5

Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현

Lecture 7. Followup. Review. Communication Interface. Socket Communication. Client-Server Model. Socket Programming January 28, 2005

Concurrent Programming

WinSock. What Is Sockets What Is Windows Sockets What Are Its Benefits Architecture of Windows Sockets Network Application Mechanics

CompSci 356: Computer Network Architectures Lecture 3: Hardware and physical links References: Chap 1.4, 1.5 of [PD] Xiaowei Yang

CSE 333 Section 3. Thursday 12 April Thursday, April 12, 12

SOCKET PROGRAMMING. What is a socket? Using sockets Types (Protocols) Associated functions Styles

Total Score is updated. The score of PA4 will be changed! Please check it. Will be changed

Introduction to Socket Programming

Socket Programming. Dr. -Ing. Abdalkarim Awad. Informatik 7 Rechnernetze und Kommunikationssysteme

CSE 333 Lecture network programming intro

Christian Tschudin (basierend auf einem Foliensatz von C. Jelger und T. Meyer) Departement Mathematik und Informatik, Universität Basel

9/13/2007. Motivations for Sockets What s in a Socket? Working g with Sockets Concurrent Network Applications Software Engineering for Project 1

ECE 650 Systems Programming & Engineering. Spring 2018

Concurrent Programming. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Final Exam Introduction to Computer Systems. May 3, Name: Andrew User ID: Recitation Section: This is an open-book exam.

System Programming. Sockets

The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1. Interprocess Communication (IPC) Work Individually (no groups)

Transcription:

Network Programming 15-213 / 18-213: Introduc2on to Computer Systems 21 st Lecture, April. 4, 2012 Instructors: Todd Mowry and Anthony Rowe 1

A Programmer s View of the Internet Hosts are mapped to a set of 32- bit IP addresses 128.2.217.13 The set of IP addresses is mapped to a set of idenafiers called Internet domain names 128.2.217.13 is mapped to www.cs.cmu.edu A process on one Internet host can communicate with a process on another Internet host over a connec.on 2

Internet ConnecAons Carnegie Mellon Clients and servers communicate by sending streams of bytes over connec.ons: Point- to- point, full- duplex (2- way communica2on), and reliable A socket is an endpoint of a connecaon Socket address is an IPaddress:port pair A port is a 16- bit integer that idenafies a process: Ephemeral port: Assigned automa2cally on client when client makes a connec2on request Well- known port: Associated with some service provided by a server (e.g., port 80 is associated with Web servers) A connecaon is uniquely idenafied by the socket addresses of its endpoints (socket pair) (cliaddr:cliport, servaddr:servport) 3

Anatomy of an Internet ConnecAon Client socket address 128.2.194.242:51213 Server socket address 208.216.181.15:80 Client Client host address 128.2.194.242 ConnecAon socket pair (128.2.194.242:51213, 208.216.181.15:80) Server (port 80) Server host address 208.216.181.15 51213 is an ephemeral port allocated by the kernel 80 is a well- known port associated with Web servers 4

A Client- Server TransacAon 4. Client handles response Client process 1. Client sends request 3. Server sends response Server process 2. Server handles request Resource Note: clients and servers are processes running on hosts (can be the same or different hosts) Most network applicaaons are based on the client- server model: A server process and one or more client processes Server manages some resource Server provides service by manipula2ng resource for clients Server ac2vated by request from client (vending machine analogy) 5

Clients Examples of client programs Web browsers, ftp, telnet, ssh How does a client find the server? The IP address in the server socket address iden2fies the host (more precisely, an adapter on the host) The (well- known) port in the server socket address iden2fies the service, and thus implicitly iden2fies the server process that performs that service. Examples of well know ports Port 7: Echo server Port 23: Telnet server Port 25: Mail server Port 80: Web server 6

Using Ports to IdenAfy Services Server host 128.2.194.242 Client host Client Service request for 128.2.194.242:80 (i.e., the Web server) Kernel Web server (port 80) Echo server (port 7) Client Service request for 128.2.194.242:7 (i.e., the echo server) Kernel Web server (port 80) Echo server (port 7) 7

Servers Servers are long- running processes (daemons) Created at boot- 2me (typically) by the init process (process 1) Run con2nuously un2l the machine is turned off Each server waits for requests to arrive on a well- known port associated with a paracular service Port 7: echo server Port 23: telnet server Port 25: mail server Port 80: HTTP server A machine that runs a server process is also o]en referred to as a server 8

Server Examples Web server (port 80) Resource: files/compute cycles (CGI programs) Service: retrieves files and runs CGI programs on behalf of the client FTP server (20, 21) Resource: files Service: stores and retrieve files See /etc/services for a comprehensive list of the port mappings on a Linux machine Telnet server (23) Resource: terminal Service: proxies a terminal on the server machine Mail server (25) Resource: email spool file Service: stores mail messages in spool file 9

Sockets Interface Created in the early 80 s as part of the original Berkeley distribuaon of Unix that contained an early version of the Internet protocols Provides a user- level interface to the network Underlying basis for all Internet applicaaons Based on client/server programming model 10

Sockets What is a socket? To the kernel, a socket is an endpoint of communica2on To an applica2on, a socket is a file descriptor that lets the applica2on read/write from/to the network Remember: All Unix I/O devices, including networks, are modeled as files Clients and servers communicate with each other by reading from and wriang to socket descriptors Client clientfd Server serverfd The main disancaon between regular file I/O and socket I/O is how the applicaaon opens the socket descriptors 11

Overview of the Sockets Interface Client Server socket socket bind open_listenfd open_clientfd connect ConnecAon request listen accept Client / Server Session rio_writen rio_readlineb rio_readlineb rio_writen Await connecaon request from next client close EOF rio_readlineb close 12

Socket Address Structures Generic socket address: For address arguments to connect, bind, and accept Necessary only because C did not have generic (void *) pointers when the sockets interface was designed struct sockaddr { unsigned short sa_family; /* protocol family */ char sa_data[14]; /* address data. */ }; sa_family Family Specific 13

Socket Address Structures Internet- specific socket address: Must cast (sockaddr_in *) to (sockaddr *) for connect, bind, and accept 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) */ }; sin_port AF_INET sa_family sin_family sin_addr 0 0 0 0 0 0 0 0 Family Specific 14

Example: Echo Client and Server On Client greatwhite>./echoserveri 15213 On Server linux> echoclient greatwhite.ics.cs.cmu.edu 15213 type: hello there echo: HELLO THERE type: ^D server connected to BRYANT-TP4.VLSI.CS.CMU.EDU (128.2.213.29), port 64690 server received 12 bytes Connection closed 15

Echo Client Main RouAne #include "csapp.h" Send line to server Receive line from server /* usage:./echoclient host port */ int main(int argc, char **argv) { int clientfd, port; char *host, buf[maxline]; rio_t rio; host = argv[1]; port = atoi(argv[2]); clientfd = Open_clientfd(host, port); Rio_readinitb(&rio, clientfd); printf("type:"); fflush(stdout); while (Fgets(buf, MAXLINE, stdin)!= NULL) { Rio_writen(clientfd, buf, strlen(buf)); Rio_readlineb(&rio, buf, MAXLINE); printf("echo:"); Fputs(buf, stdout); printf("type:"); fflush(stdout); } Close(clientfd); exit(0); } Read input line Print server response 16

Overview of the Sockets Interface Client socket Server socket open_clientfd connect ConnecAon request bind listen accept open_listenfd 17

Echo Client: open_clientfd Carnegie Mellon int open_clientfd(char *hostname, int port) { int clientfd; This funcaon opens a connecaon struct hostent *hp; from the client to the server at struct sockaddr_in serveraddr; hostname:port if ((clientfd = socket(af_inet, SOCK_STREAM, 0)) < 0) return -1; /* check errno for cause of error */ /* Fill in the server's IP address and port */ if ((hp = gethostbyname(hostname)) == NULL) return -2; /* check h_errno for cause of error */ bzero((char *) &serveraddr, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; bcopy((char *)hp->h_addr_list[0], (char *)&serveraddr.sin_addr.s_addr, hp->h_length); serveraddr.sin_port = htons(port); Create socket Create address } /* Establish a connection with the server */ if (connect(clientfd, (SA *) &serveraddr, sizeof(serveraddr)) < 0) return -1; return clientfd; Establish connecaon 18

Echo Client: open_clientfd (socket) n socket creates a socket descriptor on the client Just allocates & ini2alizes some internal data structures AF_INET: indicates that the socket is associated with Internet protocols SOCK_STREAM: selects a reliable byte stream connec2on provided by TCP int clientfd; /* socket descriptor */ if ((clientfd = socket(af_inet, SOCK_STREAM, 0)) < 0) return -1; /* check errno for cause of error */... <more> 19

Echo Client: open_clientfd (gethostbyname) The client then builds the server s Internet address int clientfd; /* socket descriptor */ struct hostent *hp; /* DNS host entry */ struct sockaddr_in serveraddr; /* server s IP address */... /* fill in the server's IP address and port */ if ((hp = gethostbyname(hostname)) == NULL) return -2; /* check h_errno for cause of error */ bzero((char *) &serveraddr, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; serveraddr.sin_port = htons(port); bcopy((char *)hp->h_addr_list[0], (char *)&serveraddr.sin_addr.s_addr, hp->h_length); Check this out! 20

A Careful Look at bcopy Arguments /* DNS host entry structure */ struct hostent {... int h_length; /* length of an address, in bytes */ char **h_addr_list; /* null-terminated array of in_addr structs */ }; struct sockaddr_in {... struct in_addr sin_addr; /* IP addr in network byte order */... }; /* Internet address structure */ struct in_addr { unsigned int s_addr; /* network byte order (big-endian) */ }; struct hostent *hp; /* DNS host entry */ struct sockaddr_in serveraddr; /* server s IP address */... bcopy((char *)hp->h_addr_list[0], /* src, dest */ (char *)&serveraddr.sin_addr.s_addr, hp->h_length); 21

Bcopy Argument Data Structures struct hostent h_length struct in_addr h_addr_list s_addr s_addr... 0 struct sockaddr_in sin_family sin_port AF_INET sin_addr 0 0 0 0 0 0 0 0 struct in_addr s_addr 22

Echo Client: open_clientfd (connect) Finally the client creates a connecaon with the server Client process suspends (blocks) un2l the connec2on is created Aber resuming, the client is ready to begin exchanging messages with the server via Unix I/O calls on descriptor clientfd int clientfd; /* socket descriptor */ struct sockaddr_in serveraddr; /* server address */ typedef struct sockaddr SA; /* generic sockaddr */... /* Establish a connection with the server */ if (connect(clientfd, (SA *)&serveraddr, sizeof(serveraddr)) < 0) return -1; return clientfd; } 23

Echo Server: Main RouAne int main(int argc, char **argv) { int listenfd, connfd, port, clientlen; struct sockaddr_in clientaddr; struct hostent *hp; char *haddrp; unsigned short client_port; port = atoi(argv[1]); /* the server listens on a port passed on the command line */ listenfd = open_listenfd(port); } while (1) { clientlen = sizeof(clientaddr); connfd = Accept(listenfd, (SA *)&clientaddr, &clientlen); hp = Gethostbyaddr((const char *)&clientaddr.sin_addr.s_addr, sizeof(clientaddr.sin_addr.s_addr), AF_INET); haddrp = inet_ntoa(clientaddr.sin_addr); client_port = ntohs(clientaddr.sin_port); printf("server connected to %s (%s), port %u\n", hp->h_name, haddrp, client_port); echo(connfd); Close(connfd); } 24

Overview of the Sockets Interface Client socket Server socket open_clientfd connect ConnecAon request bind listen accept open_listenfd Office Telephone Analogy for Server Socket: Bind: Listen: Accept: Buy a phone Tell the local administrator what number you want to use Plug the phone in Answer the phone when it rings 25

Echo Server: open_listenfd int open_listenfd(int port) { int listenfd, optval=1; struct sockaddr_in serveraddr; /* Create a socket descriptor */ if ((listenfd = socket(af_inet, SOCK_STREAM, 0)) < 0) return -1; /* Eliminates "Address already in use" error from bind. */ if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const void *)&optval, sizeof(int)) < 0) return -1;... <more> 26

Echo Server: open_listenfd (cont.)... /* Listenfd will be an endpoint for all requests to port on any IP address for this host */ bzero((char *) &serveraddr, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; serveraddr.sin_addr.s_addr = htonl(inaddr_any); serveraddr.sin_port = htons((unsigned short)port); if (bind(listenfd, (SA *)&serveraddr, sizeof(serveraddr)) < 0) return -1; /* Make it a listening socket ready to accept connection requests */ if (listen(listenfd, LISTENQ) < 0) return -1; } return listenfd; 27

Echo Server: open_listenfd (socket) socket creates a socket descriptor on the server AF_INET: indicates that the socket is associated with Internet protocols SOCK_STREAM: selects a reliable byte stream connec2on (TCP) int listenfd; /* listening socket descriptor */ /* Create a socket descriptor */ if ((listenfd = socket(af_inet, SOCK_STREAM, 0)) < 0) return -1; 28

Echo Server: open_listenfd (setsockopt) The socket can be given some aiributes... /* Eliminates "Address already in use" error from bind(). */ if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (const void *)&optval, sizeof(int)) < 0) return -1; Handy trick that allows us to rerun the server immediately a]er we kill it Otherwise we would have to wait about 15 seconds Eliminates Address already in use error from bind() Strongly suggest you do this for all your servers to simplify debugging 29

Echo Server: open_listenfd (iniaalize socket address) IniAalize socket with server port number Accept connecaon from any IP address struct sockaddr_in serveraddr; /* server's socket addr */... /* listenfd will be an endpoint for all requests to port on any IP address for this host */ bzero((char *) &serveraddr, sizeof(serveraddr)); serveraddr.sin_family = AF_INET; serveraddr.sin_port = htons((unsigned short)port); serveraddr.sin_addr.s_addr = htonl(inaddr_any); IP addr and port stored in network (big- endian) byte order sin_port AF_INET sa_family sin_family sin_addr INADDR_ANY 0 0 0 0 0 0 0 0 30

Echo Server: open_listenfd (bind) bind associates the socket with the socket address we just created int listenfd; /* listening socket */ struct sockaddr_in serveraddr; /* server s socket addr */... /* listenfd will be an endpoint for all requests to port on any IP address for this host */ if (bind(listenfd, (SA *)&serveraddr, sizeof(serveraddr)) < 0) return -1; 31

Echo Server: open_listenfd (listen) listen indicates that this socket will accept connecaon (connect) requests from clients LISTENQ is constant indicaang how many pending requests allowed int listenfd; /* listening socket */... /* Make it a listening socket ready to accept connection requests */ if (listen(listenfd, LISTENQ) < 0) return -1; return listenfd; } We re finally ready to enter the main server loop that accepts and processes client connecaon requests. 32

Echo Server: Main Loop The server loops endlessly, waiang for connecaon requests, then reading input from the client, and echoing the input back to the client. main() { /* create and configure the listening socket */ } while(1) { /* Accept(): wait for a connection request */ /* echo(): read and echo input lines from client til EOF */ /* Close(): close the connection */ } 33

Overview of the Sockets Interface Client Server socket socket bind open_listenfd open_clientfd connect ConnecAon request listen accept Client / Server Session rio_writen rio_readlineb rio_readlineb rio_writen Await connecaon request from next client close EOF rio_readlineb close 34

Echo Server: accept accept() blocks waiang for a connecaon request int listenfd; /* listening descriptor */ int connfd; /* connected descriptor */ struct sockaddr_in clientaddr; int clientlen; clientlen = sizeof(clientaddr); connfd = Accept(listenfd, (SA *)&clientaddr, &clientlen); accept returns a connected descriptor (connfd) with the same properaes as the listening descriptor (listenfd) n Returns when the connec2on between client and server is created and ready for I/O transfers n All I/O with the client will be done via the connected socket accept also fills in client s IP address 35

Echo Server: accept Illustrated Client clientfd listenfd(3) Server 1. Server blocks in accept, wai.ng for connec.on request on listening descriptor listenfd Client ConnecAon request clientfd listenfd(3) Server 2. Client makes connec.on request by calling and blocking in connect Client clientfd listenfd(3) Server connfd(4) 3. Server returns connfd from accept. Client returns from connect. Connec.on is now established between clientfd and connfd 36

Connected vs. Listening Descriptors Listening descriptor End point for client connec2on requests Created once and exists for life2me of the server Connected descriptor End point of the connec2on between client and server A new descriptor is created each 2me the server accepts a connec2on request from a client Exists only as long as it takes to service client Why the disancaon? Allows for concurrent servers that can communicate over many client connec2ons simultaneously E.g., Each 2me we receive a new request, we fork a child to handle the request 37

Echo Server: IdenAfying the Client The server can determine the domain name, IP address, and port of the client struct hostent *hp; /* pointer to DNS host entry */ char *haddrp; /* pointer to dotted decimal string */ unsigned short client_port; hp = Gethostbyaddr((const char *)&clientaddr.sin_addr.s_addr, sizeof(clientaddr.sin_addr.s_addr), AF_INET); haddrp = inet_ntoa(clientaddr.sin_addr); client_port = ntohs(clientaddr.sin_port); printf("server connected to %s (%s), port %u\n", hp->h_name, haddrp, client_port); 38

Echo Server: echo The server uses RIO to read and echo text lines unal EOF (end- of- file) is encountered. EOF no2fica2on caused by client calling close(clientfd) void echo(int connfd) { size_t n; char buf[maxline]; rio_t rio; } Rio_readinitb(&rio, connfd); while((n = Rio_readlineb(&rio, buf, MAXLINE))!= 0) { upper_case(buf); Rio_writen(connfd, buf, n); printf("server received %d bytes\n", n); } 39

TesAng Servers Using telnet The telnet program is invaluable for tesang servers that transmit ASCII strings over Internet connecaons Our simple echo server Web servers Mail servers Usage: unix> telnet <host> <portnumber> Creates a connec2on with a server running on <host> and listening on port <portnumber> 40

TesAng the Echo Server With telnet greatwhite> echoserver 15213 linux> telnet greatwhite.ics.cs.cmu.edu 15213 Trying 128.2.220.10... Connected to greatwhite.ics.cs.cmu.edu. Escape character is '^]'. hi there HI THERE 41

For More InformaAon W. Richard Stevens, Unix Network Programming: Networking APIs: Sockets and XTI, Volume 1, Second EdiAon, PrenAce Hall, 1998 THE network programming bible Unix Man Pages Good for detailed informa2on about specific func2ons Complete versions of the echo client and server are developed in the text Updated versions linked to course website Feel free to use this code in your assignments 42

Watching Echo Client / Server 43

Ethical Issues Packet Sniffer Program that records network traffic visible at node Promiscuous mode: Record traffic that does not have this host as source or des2na2on University Policy Network Traffic: Network traffic should be considered private. Because of this, any "packet sniffing", or other deliberate attempts to read network information which is not intended for your use will be grounds for loss of network privileges for a period of not less than one full semester. In some cases, the loss of privileges may be permanent. Note that it is permissable to run a packet sniffer explicitely configured in non-promiscuous mode (you may sniff packets going to or from your machine). This allows users to explore aspects of networking while protecting the privacy of others. 44