/*
- * "$Id: http-addr.c,v 1.1.2.8 2003/01/07 18:26:24 mike Exp $"
+ * "$Id: http-addr.c,v 1.1.2.9 2003/01/14 14:34:14 mike Exp $"
*
* HTTP address routines for the Common UNIX Printing System (CUPS).
*
* httpAddrLocalhost() - Check for the local loopback address.
* httpAddrLookup() - Lookup the hostname associated with the address.
* httpAddrString() - Convert an IP address to a dotted string.
+ * httpGetHostByName() - Lookup a hostname or IP address, and return
+ * address records for the specified name.
*/
/*
/*
- * End of "$Id: http-addr.c,v 1.1.2.8 2003/01/07 18:26:24 mike Exp $".
+ * 'httpGetHostByName()' - Lookup a hostname or IP address, and return
+ * address records for the specified name.
+ */
+
+struct hostent * /* O - Host entry */
+httpGetHostByName(const char *name) /* I - Hostname or IP address */
+{
+ const char *nameptr; /* Pointer into name */
+ unsigned ip[4]; /* IP address components */
+ static unsigned packed_ip; /* Packed IPv4 address */
+ static char *packed_ptr[2]; /* Pointer to packed address */
+ static struct hostent host_ip; /* Host entry for IP address */
+
+#if defined(__APPLE__)
+ /* OS X hack to avoid it's ocassional long delay in lookupd */
+ static char sLoopback[] = "127.0.0.1";
+ if (strcmp(name, "localhost") == 0)
+ name = sLoopback;
+#endif /* __APPLE__ */
+
+ /*
+ * This function is needed because some operating systems have a
+ * buggy implementation of gethostbyname() that does not support
+ * IP addresses. If the first character of the name string is a
+ * number, then sscanf() is used to extract the IP components.
+ * We then pack the components into an IPv4 address manually,
+ * since the inet_aton() function is deprecated. We use the
+ * htonl() macro to get the right byte order for the address.
+ */
+
+ for (nameptr = name; isdigit(*nameptr) || *nameptr == '.'; nameptr ++);
+
+ if (!*nameptr)
+ {
+ /*
+ * We have an IP address; break it up and provide the host entry
+ * to the caller. Currently only supports IPv4 addresses, although
+ * it should be trivial to support IPv6 in CUPS 1.2.
+ */
+
+ if (sscanf(name, "%u.%u.%u.%u", ip, ip + 1, ip + 2, ip + 3) != 4)
+ return (NULL); /* Must have 4 numbers */
+
+ packed_ip = htonl(((((((ip[0] << 8) | ip[1]) << 8) | ip[2]) << 8) | ip[3]));
+
+ /*
+ * Fill in the host entry and return it...
+ */
+
+ host_ip.h_name = (char *)name;
+ host_ip.h_aliases = NULL;
+ host_ip.h_addrtype = AF_INET;
+ host_ip.h_length = 4;
+ host_ip.h_addr_list = packed_ptr;
+ packed_ptr[0] = (char *)(&packed_ip);
+ packed_ptr[1] = NULL;
+
+ return (&host_ip);
+ }
+ else
+ {
+ /*
+ * Use the gethostbyname() function to get the IP address for
+ * the name...
+ */
+
+ return (gethostbyname(name));
+ }
+}
+
+
+/*
+ * End of "$Id: http-addr.c,v 1.1.2.9 2003/01/14 14:34:14 mike Exp $".
*/
/*
- * "$Id: http.c,v 1.82.2.21 2003/01/07 18:26:24 mike Exp $"
+ * "$Id: http.c,v 1.82.2.22 2003/01/14 14:34:15 mike Exp $"
*
* HTTP routines for the Common UNIX Printing System (CUPS).
*
* httpConnectEncrypt() - Connect to a HTTP server using encryption.
* httpEncryption() - Set the required encryption on the link.
* httpReconnect() - Reconnect to a HTTP server...
- * httpGetHostByName() - Lookup a hostname or IP address, and return
- * address records for the specified name.
* httpSetField() - Set the value of an HTTP header.
* httpDelete() - Send a DELETE request to the server.
* httpGet() - Send a GET request to the server.
}
-/*
- * 'httpGetHostByName()' - Lookup a hostname or IP address, and return
- * address records for the specified name.
- */
-
-struct hostent * /* O - Host entry */
-httpGetHostByName(const char *name) /* I - Hostname or IP address */
-{
- const char *nameptr; /* Pointer into name */
- unsigned ip[4]; /* IP address components */
- static unsigned packed_ip; /* Packed IPv4 address */
- static char *packed_ptr[2]; /* Pointer to packed address */
- static struct hostent host_ip; /* Host entry for IP address */
-
-#if defined(__APPLE__)
- /* OS X hack to avoid it's ocassional long delay in lookupd */
- static char sLoopback[] = "127.0.0.1";
- if (strcmp(name, "localhost") == 0)
- name = sLoopback;
-#endif /* __APPLE__ */
-
- /*
- * This function is needed because some operating systems have a
- * buggy implementation of httpGetHostByName() that does not support
- * IP addresses. If the first character of the name string is a
- * number, then sscanf() is used to extract the IP components.
- * We then pack the components into an IPv4 address manually,
- * since the inet_aton() function is deprecated. We use the
- * htonl() macro to get the right byte order for the address.
- */
-
- for (nameptr = name; isdigit(*nameptr) || *nameptr == '.'; nameptr ++);
-
- if (!*nameptr)
- {
- /*
- * We have an IP address; break it up and provide the host entry
- * to the caller. Currently only supports IPv4 addresses, although
- * it should be trivial to support IPv6 in CUPS 1.2.
- */
-
- if (sscanf(name, "%u.%u.%u.%u", ip, ip + 1, ip + 2, ip + 3) != 4)
- return (NULL); /* Must have 4 numbers */
-
- packed_ip = htonl(((((((ip[0] << 8) | ip[1]) << 8) | ip[2]) << 8) | ip[3]));
-
- /*
- * Fill in the host entry and return it...
- */
-
- host_ip.h_name = (char *)name;
- host_ip.h_aliases = NULL;
- host_ip.h_addrtype = AF_INET;
- host_ip.h_length = 4;
- host_ip.h_addr_list = packed_ptr;
- packed_ptr[0] = (char *)(&packed_ip);
- packed_ptr[1] = NULL;
-
- return (&host_ip);
- }
- else
- {
- /*
- * Use the gethostbyname() function to get the IP address for
- * the name...
- */
-
- return (gethostbyname(name));
- }
-}
-
-
/*
* 'httpGetSubField()' - Get a sub-field value.
*/
/*
- * End of "$Id: http.c,v 1.82.2.21 2003/01/07 18:26:24 mike Exp $".
+ * End of "$Id: http.c,v 1.82.2.22 2003/01/14 14:34:15 mike Exp $".
*/