HP Rp5405 BSD Sockets Interface Programmer's Guide - Page 89
Getting the Remote Host's Network Address
View all HP Rp5405 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 89 highlights
Using Internet Datagram Sockets Preparing Address Variables Field short sin_family u_short sin_port struct in_addr sin_addr Description Specifies the address family and should always be set to AF_INET. Specifies the port address. Assign this field when you bind the port address for the socket or when you get a port address for a specific service. Specifies the internet address. Assign this field when you get the internet address for the remote host. The server process must bind the port address of the service to its own socket and establish an address structure to store the clients' addresses when they are received with recvfrom. The client process does not have to bind a port address for its local socket; the host binds one automatically if one is not already bound. Refer to the inet(7F) man page for more information on sockaddr_in. Getting the Remote Host's Network Address The client process can use gethostbyname to obtain the internet address of the host and the length of that address (as the size of struct inaddr) from /etc/hosts, NIS, or BIND. gethostbyname and its parameters are described in the following table. Include files: System call: #include struct hostent *gethostbyname(name) char *name; Parameter Description of Contents name pointer to a valid node name (null-terminated string) INPUT Value host name Function result: pointer to struct hostent containing internet address, NULL pointer (0) if failure occurs. Example: Chapter 4 89