summaryrefslogtreecommitdiff
path: root/scheduler/network.c
diff options
context:
space:
mode:
authorjlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be>2006-04-24 18:03:36 +0000
committerjlovell <jlovell@a1ca3aef-8c08-0410-bb20-df032aa958be>2006-04-24 18:03:36 +0000
commit89d46774ee527faaaf27d1b696554f4508bf105b (patch)
tree27ae92ec2e5df36836fc505515ab45f9a06cebc1 /scheduler/network.c
parente53920b9224e07b7d5f3e5a3ffea1f64ded479d2 (diff)
downloadcups-89d46774ee527faaaf27d1b696554f4508bf105b.tar.gz
Load cups into easysw/current.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@136 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'scheduler/network.c')
-rw-r--r--scheduler/network.c282
1 files changed, 3 insertions, 279 deletions
diff --git a/scheduler/network.c b/scheduler/network.c
index 46f3f2655..eb89b1217 100644
--- a/scheduler/network.c
+++ b/scheduler/network.c
@@ -1,5 +1,5 @@
/*
- * "$Id: network.c 5069 2006-02-04 05:24:35Z mike $"
+ * "$Id: network.c 5428 2006-04-18 20:45:30Z mike $"
*
* Network interface functions for the Common UNIX Printing System
* (CUPS) scheduler.
@@ -28,18 +28,15 @@
* cupsdNetIFFree() - Free the current network interface list.
* cupsdNetIFUpdate() - Update the network interface list as needed...
* compare_netif() - Compare two network interfaces.
- * getifaddrs() - Get a list of network interfaces on the system.
- * freeifaddrs() - Free an interface list...
*/
/*
* Include necessary headers.
*/
+#include <cups/http-private.h>
#include "cupsd.h"
-#include <net/if.h>
-
/*
* Local functions...
@@ -49,44 +46,6 @@ static void cupsdNetIFFree(void);
static int compare_netif(cupsd_netif_t *a, cupsd_netif_t *b);
-#ifdef HAVE_GETIFADDRS
-/*
- * Use native getifaddrs() function...
- */
-# include <ifaddrs.h>
-#else
-/*
- * Use getifaddrs() emulation...
- */
-
-# include <sys/ioctl.h>
-# ifdef HAVE_SYS_SOCKIO_H
-# include <sys/sockio.h>
-# endif
-
-# ifdef ifa_dstaddr
-# undef ifa_dstaddr
-# endif /* ifa_dstaddr */
-# ifndef ifr_netmask
-# define ifr_netmask ifr_addr
-# endif /* !ifr_netmask */
-
-struct ifaddrs /**** Interface Structure ****/
-{
- struct ifaddrs *ifa_next; /* Next interface in list */
- char *ifa_name; /* Name of interface */
- unsigned int ifa_flags; /* Flags (up, point-to-point, etc.) */
- struct sockaddr *ifa_addr, /* Network address */
- *ifa_netmask, /* Address mask */
- *ifa_dstaddr; /* Broadcast or destination address */
- void *ifa_data; /* Interface statistics */
-};
-
-static int getifaddrs(struct ifaddrs **addrs);
-static void freeifaddrs(struct ifaddrs *addrs);
-#endif /* HAVE_GETIFADDRS */
-
-
/*
* 'cupsdNetIFFind()' - Find a network interface.
*/
@@ -354,241 +313,6 @@ compare_netif(cupsd_netif_t *a, /* I - First network interface */
}
-#ifndef HAVE_GETIFADDRS
-/*
- * 'getifaddrs()' - Get a list of network interfaces on the system.
- */
-
-static int /* O - 0 on success, -1 on error */
-getifaddrs(struct ifaddrs **addrs) /* O - List of interfaces */
-{
- int sock; /* Socket */
- char buffer[65536], /* Buffer for address info */
- *bufptr, /* Pointer into buffer */
- *bufend; /* End of buffer */
- struct ifconf conf; /* Interface configurations */
- struct sockaddr addr; /* Address data */
- struct ifreq *ifp; /* Interface data */
- int ifpsize; /* Size of interface data */
- struct ifaddrs *temp; /* Pointer to current interface */
- struct ifreq request; /* Interface request */
-
-
- /*
- * Start with an empty list...
- */
-
- if (addrs == NULL)
- return (-1);
-
- *addrs = NULL;
-
- /*
- * Create a UDP socket to get the interface data...
- */
-
- memset (&addr, 0, sizeof(addr));
- if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
- return (-1);
-
- /*
- * Try to get the list of interfaces...
- */
-
- conf.ifc_len = sizeof(buffer);
- conf.ifc_buf = buffer;
-
- if (ioctl(sock, SIOCGIFCONF, &conf) < 0)
- {
- /*
- * Couldn't get the list of interfaces...
- */
-
- close(sock);
- return (-1);
- }
-
- /*
- * OK, got the list of interfaces, now lets step through the
- * buffer to pull them out...
- */
-
-# ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
-# define sockaddr_len(a) ((a)->sa_len)
-# else
-# define sockaddr_len(a) (sizeof(struct sockaddr))
-# endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */
-
- for (bufptr = buffer, bufend = buffer + conf.ifc_len;
- bufptr < bufend;
- bufptr += ifpsize)
- {
- /*
- * Get the current interface information...
- */
-
- ifp = (struct ifreq *)bufptr;
- ifpsize = sizeof(ifp->ifr_name) + sockaddr_len(&(ifp->ifr_addr));
-
- if (ifpsize < sizeof(struct ifreq))
- ifpsize = sizeof(struct ifreq);
-
- memset(&request, 0, sizeof(request));
- memcpy(request.ifr_name, ifp->ifr_name, sizeof(ifp->ifr_name));
-
- /*
- * Check the status of the interface...
- */
-
- if (ioctl(sock, SIOCGIFFLAGS, &request) < 0)
- continue;
-
- /*
- * Allocate memory for a single interface record...
- */
-
- if ((temp = calloc(1, sizeof(struct ifaddrs))) == NULL)
- {
- /*
- * Unable to allocate memory...
- */
-
- close(sock);
- return (-1);
- }
-
- /*
- * Add this record to the front of the list and copy the name, flags,
- * and network address...
- */
-
- temp->ifa_next = *addrs;
- *addrs = temp;
- temp->ifa_name = strdup(ifp->ifr_name);
- temp->ifa_flags = request.ifr_flags;
- if ((temp->ifa_addr = calloc(1, sockaddr_len(&(ifp->ifr_addr)))) != NULL)
- memcpy(temp->ifa_addr, &(ifp->ifr_addr), sockaddr_len(&(ifp->ifr_addr)));
-
- /*
- * Try to get the netmask for the interface...
- */
-
- if (!ioctl(sock, SIOCGIFNETMASK, &request))
- {
- /*
- * Got it, make a copy...
- */
-
- if ((temp->ifa_netmask = calloc(1, sizeof(request.ifr_netmask))) != NULL)
- memcpy(temp->ifa_netmask, &(request.ifr_netmask),
- sizeof(request.ifr_netmask));
- }
-
- /*
- * Then get the broadcast or point-to-point (destination) address,
- * if applicable...
- */
-
- if (temp->ifa_flags & IFF_BROADCAST)
- {
- /*
- * Have a broadcast address, so get it!
- */
-
- if (!ioctl(sock, SIOCGIFBRDADDR, &request))
- {
- /*
- * Got it, make a copy...
- */
-
- if ((temp->ifa_dstaddr = calloc(1, sizeof(request.ifr_broadaddr))) != NULL)
- memcpy(temp->ifa_dstaddr, &(request.ifr_broadaddr),
- sizeof(request.ifr_broadaddr));
- }
- }
- else if (temp->ifa_flags & IFF_POINTOPOINT)
- {
- /*
- * Point-to-point interface; grab the remote address...
- */
-
- if (!ioctl(sock, SIOCGIFDSTADDR, &request))
- {
- temp->ifa_dstaddr = malloc(sizeof(request.ifr_dstaddr));
- memcpy(temp->ifa_dstaddr, &(request.ifr_dstaddr),
- sizeof(request.ifr_dstaddr));
- }
- }
- }
-
- /*
- * OK, we're done with the socket, close it and return 0...
- */
-
- close(sock);
-
- return (0);
-}
-
-
-/*
- * 'freeifaddrs()' - Free an interface list...
- */
-
-static void
-freeifaddrs(struct ifaddrs *addrs) /* I - Interface list to free */
-{
- struct ifaddrs *next; /* Next interface in list */
-
-
- while (addrs != NULL)
- {
- /*
- * Make a copy of the next interface pointer...
- */
-
- next = addrs->ifa_next;
-
- /*
- * Free data values as needed...
- */
-
- if (addrs->ifa_name)
- {
- free(addrs->ifa_name);
- addrs->ifa_name = NULL;
- }
-
- if (addrs->ifa_addr)
- {
- free(addrs->ifa_addr);
- addrs->ifa_addr = NULL;
- }
-
- if (addrs->ifa_netmask)
- {
- free(addrs->ifa_netmask);
- addrs->ifa_netmask = NULL;
- }
-
- if (addrs->ifa_dstaddr)
- {
- free(addrs->ifa_dstaddr);
- addrs->ifa_dstaddr = NULL;
- }
-
- /*
- * Free this node and continue to the next...
- */
-
- free(addrs);
-
- addrs = next;
- }
-}
-#endif /* !HAVE_GETIFADDRS */
-
-
/*
- * End of "$Id: network.c 5069 2006-02-04 05:24:35Z mike $".
+ * End of "$Id: network.c 5428 2006-04-18 20:45:30Z mike $".
*/