]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix doco comment.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 14 Jan 2003 14:34:15 +0000 (14:34 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 14 Jan 2003 14:34:15 +0000 (14:34 +0000)
Move httpGetHostByName() to http-addr.c.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@3081 7a7537e8-13f0-0310-91df-b6672ffda945

cups/http-addr.c
cups/http.c

index 75cce509bb203d893a21ae464a1fcc57927e982b..f5d0705fce2d46c69e16118aec504e9ab7567719 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$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).
  *
@@ -28,6 +28,8 @@
  *   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.
  */
 
 /*
@@ -202,5 +204,77 @@ httpAddrString(const http_addr_t *addr,            /* I - Address to convert */
 
 
 /*
- * 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 $".
  */
index 01f2799f8d176cd0f19a1a0a87e41708ef2cc85d..243cb76601a7116516756b0c37a3c192e84608ff 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$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).
  *
@@ -34,8 +34,6 @@
  *   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.
@@ -613,78 +611,6 @@ httpReconnect(http_t *http)        /* I - HTTP data */
 }
 
 
-/*
- * '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.
  */
@@ -2116,5 +2042,5 @@ http_upgrade(http_t *http)        /* I - HTTP data */
 
 
 /*
- * 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 $".
  */