1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
24 Change History (most recent first):
27 Revision 1.18 2005/04/08 21:37:57 ksekar
28 <rdar://problem/3792767> get_ifi_info doesn't return IPv6 interfaces on Linux
30 Revision 1.17 2004/12/17 19:32:43 cheshire
33 Revision 1.16 2004/12/01 04:25:05 cheshire
34 <rdar://problem/3872803> Darwin patches for Solaris and Suse
35 Provide daemon() for platforms that don't have it
37 Revision 1.15 2004/11/30 22:37:01 cheshire
38 Update copyright dates and add "Mode: C; tab-width: 4" headers
40 Revision 1.14 2004/10/16 00:17:01 cheshire
41 <rdar://problem/3770558> Replace IP TTL 255 check with local subnet source address check
43 Revision 1.13 2004/03/20 05:37:09 cheshire
44 Fix contributed by Terry Lambert & Alfred Perlstein:
45 Don't use uint8_t -- it requires stdint.h, which doesn't exist on FreeBSD 4.x
47 Revision 1.12 2004/01/28 21:12:15 cheshire
48 Reconcile mDNSIPv6Support & HAVE_IPV6 into a single flag (HAVE_IPV6)
50 Revision 1.11 2003/12/13 05:43:09 bradley
51 Fixed non-sa_len and non-IPv6 version of GET_SA_LEN macro to cast as sockaddr to access
52 sa_family so it works with any sockaddr-compatible address structure (e.g. sockaddr_storage).
54 Revision 1.10 2003/12/11 03:03:51 rpantos
55 Clean up mDNSPosix so that it builds on OS X again.
57 Revision 1.9 2003/12/08 20:47:02 rpantos
58 Add support for mDNSResponder on Linux.
60 Revision 1.8 2003/08/12 19:56:26 cheshire
63 Revision 1.7 2003/08/06 18:20:51 cheshire
66 Revision 1.6 2003/07/02 21:19:59 cheshire
67 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
69 Revision 1.5 2003/03/13 03:46:21 cheshire
70 Fixes to make the code build on Linux
72 Revision 1.4 2002/12/23 22:13:32 jgraessl
74 Reviewed by: Stuart Cheshire
75 Initial IPv6 support for mDNSResponder.
77 Revision 1.3 2002/09/21 20:44:53 zarzycki
80 Revision 1.2 2002/09/19 04:20:44 cheshire
81 Remove high-ascii characters that confuse some systems
83 Revision 1.1 2002/09/17 06:24:35 cheshire
91 #include <sys/types.h>
92 #include <sys/socket.h>
94 #include <netinet/in.h>
97 #include <linux/socket.h>
104 #ifdef NOT_HAVE_SOCKLEN_T
105 typedef unsigned int socklen_t
;
108 #if !defined(_SS_MAXSIZE)
110 #define sockaddr_storage sockaddr_in6
112 #define sockaddr_storage sockaddr
114 #endif // !defined(_SS_MAXSIZE)
116 #ifndef NOT_HAVE_SA_LEN
117 #define GET_SA_LEN(X) (sizeof(struct sockaddr) > ((struct sockaddr*)&(X))->sa_len ? \
118 sizeof(struct sockaddr) : ((struct sockaddr*)&(X))->sa_len )
120 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : \
121 ((struct sockaddr*)&(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
123 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr))
126 #define IFI_NAME 16 /* same as IFNAMSIZ in <net/if.h> */
127 #define IFI_HADDR 8 /* allow for 64-bit EUI-64 in future */
129 // Renamed from my_in_pktinfo because in_pktinfo is used by Linux.
131 struct my_in_pktinfo
{
132 struct sockaddr_storage ipi_addr
;
133 int ipi_ifindex
; /* received interface index */
134 char ipi_ifname
[IFI_NAME
]; /* received interface name */
137 /* From the text (Stevens, section 20.2): */
138 /* 'As an example of recvmsg we will write a function named recvfrom_flags that */
139 /* is similar to recvfrom but also returns: */
140 /* 1. the returned msg_flags value, */
141 /* 2. the destination addres of the received datagram (from the IP_RECVDSTADDR socket option, and */
142 /* 3. the index of the interface on which the datagram was received (the IP_RECVIF socket option).' */
143 extern ssize_t
recvfrom_flags(int fd
, void *ptr
, size_t nbytes
, int *flagsp
,
144 struct sockaddr
*sa
, socklen_t
*salenptr
, struct my_in_pktinfo
*pktp
, u_char
*ttl
);
147 char ifi_name
[IFI_NAME
]; /* interface name, null terminated */
148 u_char ifi_haddr
[IFI_HADDR
]; /* hardware address */
149 u_short ifi_hlen
; /* #bytes in hardware address: 0, 6, 8 */
150 short ifi_flags
; /* IFF_xxx constants from <net/if.h> */
151 short ifi_myflags
; /* our own IFI_xxx flags */
152 int ifi_index
; /* interface index */
153 struct sockaddr
*ifi_addr
; /* primary address */
154 struct sockaddr
*ifi_netmask
;
155 struct sockaddr
*ifi_brdaddr
;/* broadcast address */
156 struct sockaddr
*ifi_dstaddr
;/* destination address */
157 struct ifi_info
*ifi_next
; /* next of these structures */
160 #if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
161 #define PROC_IFINET6_PATH "/proc/net/if_inet6"
162 extern struct ifi_info
*get_ifi_info_linuxv6(int family
, int doaliases
);
165 #if defined(AF_INET6) && HAVE_IPV6
166 #define INET6_ADDRSTRLEN 46 /*Maximum length of IPv6 address */
171 #define IFI_ALIAS 1 /* ifi_addr is an alias */
173 /* From the text (Stevens, section 16.6): */
174 /* 'Since many programs need to know all the interfaces on a system, we will develop a */
175 /* function of our own named get_ifi_info that returns a linked list of structures, one */
176 /* for each interface that is currently "up."' */
177 extern struct ifi_info
*get_ifi_info(int family
, int doaliases
);
179 /* 'The free_ifi_info function, which takes a pointer that was */
180 /* returned by get_ifi_info and frees all the dynamic memory.' */
181 extern void free_ifi_info(struct ifi_info
*);
183 #ifdef NOT_HAVE_DAEMON
184 extern int daemon(int nochdir
, int noclose
);