1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * The contents of this file are subject to the Mozilla Public License
9 * Version 1.0 (the "License"); you may not use this file except in
10 * compliance with the License. You may obtain a copy of the License at
11 * http://www.mozilla.org/MPL/
13 * Software distributed under the License is distributed on an "AS IS"
14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15 * License for the specific language governing rights and limitations
18 * The Original Code is Curl.
20 * The Initial Developer of the Original Code is Daniel Stenberg.
22 * Portions created by the Initial Developer are Copyright (C) 1998.
23 * All Rights Reserved.
25 * ------------------------------------------------------------
27 * - Daniel Stenberg <Daniel.Stenberg@haxx.nu>
31 * $Source: /cvsroot/curl/curl/lib/hostip.c,v $
32 * $Revision: 1.1.1.1 $
33 * $Date: 1999-12-29 14:21:31 $
38 * ------------------------------------------------------------
39 ****************************************************************************/
45 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
48 #ifdef HAVE_SYS_TYPES_H
49 #include <sys/types.h>
51 #ifdef HAVE_SYS_SOCKET_H
52 #include <sys/socket.h>
54 #include <netinet/in.h>
56 #ifdef HAVE_ARPA_INET_H
57 #include <arpa/inet.h>
64 /* --- resolve name or IP-number --- */
66 char *MakeIP(unsigned long num
)
71 in
.s_addr
= htonl(num
);
72 return (inet_ntoa(in
));
74 static char addr
[128];
77 num
= htonl(num
); /* htonl() added to avoid endian probs */
78 paddr
= (unsigned char *)&num
;
79 sprintf(addr
, "%u.%u.%u.%u", paddr
[0], paddr
[1], paddr
[2], paddr
[3]);
84 /* Stolen from Dancer source code, written by
85 Bjorn Reese <breese@imada.ou.dk> */
87 #define INADDR_NONE (unsigned long) ~0
89 struct hostent
*GetHost(struct UrlData
*data
, char *hostname
)
91 struct hostent
*h
= NULL
;
93 static struct hostent he
;
94 static char name
[MAXHOSTNAMELEN
];
95 static char *addrlist
[2];
96 static struct in_addr addrentry
;
98 if ( (in
=inet_addr(hostname
)) != INADDR_NONE
) {
99 addrentry
.s_addr
= in
;
100 addrlist
[0] = (char *)&addrentry
;
102 he
.h_name
= strncpy(name
, MakeIP(ntohl(in
)), MAXHOSTNAMELEN
);
103 he
.h_addrtype
= AF_INET
;
104 he
.h_length
= sizeof(struct in_addr
);
105 he
.h_addr_list
= addrlist
;
107 } else if ( (h
=gethostbyname(hostname
)) == NULL
) {
108 infof(data
, "gethostbyname(2) failed for %s\n", hostname
);