xref: /aosp_15_r20/external/libcups/cups/getifaddrs-internal.h (revision 5e7646d21f1134fb0638875d812ef646c12ab91e)
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 #    include <netinet/in.h>
29 #    define CUPS_SOCAST
30 #  endif /* _WIN32 */
31 
32 #  if defined(__APPLE__) && !defined(_SOCKLEN_T)
33 /*
34  * macOS 10.2.x does not define socklen_t, and in fact uses an int instead of
35  * unsigned type for length values...
36  */
37 
38 typedef int socklen_t;
39 #  endif /* __APPLE__ && !_SOCKLEN_T */
40 
41 #  ifndef _WIN32
42 #    include <net/if.h>
43 #    include <resolv.h>
44 #    ifdef HAVE_GETIFADDRS
45 #      include <ifaddrs.h>
46 #    else
47 #      include <sys/ioctl.h>
48 #      ifdef HAVE_SYS_SOCKIO_H
49 #        include <sys/sockio.h>
50 #      endif /* HAVE_SYS_SOCKIO_H */
51 #    endif /* HAVE_GETIFADDRS */
52 #  endif /* !_WIN32 */
53 
54 
55 /*
56  * C++ magic...
57  */
58 
59 #  ifdef __cplusplus
60 extern "C" {
61 #  endif /* __cplusplus */
62 
63 
64 /*
65  * Some OS's don't have getifaddrs() and freeifaddrs()...
66  */
67 
68 #  if !defined(_WIN32) && !defined(HAVE_GETIFADDRS)
69 #    ifdef ifa_dstaddr
70 #      undef ifa_dstaddr
71 #    endif /* ifa_dstaddr */
72 #    ifndef ifr_netmask
73 #      define ifr_netmask ifr_addr
74 #    endif /* !ifr_netmask */
75 
76 struct ifaddrs				/**** Interface Structure ****/
77 {
78   struct ifaddrs	*ifa_next;	/* Next interface in list */
79   char			*ifa_name;	/* Name of interface */
80   unsigned int		ifa_flags;	/* Flags (up, point-to-point, etc.) */
81   struct sockaddr	*ifa_addr,	/* Network address */
82 			*ifa_netmask;	/* Address mask */
83   union
84   {
85     struct sockaddr	*ifu_broadaddr;	/* Broadcast address of this interface. */
86     struct sockaddr	*ifu_dstaddr;	/* Point-to-point destination address. */
87   } ifa_ifu;
88 
89   void			*ifa_data;	/* Interface statistics */
90 };
91 
92 #    ifndef ifa_broadaddr
93 #      define ifa_broadaddr ifa_ifu.ifu_broadaddr
94 #    endif /* !ifa_broadaddr */
95 #    ifndef ifa_dstaddr
96 #      define ifa_dstaddr ifa_ifu.ifu_dstaddr
97 #    endif /* !ifa_dstaddr */
98 
99 extern int	_cups_getifaddrs(struct ifaddrs **addrs) _CUPS_PRIVATE;
100 #    define getifaddrs _cups_getifaddrs
101 extern void	_cups_freeifaddrs(struct ifaddrs *addrs) _CUPS_PRIVATE;
102 #    define freeifaddrs _cups_freeifaddrs
103 #  endif /* !_WIN32 && !HAVE_GETIFADDRS */
104 
105 
106 /*
107  * C++ magic...
108  */
109 
110 #  ifdef __cplusplus
111 }
112 #  endif /* __cplusplus */
113 
114 #endif /* !_CUPS_GETIFADDRS_INTERNAL_H_ */
115