Posted on 1998-08-26
In Stevens' book "Unix Network Programming" is the source code for an Internet ping client. The following part of the code, however, puzzles me:
struct sockaddr_in dest;
host = gethostbyname(argv);
bcopy(host->h_addr, (caddr_t) &dest.sin_addr, host->h_length);
What I don't understand is why the h_addr member of the structure pointed to by host is copied to the sin_addr member of the dest structure; I'd have thought that it would be copied to dest.sin_addr.s_addr instead. Or does the caddr_t cast enable the programmer to ignore the fact that sin_addr is itself a structure? Also, what exactly is caddr_t? Kernighan and Ritchie's book makes no mention of that data type.
The program also makes reference to a function called setlinebuf. I can't find it elsewhere in the program; is it a standard library routine?