Date: Fri, 20 Sep 2002 16:42:33 +1000 From: Jacob Rhoden <jrhoden@unimelb.edu.au> To: Tony <tony@idk.com>, freebsd-questions@freebsd.org Subject: Re: gethostbyname Message-ID: <200209201642.33375.jrhoden@unimelb.edu.au> In-Reply-To: <200209200618.XAA05767@idk.com> References: <200209200618.XAA05767@idk.com>
index | next in thread | previous in thread | raw e-mail
On Fri, 20 Sep 2002 16:18, Tony wrote:
> Anyone have a simple example of how to use this function..
Hope this helps.
struct hostent *he;
struct sockaddr_in sin;
char *hostname="freebsd.org";
int port=80;
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = inet_addr(hstname);
if(sin.sin_addr.s_addr == INADDR_NONE) {
he = gethostbyname(hstname);
if(!he) {
close(s);
errno=0;
return -1;
}
memcpy(&sin.sin_addr, he->h_addr, he->h_length);
}
Jacob Rhoden Phone: +61 3 9844 6102
ITS Division Email: jrhoden@unimelb.edu.au
Melbourne University Mobile: +61 403 788 386
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209201642.33375.jrhoden>
