1.BYTE ORDER: -------------- 16 BIT //////////////////////////////////////////////////////// // MSB // LSB // // HIGH-ORDER BYTE // LOW-ORDER BYTE // // // // //////////////////////////////////////////////////////// ------------------------->BIG ENDIAN BYTE ORDER <------------------------- LITTLE ENDIAN BYTE ORDER NETWORK BYTE ORDER(INTERNET PROTOCOLS): BIG ENDIAN BYTE ORDER MSB HOST BYTE ORDER(SYSTEM BYTE ORDER): (IN i80x86) LITTLE ENDIAN BYTE ORDER LSB 2. CONVERT VALUES BETWEEN HOST AND NETWORK BYTE ORDER ------------------------------------------------------ uint32_t htonl(uint32_t hostlong); htons host to network(short interger) ntohl host to network(interger) ntohs host to network(short interger) 3. CONVERT INTERNET HOST ADDRESS FROM NUMBERS AND DOTS INTO BINARY DATA IN NETWORK BYTE ORDER in_addr_t inet_addr(const char *cp); 4. SOCKET ------------------------- int socket (int NAMESPACE, int STYLE, int PROTOCOL) 4.1 Namespace and address format namespace(protocol family) : start with 'PF_' address format for the namespace : start with 'AF_' Ejemplos: AF_INET --- PF_INET AF_INET6 --- PF_INET6 AF_LOCAL --- PF_LOCAL 4.2 comunication Styles: int SOCK_STREAM (Pipes and FIFOs) int SOCK_DGRAM (Datagrams) 4.3 Protocol For each combination of style and namespace there is a "default protocol", which you can request by specifying 0 as the protocol number. 4.4 Internet Socket Address Formats AF_INET, AF_INET6 struct sockaddr_in : represent socket addresses in the Internet namespace sa_family_t sin_family : address family - AF_INET struct in_addr sin_addr : The Internet address of the host machine unsigned short int sin_port : The port number 4.5 Host Address Data Type struct in_addr : Used in certain contexts to contain an IPv4 Internet host address s_addr : the host address number as an 'uint32_t'. 5. CONNECT TO SOCKET A connection is asymmetric, the "client" acts to request a connection, while the "server" makes a socket and waits for the connection request 4.6.1 Making a Connection the client makes a connection int connect (int SOCKET, struct sockaddr *ADDR, socklen_t LENGTH) SOCKET: File descriptor SOCKET (cliente) ADDR,LENGTH: Server "connect" waits until the server responds to the request.