Review of Donahoo Chapter 2,3,4 (TCP sockets, Addressing/naming
services, UDP sockets. This book presents very basic
examples of sockets programs written in "C".
The UDPEcho code is here: https://people.cs.clemson.edu/~jmarty/courses/CPSC6240-Student/code/UDPEcho/
The TCPEcho code is here: https://people.cs.clemson.edu/~jmarty/courses/CPSC6240-Student/code/TCPEcho/
- Ch2 assumes address parameters passed to client programs are
address numbers (i.e., dotted quad notation for V4).
- It shows how to deal with V6 programs .... but to best support
V4 and V6 use the Address Naming Service approach described in
Ch3.
- Socket addresses:
- Generic struct :
- IP V4 version - two parts.
- struct in_addr
- uint32_t s_addr; 4 octets
- struct sockaddr_in
- ....struct in_addr sin_addr ; the actual IP V4
address, 4 octets
- ....
- IP V6 : NOTE: I believe p.24 of the second edition of
Donahoo has a typo...the IPV6 structs should be:
- struct in6_addr
- uint8_t s_addr[16] : IPV6 address is 16 octets
- struct sockaddr_in6
- ...struct in6_addr sin6_addr;
- ...
- Routines for converrting string Address numbers to binary
addresses - examples below assume IP V6 addresses
- int inet_pton(int addressFamily, const char *src, void
*dst)
- Printable to numeric
- Need to know if it's AF_INET or AF_INET6),
- Caller provides string in src ptr
- Result is placed in callers memory pointed to by dst.
- Caller can allocate memory to hold the largest
possible string name for IPV6 address number:
- char str[INET6_ADDRSTRLEN];\
- struct sockaddr_storage myAddress; //the
system ensures this is large enough
- Caller invokes: inet_pton(AF_INET6,(char
*)str, (void *)&myAddress;
- int inet_ntop(int addressFamily,const void *src, char
*dst, socklen_t dstBytes);
- Numeric to printable
- caller's IP V6 address (struct in6_addr sin6_addr) is
pointed to by the src ptr
- The returned printable address number (string) is
returned in the callers dst ptr (or up to dstBytes - the
caller indicates the size of its string buffer
- The client can allocate the string buffer using:
- char str[INET6_ADDRSTRLEN];\
Last update: 3/13/2019