Introduction to Lab 2 and Socket Programming. -Vengatanathan Krishnamoorthi

Similar documents
CSE 333 Section 8 - Client-Side Networking

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

Computer Network Programming

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks

CSE 333 SECTION 6. Networking and sockets

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

CSE 333 SECTION 8. Sockets, Network Programming

UNIX System Programming Lecture 19: IP Sockets

CSE 333 SECTION 7. Client-Side Network Programming

Outline. Option Types. Socket Options SWE 545. Socket Options. Out-of-Band Data. Advanced Socket. Many socket options are Boolean flags

CSE 333 SECTION 7. Client-Side Network Programming

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

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

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

Introduction to Computer Networks

Internet applications

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

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

Sockets 15H2. Inshik Song

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

IP Addresses, DNS. CSE 333 Summer Teaching Assistants: Renshu Gu William Kim Soumya Vasisht

IP Addresses, DNS. CSE 333 Spring Instructor: Justin Hsia

A Client-Server Exchange

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

Client-side Networking

CLIENT-SIDE PROGRAMMING

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

Networked Applications: Sockets. Goals of Todayʼs Lecture. End System: Computer on the ʻNet. Client-server paradigm End systems Clients and servers

CSc 450/550 Computer Networks Network Architectures & Client-Server Model

Socket Programming. Sungkyunkwan University. Hyunseung Choo Copyright Networking Laboratory

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

Tutorial on Socket Programming

Lecture 2. Outline. Layering and Protocols. Network Architecture. Layering and Protocols. Layering and Protocols. Chapter 1 - Foundation

Review. Preview. Closing a TCP Connection. Closing a TCP Connection. Port Numbers 11/27/2017. Packet Exchange for TCP Connection

CSE/EE 461 Lecture 14. Connections. Last Time. This Time. We began on the Transport layer. Focus How do we send information reliably?

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

CSCI 4061: Sockets and Network Programming

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

Socket Programming TCP UDP

UNIX Sockets. COS 461 Precept 1

Computer Networks Prof. Ashok K. Agrawala

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

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

System Programming. Sockets

Socket Programming for TCP and UDP

Elementary TCP Sockets

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

CptS 360 (System Programming) Unit 17: Network IPC (Sockets)

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

CS321: Computer Networks Introduction to Application Layer

Interprocess Communication Mechanisms

shared storage These mechanisms have already been covered. examples: shared virtual memory message based signals

Oral. Total. Dated Sign (2) (5) (3) (2)

Lab 0. Yvan Petillot. Networks - Lab 0 1

TCP: Three-way handshake

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

2007 Microsoft Corporation. All rights reserved.

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

UDP and TCP. Introduction. So far we have studied some data link layer protocols such as PPP which are responsible for getting data

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

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

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CCNA R&S: Introduction to Networks. Chapter 7: The Transport Layer

CSE 124 Discussion Section Sockets Programming 10/10/17

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

TCP/IP. Chapter 5: Transport Layer TCP/IP Protocols

Memory-Mapped Files. generic interface: vaddr mmap(file descriptor,fileoffset,length) munmap(vaddr,length)

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

Transport Layer Review

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

Lecture 11: IP routing, IP protocols

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani

Different Layers Lecture 21

Chapter 6. The Transport Layer. Transport Layer 3-1

Transport Layer. The transport layer is responsible for the delivery of a message from one process to another. RSManiaol

The Transmission Control Protocol (TCP)

Redesde Computadores(RCOMP)

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

CSE 333 Lecture 16 - network programming intro

The TCP Protocol Stack

CSEP 561 Connections. David Wetherall

Internet Layers. Physical Layer. Application. Application. Transport. Transport. Network. Network. Network. Network. Link. Link. Link.

Azblink API for Sending XMPP Messages via HTTP POST

Randall Stewart, Cisco Systems Phill Conrad, University of Delaware

Connections. Topics. Focus. Presentation Session. Application. Data Link. Transport. Physical. Network

Category: Informational J. Bound J. McCann Hewlett-Packard W. Stevens February 2003

Systems software design NETWORK COMMUNICATIONS & RPC SYSTEMS

Transport Layer. Gursharan Singh Tatla. Upendra Sharma. 1

Chapter 2 - Part 1. The TCP/IP Protocol: The Language of the Internet

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron

