• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * getifaddrs definitions for CUPS.
3  *
4  * Copyright 2007-2018 by Apple Inc.
5  * Copyright 1997-2007 by Easy Software Products, all rights reserved.
6  *
7  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
8  * information.
9  */
10 
11 #ifndef _CUPS_GETIFADDRS_INTERNAL_H_
12 #  define _CUPS_GETIFADDRS_INTERNAL_H_
13 
14 /*
15  * Include necessary headers...
16  */
17 
18 #  include "config.h"
19 #  ifdef _WIN32
20 #    define _WINSOCK_DEPRECATED_NO_WARNINGS 1
21 #    include <io.h>
22 #    include <winsock2.h>
23 #    define CUPS_SOCAST (const char *)
24 #  else
25 #    include <unistd.h>
26 #    include <fcntl.h>
27 #    include <sys/socket.h>
28 #    define CUPS_SOCAST
29 #  endif /* _WIN32 */
30 
31 #  if defined(__APPLE__) && !defined(_SOCKLEN_T)
32 /*
33  * macOS 10.2.x does not define socklen_t, and in fact uses an int instead of
34  * unsigned type for length values...
35  */
36 
37 typedef int socklen_t;
38 #  endif /* __APPLE__ && !_SOCKLEN_T */
39 
40 #  ifndef _WIN32
41 #    include <net/if.h>
42 #    include <resolv.h>
43 #    ifdef HAVE_GETIFADDRS
44 #      include <ifaddrs.h>
45 #    else
46 #      include <sys/ioctl.h>
47 #      ifdef HAVE_SYS_SOCKIO_H
48 #        include <sys/sockio.h>
49 #      endif /* HAVE_SYS_SOCKIO_H */
50 #    endif /* HAVE_GETIFADDRS */
51 #  endif /* !_WIN32 */
52 
53 
54 /*
55  * C++ magic...
56  */
57 
58 #  ifdef __cplusplus
59 extern "C" {
60 #  endif /* __cplusplus */
61 
62 
63 /*
64  * Some OS's don't have getifaddrs() and freeifaddrs()...
65  */
66 
67 #  if !defined(_WIN32) && !defined(HAVE_GETIFADDRS)
68 #    ifdef ifa_dstaddr
69 #      undef ifa_dstaddr
70 #    endif /* ifa_dstaddr */
71 #    ifndef ifr_netmask
72 #      define ifr_netmask ifr_addr
73 #    endif /* !ifr_netmask */
74 
75 struct ifaddrs				/**** Interface Structure ****/
76 {
77   struct ifaddrs	*ifa_next;	/* Next interface in list */
78   char			*ifa_name;	/* Name of interface */
79   unsigned int		ifa_flags;	/* Flags (up, point-to-point, etc.) */
80   struct sockaddr	*ifa_addr,	/* Network address */
81 			*ifa_netmask;	/* Address mask */
82   union
83   {
84     struct sockaddr	*ifu_broadaddr;	/* Broadcast address of this interface. */
85     struct sockaddr	*ifu_dstaddr;	/* Point-to-point destination address. */
86   } ifa_ifu;
87 
88   void			*ifa_data;	/* Interface statistics */
89 };
90 
91 #    ifndef ifa_broadaddr
92 #      define ifa_broadaddr ifa_ifu.ifu_broadaddr
93 #    endif /* !ifa_broadaddr */
94 #    ifndef ifa_dstaddr
95 #      define ifa_dstaddr ifa_ifu.ifu_dstaddr
96 #    endif /* !ifa_dstaddr */
97 
98 extern int	_cups_getifaddrs(struct ifaddrs **addrs) _CUPS_PRIVATE;
99 #    define getifaddrs _cups_getifaddrs
100 extern void	_cups_freeifaddrs(struct ifaddrs *addrs) _CUPS_PRIVATE;
101 #    define freeifaddrs _cups_freeifaddrs
102 #  endif /* !_WIN32 && !HAVE_GETIFADDRS */
103 
104 
105 /*
106  * C++ magic...
107  */
108 
109 #  ifdef __cplusplus
110 }
111 #  endif /* __cplusplus */
112 
113 #endif /* !_CUPS_GETIFADDRS_INTERNAL_H_ */
114