Chapter 3 Terminal Specific Function Library
149
name.sin_family = AF_INET;
name.sin_port = htons (3000);
phostent = gethostbyname ("server1.Metrologic.com.tw");
if (!phostent) {
printf ("Can not get IP from DNS server");
.......................
}
memcpy (&name.sin_addr, phostent->h_addr_list[0], 4);
if (connect (s, (struct sockaddr*) &name, sizeof (name)) < 0) {
printf ("Error in Establishing connection");
.......................
}
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.
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.
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
Descriptor identifying a socket
name
Pointer to a sockaddr structure receiving the remote IP address
and port number
namelen
Pointer to an integer containing the length of
name
Example
SOCKET s;
struct sockaddr_in remote_name;
int size_of_name;
........................
size_of_name = sizeof (remote_name);
Summary of Contents for Optimus R
Page 1: ...Printed on 20 March 2006 C Programming Guide Version 3 04 02 Optimus S Optimus R...
Page 6: ......
Page 8: ...2 C Programming Guide For Optimus S R...
Page 12: ...6 C Programming Guide For Optimus S R The flow is illustrated as shown below...
Page 23: ...Chapter 2 Development Environment 17 Different types signed unsigned Different types same size...
Page 24: ...18 C Programming Guide For Optimus S R...
Page 220: ...214 C Programming Guide For Optimus S R See Also FlashSize free_memory...