name.sin_family = AF_INET;
name.sin_port = htons (3000);
phostent = gethostbyname ("server1.Metrologic.com.tw");
if (!phostent) {
}
memcpy (&name.sin_addr, phostent->h_addr_list[0], 4);
if (connect (s, (struct sockaddr*) &name, sizeof (name)) < 0) {
}
Description
This routine searches for information by the given host name specified by the
character-string parameter hnp. It then returns a pointer to a struct hostent
structure describing an internet host referenced by name.
This routine gets the IP address of the specified host from DNS server.
Return
If successful, it returns a pointer.
On error, it returns a NULL pointer.
See Also
DNS_resolver, gethostbyaddr
getpeername
Purpose
To get name of a connected peer.
Syntax
int getpeername (SOCKET s, struct sockaddr *name, int *namelen);
s
name
namelen
SOCKET s;
Example
struct sockaddr_in remote_name;
int size_of_name;
........................
size_of_name = sizeof (remote_name);
Chapter 3 Terminal Specific Function Library
printf ("Can not get IP from DNS server");
.......................
printf ("Error in Establishing connection");
.......................
The IP address of DNS server must be specified when calling
SetNetConfig.
Or, it can be automatically retrieved from DHCP server, if DhcpEnable is
set.
Descriptor identifying a socket
Pointer to a sockaddr structure receiving the remote IP address
and port number
Pointer to an integer containing the length of name
149