Returns the IP address.
gethostbyname Syntax: string gethostbyname (string hostname);
gethostbyname return Value: String
Function Type: Network system
gethostbyname Content Description
This function returns the IP address of a machine name (Domain
gethostbyname () returns a pointer to the hostent structure that contains the host name and address information for the given host name. The declaration of the structure is consistent with the GETHOSTADDR (). Returns the host information
The following are two functions used in VC socket initialization:
1. wsastartup FunctionInt wsastartup(Word wversionrequested,Lpwsadata);Use SOCKET Program Before using socket, you must call the wsastartup function. The first parameter of this
The IP address is essentially a 32-bit unsigned integer that is stored in the following structure1 struct 23 int4 };For historical reasons, although the IP address is just a scalar, it is stored with a struct.Because the host can have different
1. In the simplest client/server program, a client is a process and only one connection is initiated, you only need to modify it to allow a client to initiate multiple connections and then use only one connection to send data.
First, let's get to
From: http://blog.163.com/lyzaily@126/blog/static/4243883720091025102830596/
Gethostbyname () can be used to convert the domain name of a server into the IP address of the server. Note that the domain name of a server can correspond to multiple
Address: http://blog.csdn.net/leesphone/archive/2008/03/02/2138775.aspx
Header file:# Include # Include Struct hostent * gethostbyname (const char * Name );The input value of this function is the domain name or host name, for example,
# Include # Include // hostent, gethostbyname gethostbyaddr# Include // memcpy# Include # Include // inet_ntop# Include # Include # Include Int main (void){Unsigned long d;Struct in_addr ADDR;Char * IP = "192.168.1.11 ";D = inet_addr (IP );Memcpy
The compilation environment for this code is MAC and the system version is 10.11.6:#include string.h>#include#include#includeintMainintargcChar*argv[]) { CharHost[] ="www.baidu.com"; structHostent *ht =NULL; HT=gethostbyname (host); if(HT)
Function Description:
1. wsastartup FunctionInt wsastartup(Word wversionrequested,Lpwsadata);The program using the socket must call the wsastartup function before using the socket. The first parameter of this function indicates the socket version
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.