Transport Layer (TCP/UDP)

Network Programming in Python. based on Chun, chapter 2; plus material on classes

Interprocess Communication Mechanisms

05 Transmission Control Protocol (TCP)

CS4700/CS5700 Fundamentals of Computer Networks

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

ECE 650 Systems Programming & Engineering. Spring 2018

Network Software Implementations

Group-A Assignment No. 6

Outline. Inter-Process Communication. IPC across machines: Problems. CSCI 4061 Introduction to Operating Systems

Transcription:

Introduction to Lab 2 and Socket Programming -Vengatanathan Krishnamoorthi

Before we start.. Soft deadline for lab 2- February 13 Finish assignment 1 as soon as possible if you have not yet. Hard deadline for assignments- March 11 If you still have issues with login, registration or group write an email immediately to your TA. For change of group/no group-mate remember to cc both new and old group-mates.

What will we do in lab 2? Goals: Learn about WWW and HTTP Learn TCP/IP socket programming to understand HTTP and WWW better Build a simple proxy

What is WWW? It is a world-wide system of interconnected servers which distribute a special type of document. Documents are marked-up to indicate formatting (Hypertexts) This idea has been extended to embed multimedia and other content within the marked-up page.

What is HTTP? HTTP is WWW's application layer protocol. HyperText Transfer Protocol (HTTP) to transfer HyperText Markup (HTML) pages and embedded objects. Works on a client-server paradigm. Needs reliable transport mechanism (TCP).

HTTP Server Router Client

HTTP Note: HTTP server always runs on port 80 Server Router Client

HTTP Note: HTTP server always runs on port 80 Server Router Note: Client can use any unrestricted port Generally >1024 Client

Proxy Acts as intermediary between client and server.

Benefits of a proxy Hide your internal network information (such as host names and IP addresses). You can set the proxy server to require user authentication. The proxy server provides advanced logging capabilities. Proxy servers help you control which services users can access. Proxy-caches can be used to save bandwidth.

HTTP with proxy Note: HTTP server always runs on port 80 Server Proxy listens on a port (>1024) and talks to server on another (>1024) Router Note: Client can use any unrestricted port Generally >1024 Proxy Client

What is a port? A port is an application-specific or processspecific software construct serving as a communications endpoint. The purpose of ports is to uniquely identify different applications or processes running on a single computer and thereby enable them to share a single physical connection to a packet-switched network like the Internet.

Port cont.. Port only identifies processes/applications. W.r.t. Internet, ports are always used together with IP. Notation 192.168.1.1:80 IP address Transport protocol port UDP/TCP

Socket programming These are software constructs used to create ports and perform operations on them. It is a way to speak to other programs using standard Unix file descriptors. We will talk about two types of sockets: Datagram socket Stream socket

Datagram sockets They are connectionless Do not guarantee in order delivery No form of loss recovery No congestion control No flow control

Datagram sockets They are connectionless Do not guarantee in order delivery No form of loss recovery No congestion control No flow control Datagram sockets use UDP

Stream sockets Connection oriented sockets In order and guaranteed delivery Error identification and recovery Congestion control Flow control Stream sockets use TCP protocol

