CSE 333 – SECTION 8 Networking and sockets. Overview Network Sockets IP addresses and IP address structures in C/C++ DNS – Resolving DNS names Demos.

Slides:



Advertisements
Similar presentations
Network Programming Week #1 J.P. Yoo
Advertisements

Socket Programming 101 Vivek Ramachandran.
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Socket Programming CS3320 Fall 2010.
CS 4700 / CS 5700 Network Fundamentals
Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
IPv6 Technologies and Advanced Services page 1 Porting applications to IPv6 OpenH323 and IPv6 support K. Stamos Computer Engineer, University of Patras.
Chapter 10 IPv4 and IPv6 Interoperability. contents Introduction IPv4 Client, IPv6 Server IPv6 Client, IPv4 Server IPv6 Address Testing Macros IPV6_ADDRFORM.
Ipv4 Socket Address Structure struct in_addr { in_addr_t s_addr; /* 32-bit IPv4 address */ /* network byte ordered */ }; struct sockaddr_in { uint8_t sin_len;
Socket Programming with IPv6. Why IPv6? Addressing and routing scalability Address space exhaustion Host autoconfiguration QoS of flow using flowlabel.
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Taekyung Kim 0x410 ~ 0x International Standards Organization (ISO) is a multinational body dedicated to worldwide agreement on international.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
CS252: Systems Programming Ninghui Li Based on slides by Prof. Gustavo Rodriguez-Rivera Topic 16: Socket Programming & Project 5.
Socket Programming Application Programming Interface.
Sockets Programming CS144 Review Session 1 April 4, 2008 Ben Nham.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
Tutorial 8 Socket Programming
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Introduction to Project 1 Web Client and Server Jan 2006.
UNIX Sockets COS 461 Precept 1. Clients and Servers Client program – Running on end host – Requests service – E.g., Web browser Server program – Running.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Assignment 3 A Client/Server Application: Chatroom.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
Client-Side Network Programming
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
Sockets API Overview Sockets with UDP Sockets with TCP Fast Sockets (Fast UDP) IP Multicasting.
Remote Shell CS230 Project #4 Assigned : Due date :
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
UNIX Sockets COS 461 Precept 1. Socket and Process Communication The interface that the OS provides to its networking subsystem application layer transport.
Introduction to Socket
Socket Programming Lab 1 1CS Computer Networks.
TELE 402 Lecture 6: Name and address conversions 1 Overview Last Lecture –Socket Options and elementary UDP sockets This Lecture –Name and address conversions.
Socket Programming.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Chapter 11 Advanced Name and Address Conversion. Introduction gethostbyname, gethostbyaddr: protocol dependent getaddrinfo: –a function providing protocol.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
Sockets Intro to Network Programming. Before the internet... Early computers were entirely isolated No Internet No network No model No external communications.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
CSE 333 – SECTION 8 Client-Side Network Programming.
Sockets and Beginning Network Programming
UNIX Sockets COS 461 Precept 1.
Socket Programming (Cont.)
Socket Programming in C
Client-side Networking CSE 333 Spring 2018
Socket Programming in C
IP Addresses, DNS CSE 333 Spring 2018
IP Addresses, DNS CSE 333 Summer 2018
Client-side Networking CSE 333 Summer 2018
IP Addresses, DNS CSE 333 Autumn 2018
IP Addresses, DNS CSE 333 Winter 2019
Socket Programming(1/2)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Client-side Networking CSE 333 Winter 2019
Internet Networking recitation #8
Sockets.
Client-side Networking CSE 333 Spring 2019
Presentation transcript:

CSE 333 – SECTION 8 Networking and sockets

Overview Network Sockets IP addresses and IP address structures in C/C++ DNS – Resolving DNS names Demos

Sockets Network sockets are network interfaces Endpoints in an interprocess communication flow Socket address = IP address + port number Socket API Programs to control and use sockets

Pictorially Web server fd 5 fd 8 fd 9 fd 3 index.html pic.png clientclientclientclient : : Internet filedescriptortype connected to? 0pipe stdin (console) 1pipe stdout (console) 2pipe stderr (console) 3TCPsocket local: :80 remote: :7113 5fileindex.html 8filepic.png 9 TCPsocket local: :80 remote: :5544 OS’s descriptor table

How sockets work Step 1: The socket() API creates an endpoint for communications and returns a socket descriptor that represents the endpoint. Step 2: When an application has a socket descriptor, it can bind a unique name to the socket. Servers must bind a name to be accessible from the network. Step 3: The listen() API indicates a willingness to accept client connection requests.

Sockets continued Step 4: The client application uses a connect() API on a stream socket to establish a connection to the server. Step 5: The server application uses the accept() API to accept a client connection request. Step 6: Use read(), write(), send(), recv(), etc to transfer data. Step 7: Issue a close() API to release any system resources acquired by the socket.

Network Addresses For IPv4, an IP address is a 4-byte tuple - e.g., (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 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, " ", &(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 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.

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

nc - Netcat utility Demo simple nc usage.

sendreceive.cc