CSE 333 SECTION 6. Networking and sockets



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

Elementary Name and Address. Conversions

IPv6 Enabling CIFS/SMB Applications

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

NS3 Lab 1 TCP/IP Network Programming in C

Introduction to Socket programming using C

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

IBM i Version 7.2. Programming Socket programming IBM

Name and Address Conversions

Tutorial on Socket Programming

Best practices in IPv6 enabled networking software development.

Socket Programming. Srinidhi Varadarajan

Beej's Guide to Network Programming

Network Programming with Sockets. Anatomy of an Internet Connection

Concurrent Server Design Alternatives

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

Implementing Network Software

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

Unix Network Programming

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

IPv6 Applications. Piers O Hanlon

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

Communication Networks. Introduction & Socket Programming Yuval Rochman

Programming guidelines on transition to IPv6

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

Lab 4: Socket Programming: netcat part

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

Windows Socket Programming & IPv6 Translation Middleware

IPv6 Applications. Location, country Date. Speaker name (or address)

Application Architecture

Client / Server Programming with TCP/IP Sockets

UNIX. Sockets. mgr inż. Marcin Borkowski

TCP/IP - Socket Programming

Programmation Systèmes Cours 9 UNIX Domain Sockets

Review of Previous Lecture

Generalised Socket Addresses for Unix Squeak

416 Distributed Systems. Feb 24, 2016 DNS and CDNs

Socket Programming in C/C++

An Overview of IPv6 CHAPTER

UNIX Sockets. COS 461 Precept 1

IPv6 Applications. Formation IPv6 RENATER -Rouen, FR

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

IPv4/IPv6 Transition for SIP VoIP Applications

Elementary Name and Address Conversions

BSD Sockets Interface Programmer s Guide

TCP/IP Sockets in C. Practical Guide for Programmers

sys socketcall: Network systems calls on Linux

ELEN 602: Computer Communications and Networking. Socket Programming Basics

Computer Networks Network architecture

Porting and Deploying VoIP to IPv6: Lessons Learned

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

Software changes for Website and Application IPv6 Readiness

The POSIX Socket API

URI and UUID. Identifying things on the Web.

Category: Standards Track August 1995

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

Network Layers. CSC358 - Introduction to Computer Networks

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

Writing a C-based Client/Server

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

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

Lecture 7: Introduction to Sockets

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

Programming with TCP/IP Best Practices

Application. Transport. Network. Data Link. Physical. Network Layers. Goal

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

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

Theater Key Retrieval (TKR)

Network Programming. Chapter The Client-Server Programming Model

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

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

Lab - Observing DNS Resolution

Outline Computer Networking. IPv6 Addressing. IPv IPv Translation: too many names and addresses!

CS3250 Distributed Systems

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

Understand Names Resolution

1 Operating Systems Prof. Dr. Marc H. Scholl DBIS U KN Summer Term IPC may often be used for both

IP addressing. Interface: Connection between host, router and physical link. IP address: 32-bit identifier for host, router interface

Lab - Observing DNS Resolution

DNS Domain Name System

The Facts. 1 The Facts. IPv6 Protocol. IPv6 Addresses. 2 IPv6 Protocol. IPv6. mechanisms. 3 IPv6 Addresses. Routing Protocols.

CS640: Computer Networks. Naming /ETC/HOSTS

An API for Reading the MySQL Binary Log

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

15-441: Computer Networks Homework 1

ECE 4321 Computer Networks. Network Programming

Porting and Running Asterisk to IPv6

NET0183 Networks and Communications

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

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.

Packet Sniffing and Spoofing Lab

Operating Systems Design 16. Networking: Sockets

Motivation. Domain Name System (DNS) Flat Namespace. Hierarchical Namespace

App Note. VoxStack GSM Gateway API

Giving credit where credit is due

AT12181: ATWINC1500 Wi-Fi Network Controller - AP Provision Mode. Introduction. Features. Atmel SmartConnect APPLICATION NOTE

Copyright

RIOT-Lab. How to use RIOT in the IoT-Lab. Oliver "Oleg" Hahm. November 7, 2014 INRIA. O. Hahm (INRIA) RIOT-Lab November 7, / 29

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

CHAPTER 7. ing with CGI

Transcription:

CSE 333 SECTION 6 Networking and sockets

Goals for Today Overview of IP addresses Look at the IP address structures in C/C++ Overview of DNS Write your own (short!) program to do the domain name IP address translation

Networks

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

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 #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 #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 Domain Name System/Service A hierarchical distributed naming system any resource connected to the Internet or a private network. Resolves queries for names into IP addresses. The sockets API lets you convert between the two. Is on the application layer on the Internet protocol suite.

DNS hierarchy

Resolving DNS names The POSIX way is to use getaddrinfo( ). Set up a hints structure with constraints, 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 in an addrinfo struct.

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 exercise Write a C++ program dnsresolve.cc that: Takes a hostname as an argument (e.g. google.com or cs.washington.edu) Returns the IPv4 addresses associated with it. Optional: Fix it so it retrieves both IPv4 and IPv6 addresses. Steps (Recommended) Setup/initialize hints and results addrinfo structs (remember to free them later!). Zero out everything in hints, and separately set the ai_family and ai_socktype. Use getaddrinfo() to ask DNS for the IP addresses. Use gai_strerror() to translate error codes for getaddrinfo() failures. Cycle through returned addresses and use inet_ntop() to get a nice string out and print the results. Free the addrinfo struct list returned by getaddrinfo() using freeaddrinfo(). For the extra credit part: Distinguish between IPv4 and IPv6 addresses while printing.