Kiran-SocketProgramming

There must be a generic way to specify endpoint

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: ust be a generic way to specify endpoint endpoint addresses. • TCP/IP requires an IP address and a port number for each endpoint address. • Other protocol suites (families) may use other schemes. Specifying Specifying an Endpoint Address 20 4 3 2 1 0 Descriptor Table ECEN 602 Socket Programming Family: AF_INET Service: SOCK_STREAM Local IP: 111.22.3.4 Remote IP: 123.45.6.78 Local Port: 2249 Remote Port: 3726 Socket Socket Descriptor Data Structure 21 address family length of struct IPv4 address IP port number ECEN 602 Socket Programming sa_family_t socklen_t in_addr_t in_port_t Some Some data types that are used 22 { sa_len; sa_family; sa_data[14]; ECEN 602 Socket Programming • sa_family specifies the address type. • sa_data specifies the address value. struct sockaddr uint8_t sa_family_t char char }; Generic Generic socket addresses 23 ECEN 602 Socket Programming – 16 bit port number – 32 bit IP address For AF_INET we need: AF_INET AF_INET 24 ECEN 602 Socket Programming A special kind of sockaddr structure struct sockaddr_in { uint8_t sin_len; sa_family_t sin_family; in_port_t sin_port; struct in_addr sin_addr; char sin_zero[8]; }; struct struct sockaddr_in (IPv4) 25 ECEN 602 Socket Programming However, the architectures of the two end hosts could be different, i.e., one is little endian and the other is big endian Bytes travel through the network in a stream of bytes. Network Network Byte Order 26 ECEN 602 Socket Programming Network Network Byte Order (Contd..) 27 – sin_port – sin_addr ECEN 602 Socket Programming a TCP/IP port number. an IP address. sockaddr_in • All values stored in a sockaddr_in must be in network byte order. Network Network Byte Order (Contd..) 28 ‘l’ : long (32bit) ‘s’ : short (16bit) ECEN 602 Socket Programming uint32_t htonl(uint32_t); uint32_t ntohl(uint32_t); uint16_t htons(uint16_t); uint16_t ntohs(uint_16_t); ‘n’ : network byte order ‘h’ : host byte order Network Network Byte Order Functions 29 ECEN 602 Socket Programming BUT: The C functions that make up the sockets API expect structures of type sockaddr sockaddr. sockaddr • We...
View Full Document

Ask a homework question - tutors are online