Ushort sinport htons port struct inaddr sinaddr

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ad/write: send/recv! •  Stream sockets: bi- direc)onal pipes –  With IP, gives you TCP –  Bytes wriben on one end read on another –  Reads may not return full amount requested, must re- read System calls for using TCP Client socket – make socket Server socket – make socket bind – assign address, port listen – listen for clients bind* – assign address connect – connect to listening socket accept – accept connec)on •  This call to bind is op)onal, connect can choose address & port. Socket Naming •  Naming of TCP & UDP communica)on endpoints –  IP address specifies host (129.7.240.18) –  16- bit port number demul)plexes within host –  Well- known services listen on standard ports (e.g. ssh – 22, hbp – 80, see /etc/services for list) –  Clients connect from arbitrary ports to well known ports •  A connec)on is named by 5 components –  Protocol, local IP, local port, remote IP, remote port –  TCP requires connected sockets, but not UDP Socket Address Structures •  Socket interface supports mul)ple network types •  Most calls take a generic sockaddr: struct sockaddr {! uint16_t sa_family; /* address family */! char sa_data[14]; /* protocol-specific addr */! };! •  E.g. int connect(int s, struct sockaddr* srv, ! socklen_t addrlen);! •  Cast sockaddr * from protocol- specific struct, e.g., struct sockaddr_in { ! !short sin_family; /* = AF_INET */ ! !u_short sin_port; /* = htons (PORT) */ ! !struct in_addr sin_addr; /*32-bit IPv4 addr */! !chars ! in_zero[8];! }; ! Dealing with Address...
View Full Document

This note was uploaded on 01/27/2014 for the course COSC 4377 taught by Professor Staff during the Spring '08 term at University of Houston.

Ask a homework question - tutors are online