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

Similar documents
CSE 333 SECTION 7. Client-Side Network Programming

CSE 333 SECTION 6. Networking and sockets

CSE 333 SECTION 7. Client-Side Network Programming

CSE 333 SECTION 8. Sockets, Network Programming

CSE 333 Lecture 16 - network programming intro

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

CSE 333 Lecture network programming intro

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

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

CSE 333 Lecture 8 - file and network I/O

CSE 333 Section 8 - Client-Side Networking

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

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

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

CSE 124 Discussion Section Sockets Programming 10/10/17

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

Client-side Networking

CLIENT-SIDE PROGRAMMING

IPv6 Porting Applications

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

목포해양대해양컴퓨터공학과. IPv6 적용

CMPSC 311- Introduction to Systems Programming Module: Network Programming

CMPSC 311- Introduction to Systems Programming Module: Network Programming

Computer Network Programming

Azblink API for Sending XMPP Messages via HTTP POST

Introduction to Lab 2 and Socket Programming. -Vengatanathan Krishnamoorthi

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Socket Programming(2/2)

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

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

ECE 435 Network Engineering Lecture 2

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

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

CS321: Computer Networks Socket Programming

C Structures in Practice

Network Programming: Part I

last time redo logging copy-on-write filesystems / snapshots distributed systems motivation, etc.

Network programming(i) Lenuta Alboaie

Redesde Computadores(RCOMP)

CS321: Computer Networks Introduction to Application Layer

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

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

UNIX System Programming Lecture 19: IP Sockets

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

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

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

Lab 0. Yvan Petillot. Networks - Lab 0 1

ECE 435 Network Engineering Lecture 2

Internet Engineering Task Force (IETF) July 2011

Socket Programming TCP UDP

CS 3516: Computer Networks

Tutorial on Socket Programming

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

System Programming. Sockets

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

#include <dirent.h> int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen); DIR *opendir(const char *name);

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

Networks class. CS144 Introduction to Computer Networking. Administrivia. Administrivia 2. Grading. Labs. Goal: Teach the concepts underlying networks

UNIX Network Programming. Overview of Socket API Network Programming Basics

Server-side Programming

A Client-Server Exchange

The exam is closed book, closed notes, closed electronics, closed telepathy, open mind.

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

CSCI 4061: Sockets and Network Programming

Beej's Guide to Network Programming

Beej's Guide to Network Programming

Modern System Calls(IPv4/IPv6)

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

Chapter 16. Network IPC: Sockets

Write your answer on the next page. You may remove this page for reference while working if you wish.

2007 Microsoft Corporation. All rights reserved.

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

Network Socket Programming - 3 BUPT/QMUL

UNIVERSITY OF LIEGE Faculty of Applied Sciences Montéfiore Electricity Institute. Extension of a network scanning tool with IPv6 features (Nmap)

Porting IPv4 applications to IPv4/v6 dual stack. Owen DeLong

Lecture 7 Overview. IPv6 Source: Chapter 12 of Stevens book Chapter 31 of Comer s book

Network Programming November 3, 2008

TCP: Three-way handshake

5. System Calls or Bust

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

IBM i Version 7.3. Programming Socket programming IBM

Application Programming Interfaces

Application Layer. Application Layer. QoS and Network Policies. Quality of Service (QoS)

TCP Network Programming in C

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

Network Socket Programming - 3 BUPT/QMUL

CS 640: Computer Networking

Programming guidelines on transition to IPv6

TCP/IP Sockets in C: Practical Guide for Programmers. Computer Chat. Internet Protocol (IP) IP Address. Transport Protocols. Ports

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

Outline. Distributed Computing Systems. Socket Basics (1 of 2) Socket Basics (2 of 2) 3/28/2014

Introduction to Socket Programming

Writing Network Applications using the TCP/IP Protocol Stack: Socket Programming

Introduction to Computer Networks

Announcements. CS 5565 Network Architecture and Protocols. Queuing. Demultiplexing. Demultiplexing Issues (1) Demultiplexing Issues (2)

Winsock Server adding Multiple clients support C++

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

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

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

Transcription:

CSE 333 Section 3 Thursday 12 April 2012

Goals for Today 1. Overview IP addresses 2. Look at the IP address structures in C/C++ 3. Overview DNS 4. Talk about how to use DNS to translate IP addresses 5. Write your own (short!) program to do this translation 6. Go over the solution

Networks from 10,000ft Internet clients servers

Internet clients servers Clients talk to Servers Servers respond to Clients... But how do they know how to reach each other?... And how do we know if a response is for Firefox or Mail?

Network addresses For IPv4, an IP address is a 4-byte tuple - e.g., 128.95.4.1 (80:5f:04:01 in hex) For IPv6, an IP address is a 16-byte tuple - e.g., 2d01:0db8:f188:0000:0000:0000:0000:1f33 2d01:0db8:f188::1f33 in shorthand

There are lots of structs coming up...... we ll walk through them one at a time.