Structs Structs are used to pass values to most socket functions. Read up on the following structs addrinfo (contains address related information) sockaddr (contains socket address) struct addrinfo { int ai_flags; // AI_PASSIVE, AI_CANONNAME, etc. int ai_family; // AF_INET, AF_INET6, AF_UNSPEC int ai_socktype; // SOCK_STREAM, SOCK_DGRAM int ai_protocol; // use 0 for "any" size_t ai_addrlen; // size of ai_addr in bytes struct sockaddr *ai_addr; // struct sockaddr_in or _in6 char *ai_canonname; // full canonical hostname struct sockaddr { unsigned short sa_family; // address family, AF_xxx char sa_data[14]; // 14 bytes of protocol address }; }; struct addrinfo *ai_next; // linked list, next node

Socket programming calls getaddrinfo() Get address information Takes as input Host name Service type (HTTP) or only port number if local Information about IP family(v4 or v6), type of socket. (struct addrinfo) Returns A pointer to a linked list. Lets call this 'result'

Socket programming calls socket() Takes as input Address family Socket type Protocol Returns File descriptor

Socket programming calls bind() Takes as input File descriptor number Address information obtained from getaddrinfo() Address length Returns -1 on error What does this do? Associate the socket with a port number

Socket programing calls connect() Takes as input File descriptor number Address information obtained from getaddrinfo() Address length Returns -1 on error What does this do? Attempts to setup a connection with the other end

Socket programing calls listen() Takes as input File descriptor (fd for the socket/port to listen) Backlog (max queue of incoming connection) Returns -1 on error This must run at the server side to listen to incoming connection

Socket programing calls accept() Takes as input File descriptor number Address information obtained from getaddrinfo() Address length Returns -1 on error Reads through the backlog and picks one from the list to connect to it. Runs at the server side

Socket programing calls send() Takes as input File descriptor number Message Length Returns Number of bytes sent Send is always best effort. If it cant send the whole message, the value returned is smaller.

Socket programing calls recv() Takes as input File descriptor number Buffer Max buffer length Returns Number of bytes received Or -1 on error

Socket programing calls close() Takes as input File descriptor Closes the stream socket (TCP connection tear down)

Assignment description Imagine that you are a conscientious Internet user who wishes to protect your friends and family from viewing inappropriate Web content. In particular, you want them to avoid any Web pages that might insult their intelligence. Specific examples that may come to mind are Web pages that mention SpongeBob, Britney Spears, Paris Hilton, or Norrköping. You must do your best to prevent their Web browsers from viewing these sites.

How do you do that? Well socket programming of course... Build a proxy to which an user can connect to The proxy connects to the server on user's behalf (recollect how proxy works) Proxy receives the response from the server Forwards only 'good' responses to the user Redirects in other case

Browser configuration Proxy listens on a particular port 127.0.0.1 Proxy's port number Make sure it is blank

HTTP basics Recollect lab 1. It contains things that you need in lab 2. HTTP request Get Syn, SynAck, Ack

HTTP basics HTTP response OK

HTTP basics HTTP 1.0 vs HTTP 1.1 Many differences read http://www8.org/w8-papers/5c-protocols/key/key.html For this assignment Connection: close Handshake-Get-response-OK-Teardown Connection: keep-alive Handshake-Get-response-OK-wait-Getresponse What should you use for the proxy?

How to handle connections With connection: keep-alive, the connection is kept open. You are responsible to figure out when the response is completed. With connection: close, the server closes the connection after the response is sent.

How to handle connections With connection: keep-alive, the connection is kept open. You are responsible to figure out when the response is completed. With connection: close, the server closes the connection after the response is sent. How can you enforce connection: close on HTTP 1.1?

General overlay Server Client side Server side Proxy Client

General overlay Server side: listens on a port, accepts, receives, forwards to client side Server Client side Server side Proxy Client

General overlay Client side: connects to the server, send request, receive response, Forwards to client side Server Client side Server side Proxy Client

Content filtering Need to be able to filter both based on URL and content. In which of the two halves of the proxy will you implement filtering based on URL? In which of the two halves of the proxy will you implement content filtering? How to actually do content filtering?

Content filtering Response from the server comes in segments Remember TCP segmentation?

Content filtering Response from the server comes in segments Remember TCP segmentation? Reconstruct the message in a temporary buffer Then run filtering on the message

Text vs other binary data What is the requirement for filtering w.r.t binary data? Only that you have to be smart in handling any data type What will happen if you attempt to reconstruct an image or video and try to filter it? Solutions?

Text vs binary data Content-type header Differentiate content type Run/don't run filtering Send data or block the client

How to block specific content You are supposed to return a specific response based on URL filtering or content filtering HTTP redirect If filtering confirms presence of inappropriate words HTTP/1.1 301 Moved Permanently Else send response

Debugging advice Stick to simple web pages initially Debug incrementally Check and double check request string for formatting and completeness Source of many errors like 'server closed connection unexpectedly' If developing on own computers, use wireshark to debug. Can save a lot of time!

Debugging advice HTTP vs HTTPS Requirements do not ask for a proxy which works with HTTPS Avoid testing on any site to which you are signed in Restrict yourselves to simple sites and basic test cases

Debugging advice Header manipulation First thing to check at a proxy is the URL that it sends out to the server It might require different manipulations based on the site. Be sure that you test for all sites mentioned in the test scenario If you change some fields in the header, the packet length has to be changed or brought back to the original length

Questions? Good Luck!!