/*
* "$Id: http-addr.c 148 2006-04-25 16:54:17Z njacobs $"
*
* HTTP address routines for the Common UNIX Printing System (CUPS).
*
* Copyright 1997-2005 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
* property of Easy Software Products and are protected by Federal
* copyright law. Distribution and use rights are outlined in the file
* "LICENSE.txt" which should have been included with this file. If this
* file is missing or damaged please contact Easy Software Products
* at:
*
* Attn: CUPS Licensing Information
* Easy Software Products
* 44141 Airport View Drive, Suite 204
* Hollywood, Maryland 20636 USA
*
* Voice: (301) 373-9600
* EMail: cups-info@cups.org
* WWW: http://www.cups.org
*
* Contents:
*
* httpAddrAny() - Check for the "any" address.
* httpAddrEqual() - Compare two addresses.
* httpAddrLoad() - Load a host entry address into an HTTP address.
* 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.
*/
/*
* Include necessary headers...
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "http.h"
#include "debug.h"
#include "string.h"
#include <ctype.h>
/*
* 'httpAddrAny()' - Check for the "any" address.
*/
int /* O - 1 if "any", 0 otherwise */
{
#ifdef AF_INET6
return (1);
#endif /* AF_INET6 */
return (1);
return (0);
}
/*
* 'httpAddrEqual()' - Compare two addresses.
*/
int /* O - 1 if equal, 0 if != */
{
return (0);
#ifdef AF_INET6
#endif /* AF_INET6 */
}
/*
* 'httpAddrLoad()' - Load a host entry address into an HTTP address.
*/
void
int port, /* I - Port number */
int n, /* I - Index into host entry */
{
#ifdef AF_INET6
{
# ifdef WIN32
# else
# endif /* WIN32 */
}
else
#endif /* AF_INET6 */
#ifdef AF_LOCAL
{
}
else
#endif /* AF_LOCAL */
{
# ifdef WIN32
# else
# endif /* WIN32 */
}
}
/*
* 'httpAddrLocalhost()' - Check for the local loopback address.
*/
int /* O - 1 if local host, 0 otherwise */
/* I - Address to check */
{
#ifdef AF_INET6
return (1);
#endif /* AF_INET6 */
#ifdef AF_LOCAL
return (1);
#endif /* AF_LOCAL */
return (1);
return (0);
}
#ifdef __sgi
#else
# define ADDR_CAST (char *)
#endif /* __sgi */
/*
* 'httpAddrLookup()' - Lookup the hostname associated with the address.
*/
char * /* O - Host name */
char *name, /* I - Host name buffer */
int namelen) /* I - Size of name buffer */
{
DEBUG_printf(("httpAddrLookup(addr=%p, name=%p, namelen=%d)\n",
#ifdef AF_INET6
else
#endif /* AF_INET6 */
#ifdef AF_LOCAL
{
return (name);
}
else
#endif /* AF_LOCAL */
else
{
return (NULL);
}
return (name);
}
/*
* 'httpAddrString()' - Convert an IP address to a dotted string.
*/
char * /* O - IP string */
char *s, /* I - String buffer */
int slen) /* I - Length of string */
{
DEBUG_printf(("httpAddrString(addr=%p, s=%p, slen=%d)\n",
#ifdef AF_INET6
else
#endif /* AF_INET6 */
#ifdef AF_LOCAL
else
#endif /* AF_LOCAL */
{
}
else
DEBUG_printf(("httpAddrString: returning \"%s\"...\n", s));
return (s);
}
/*
* 'httpGetHostByName()' - Lookup a hostname or IP address, and return
* address records for the specified name.
*/
struct hostent * /* O - Host entry */
{
#if defined(__APPLE__)
/* OS X hack to avoid it's ocassional long delay in lookupd */
#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.
*
* We also support domain sockets when supported by the underlying
* OS...
*/
#ifdef AF_LOCAL
if (name[0] == '/')
{
/*
* A domain socket address, so make an AF_LOCAL entry and return it...
*/
packed_ptr[0] = (char *)name;
DEBUG_puts("httpGetHostByName: returning domain socket address...");
return (&host_ip);
}
#endif /* AF_LOCAL */
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.
*/
return (NULL); /* Must have 4 numbers */
return (NULL); /* Invalid byte ranges! */
/*
* Fill in the host entry and return it...
*/
packed_ptr[0] = (char *)(&packed_ip);
DEBUG_puts("httpGetHostByName: returning IPv4 address...");
return (&host_ip);
}
else
{
/*
* Use the gethostbyname() function to get the IP address for
* the name...
*/
DEBUG_puts("httpGetHostByName: returning domain lookup address(es)...");
return (gethostbyname(name));
}
}
/*
* End of "$Id: http-addr.c 148 2006-04-25 16:54:17Z njacobs $".
*/