CS 311 – Lecture 19 Outline Internet Sockets – gethostname utility – struct hostent – inet_addr – Machine byte to Network byte order translation and vice.

Slides:



Advertisements
Similar presentations
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Advertisements

Socket Programming CS3320 Fall 2010.
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;
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
Name and Address Conversions© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
Network Programming UNIX Internet Socket API. Everything in Unix is a File –When Unix programs do any sort of I/O, they do it by reading or writing to.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
Tutorial 8 Socket Programming
#include DatatypeDescription int8_t uint8_t int16_t uint16_t int32_t uint32_t Signed 8-bit integer Unsigned 8-bit integer Signed 16-bit integer Unsigned.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
Introduction to Socket Programming April What is a socket? An interface between application and network –The application creates a socket –The socket.
Unix Network Programming Part 2: Elementary Sockets Jani Peusaari.
Introduction to Project 1 Web Client and Server Jan 2006.
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
Network Programming Sockets and Winsock. Please Be Responsible We all know that the Internet is full of security holes –most of them do not require any.
ECE453 – Introduction to Computer Networks Lecture 15 – Transport Layer (II)
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Operating Systems Chapter 9 Distributed Communication.
Netprog: DNS and name lookups1 Address Conversion Functions and The Domain Name System Refs: Chapter 9 RFC 1034 RFC 1035.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Elementary Name and Address Conversions
Computer Systems II CSC 2405 Network Programming.
Sirak Kaewjamnong Computer Network Systems
CSTP FS01CS423 (cotter)1 Protocols 2 References: RFC’s 791, 793, 768, 826.
1 CMPT 471 Networking II Transport Layer Network Programming © Janice Regan, 2013.
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
Technical Details for sockaddr_in Structure Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Lab 5 Sockets. Useful Sockets Links (courtesy of Stanford University) Programming UNIX Sockets in C - Frequently Asked Questions
Network Programming with Sockets Reading: Stevens 3rd ed., Ch. 3-6, or 2 nd ed. Beej's Guide to Network Programming 1.
Elementary Name and Address Conversions
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.
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.
Network Programming.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 25 Acknowledgements: The syllabus and power point presentations are modified versions.
Socket address structures Byte ordering IP address conversion
Sockets Introduction Socket address structures Value-result arguments
UNIX Internet Socket API
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
1 Network Programming. 2 Background Important guidelines –Use conductor.tamucc.edu or any LINUX machine to develop your network applications –Do not use.
In unistd.h : int gethostname(char * name, int maxlen) Purpose : Find the computer's name.
EECS340 Recitation 1: Very helpful to your project Hongyu Gao 1.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
Computer networks Name: K.SUDHA Designation: Lecturer Department: Electrical and Electronics Engineering Subject code: CS2361 Year: III Unit: V Title:
Client-Server model. Socket programming 
Name and Address Conversions
Name/Address conversion:
Socket programming Péter Verhás August 2002
Onward with Chat! Networking CS 3470, Section 1.
Introduction to Unix Network Programming
Building an Internet Router
Network Programming CSC- 341
Socket Programming (Cont.)
Internet Address Routines
CpSc 360: Distributed and Network Programming
Chapter4 Elementary TCP Socket
Network Programming with Sockets
Sockets.
Things that are nice to know when you’re doing this project
Recitation 11 – 4/29/01 Outline Sockets Interface
Basic Internet Components
CS 5565 Network Architecture and Protocols
Socket Programming(1/2)
in unistd.h: int gethostname(char * name, int maxlen)
Presentation transcript:

CS 311 – Lecture 19 Outline Internet Sockets – gethostname utility – struct hostent – inet_addr – Machine byte to Network byte order translation and vice versa Lecture 191CS311 - Operating Systems I

Internet Sockets Processes communicate via network. Two identify a process on the network we need – IP address of the process (IPv4 or IPv6) – Port number where the process listens Lecture 192CS311 - Operating Systems I

Getting the IP Address To get the IP address in network byte order for the IP that is known use inet_addr(). Prototype: in_addr_t inet_addr(const char *string) – Returns the 32-bit IP of network byte order corresponding to the A.B.C.D string. If IP not known then we can get that using gethostname() and gethostbyname() Lecture 193CS311 - Operating Systems I

gethostname() and gethostbyname() gethostname() returns the host’s name where the process is executing. Prototype: int gethostname(char *name, int namelen) gethostbyname() returns a pointer to struct hostent Protoype: struct hostent * gethostbyname(const char *name) – The only parameter is the hostname. – Searches the /etc/host or the DNS database to get the structure information. Lecture 194CS311 - Operating Systems I

struct hostent The structure has these members – char *h_name - “official” name of the host. – char **h_aliases - alternative names for the host – int h_addrtype - either AF_INET or AF_INET6 – int h_length - length, in bytes, of each address. – char **h_addr_list – array of addresses for the host. – char *h_addr - first host address (or *h_addr_list[0]). Lecture 195CS311 - Operating Systems I

inet_ntoa() and inet_aton() inet_ntoa() - Takes IP address in network-byte order and converts to string format. Prototype: char *inet_ntoa(struct in_addr addr) inet_aton() – same as inet_addr() but better Prototype: int inet_aton(const char *addr, struct in_addr *addr) – Stores the char* addr into struct in_addr Lecture 196CS311 - Operating Systems I

memset() and others memset() sets a block of memory to the desired value. Prototype: void * memset (void * ptr, int value, size_t num); memcpy() copies a block of memory to another block. Prototype: void * memcpy ( void * destination, const void * source, size_t num ); memcmp() compares two blocks of memory Prototype: int memcmp ( const void * ptr1, const void * ptr2, size_t num ); Lecture 197CS311 - Operating Systems I

bzero() and bcopy() bzero() same as memset() but initializes a block of memory to zero. Prototype: void bzero (void* buffer, size_t length) bcopy() is the same as memcpy() Lecture 198CS311 - Operating Systems I

Machine-byte to network-byte Converting machine-byte order to network order Protoype: – in_port_t htons (in_port_t hostShort) – in_addr_t ntohl (in_addr_t networkLong) Converting network-byte to machine-byte Prototype: – in_port_t ntohs (in_port_t networkShort) – in_addr_t htonl (in_addr_t hostLong) Lecture 199CS311 - Operating Systems I