IPv4 address structures // Port numbers and addresses are in *network order*. // A mostly-protocol-independent address structure. struct sockaddr { short int sa_family; // Address family; AF_INET, AF_INET6 char sa_data[14]; // 14 bytes of protocol address }; // An IPv4 specific address structure. struct sockaddr_in { short int sin_family; // Address family, AF_INET == IPv4 unsigned short int sin_port; // Port number struct in_addr sin_addr; // Internet address unsigned char sin_zero[8]; // Same size as struct sockaddr }; struct in_addr { uint32_t s_addr; // IPv4 address };

IPv6 address structures // A structure big enough to hold either IPv4 or IPv6 structures. struct sockaddr_storage { sa_family_t ss_family; // address family }; // a bunch of padding; safe to ignore it. char ss_pad1[_ss_pad1size]; int64_t ss_align; char ss_pad2[_ss_pad2size]; // An IPv6 specific address structure. struct sockaddr_in6 { u_int16_t sin6_family; // address family, AF_INET6 u_int16_t sin6_port; // Port number u_int32_t sin6_flowinfo; // IPv6 flow information struct in6_addr sin6_addr; // IPv6 address u_int32_t sin6_scope_id; // Scope ID }; struct in6_addr { unsigned char s6_addr[16]; // IPv6 address };

Generating these structures Often you have a string representation of an address - how do you generate one of the address structures? #include <stdlib.h> #include <arpa/inet.h> int main(int argc, char **argv) { struct sockaddr_in sa; // IPv4 struct sockaddr_in6 sa6; // IPv6 // IPv4 string to sockaddr_in. inet_pton(af_inet, "192.0.2.1", &(sa.sin_addr)); // IPv6 string to sockaddr_in6. inet_pton(af_inet6, "2001:db8:63b3:1::3490", &(sa6.sin6_addr)); } return EXIT_SUCCESS;

Generating these structures How about going in reverse? #include <stdlib.h> #include <arpa/inet.h> int main(int argc, char **argv) { struct sockaddr_in6 sa6; // IPv6 char astring[inet6_addrstrlen]; // IPv6 // IPv6 string to sockaddr_in6. inet_pton(af_inet6, "2001:db8:63b3:1::3490", &(sa6.sin6_addr)); // sockaddr_in6 to IPv6 string. inet_ntop(af_inet6, &(sa6.sin6_addr), astring, INET6_ADDRSTRLEN); printf( %s\n, astring); } return EXIT_SUCCESS;

DNS People tend to use DNS names, not IP addresses - the sockets API lets you convert between the two - it s a complicated process, though: a given DNS name can have many IP addresses many different DNS names can map to the same IP address an IP address will reverse map into at most one DNS names, and maybe none a DNS lookup may require interacting with many DNS servers You can use the dig Linux program to explore DNS - man dig

DNS hierarchy A B C M. -- root name servers 198.41.0.4 (a.root-servers.net) 192.228.79.201 (b.root-servers.net) 202.12.27.33 (m.root-servers.net) com xxx uk org.com. -- top-level domain server google yahoo hulu gribble apache fsf www mail docs finance seattle www

Resolving DNS names The POSIX way is to use getaddrinfo( ) - a pretty complicated system call; the basic idea... set up a hints structure with constraints you want respected e.g., IPv6, IPv4, or either tell getaddrinfo( ) which host and port you want resolved host: a string representation; DNS name or IP address getaddrinfo( ) gives you a list of results packet in an addrinfo struct free the addrinfo structure using freeaddrinfo( )

getaddrinfo() and structures int getaddrinfo(const char *hostname, // hostname to look up const char *servname, // service name const struct addrinfo *hints, //desired output type struct addrinfo **res); //result structure // Hints and results take the same form. Hints are optional. struct addrinfo { int ai_flags; // Indicate options to the function int ai_family; // AF_INET, AF_INET6, or AF_UNSPEC int ai_socktype; // Socket type, (use SOCK_STREAM) int ai_protocol; // Protocol type size_t ai_addrlen; // INET_ADDRSTRLEN, INET6_ADDRSTRLEN char *ai_cananname;// canonical name for the host struct sockaddr *ai_addr; // Address (input to inet_ntop) struct addrinfo *ai_next; // Next element (It s a linked list) }; // Converts an address from network format to presentation format const char *inet_ntop(int af, // family (see above) const void * restrict src, // sockaddr char * restrict dest, // return buffer socklen_t size); // length of buffer

DNS lookup program Take in an argument to translate to ip (e.g. google.com ) If you don t want to take in an argument look up my CSE machine: cerise.cs.washington.edu ---> 128.208.6.34 Setup/initialize your hints addrinfo struct (remember to free it later!) zero out everything except ai_family and ai_socktype Use getaddrinfo() to ask DNS for the IP you can use gai_strerror() to translate error codes Cycle through returned addresses, printing results use inet_ntop() to get a nice string out you need to distinguish between IPv4 and IPv6

Don t worry about getting it perfect, we just want you to work with the structures and be familiar with them.

Let s go over the solution...