1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 Change History (most recent first):
20 Revision 1.19 2006/08/14 23:24:47 cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
23 Revision 1.18 2005/04/08 21:37:57 ksekar
24 <rdar://problem/3792767> get_ifi_info doesn't return IPv6 interfaces on Linux
26 Revision 1.17 2004/12/17 19:32:43 cheshire
29 Revision 1.16 2004/12/01 04:25:05 cheshire
30 <rdar://problem/3872803> Darwin patches for Solaris and Suse
31 Provide daemon() for platforms that don't have it
33 Revision 1.15 2004/11/30 22:37:01 cheshire
34 Update copyright dates and add "Mode: C; tab-width: 4" headers
36 Revision 1.14 2004/10/16 00:17:01 cheshire
37 <rdar://problem/3770558> Replace IP TTL 255 check with local subnet source address check
39 Revision 1.13 2004/03/20 05:37:09 cheshire
40 Fix contributed by Terry Lambert & Alfred Perlstein:
41 Don't use uint8_t -- it requires stdint.h, which doesn't exist on FreeBSD 4.x
43 Revision 1.12 2004/01/28 21:12:15 cheshire
44 Reconcile mDNSIPv6Support & HAVE_IPV6 into a single flag (HAVE_IPV6)
46 Revision 1.11 2003/12/13 05:43:09 bradley
47 Fixed non-sa_len and non-IPv6 version of GET_SA_LEN macro to cast as sockaddr to access
48 sa_family so it works with any sockaddr-compatible address structure (e.g. sockaddr_storage).
50 Revision 1.10 2003/12/11 03:03:51 rpantos
51 Clean up mDNSPosix so that it builds on OS X again.
53 Revision 1.9 2003/12/08 20:47:02 rpantos
54 Add support for mDNSResponder on Linux.
56 Revision 1.8 2003/08/12 19:56:26 cheshire
59 Revision 1.7 2003/08/06 18:20:51 cheshire
62 Revision 1.6 2003/07/02 21:19:59 cheshire
63 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
65 Revision 1.5 2003/03/13 03:46:21 cheshire
66 Fixes to make the code build on Linux
68 Revision 1.4 2002/12/23 22:13:32 jgraessl
70 Reviewed by: Stuart Cheshire
71 Initial IPv6 support for mDNSResponder.
73 Revision 1.3 2002/09/21 20:44:53 zarzycki
76 Revision 1.2 2002/09/19 04:20:44 cheshire
77 Remove high-ascii characters that confuse some systems
79 Revision 1.1 2002/09/17 06:24:35 cheshire
87 #include <sys/types.h>
88 #include <sys/socket.h>
90 #include <netinet/in.h>
93 #include <linux/socket.h>
100 #ifdef NOT_HAVE_SOCKLEN_T
101 typedef unsigned int socklen_t
;
104 #if !defined(_SS_MAXSIZE)
106 #define sockaddr_storage sockaddr_in6
108 #define sockaddr_storage sockaddr
110 #endif // !defined(_SS_MAXSIZE)
112 #ifndef NOT_HAVE_SA_LEN
113 #define GET_SA_LEN(X) (sizeof(struct sockaddr) > ((struct sockaddr*)&(X))->sa_len ? \
114 sizeof(struct sockaddr) : ((struct sockaddr*)&(X))->sa_len )
116 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : \
117 ((struct sockaddr*)&(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
119 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr))
122 #define IFI_NAME 16 /* same as IFNAMSIZ in <net/if.h> */
123 #define IFI_HADDR 8 /* allow for 64-bit EUI-64 in future */
125 // Renamed from my_in_pktinfo because in_pktinfo is used by Linux.
127 struct my_in_pktinfo
{
128 struct sockaddr_storage ipi_addr
;
129 int ipi_ifindex
; /* received interface index */
130 char ipi_ifname
[IFI_NAME
]; /* received interface name */
133 /* From the text (Stevens, section 20.2): */
134 /* 'As an example of recvmsg we will write a function named recvfrom_flags that */
135 /* is similar to recvfrom but also returns: */
136 /* 1. the returned msg_flags value, */
137 /* 2. the destination addres of the received datagram (from the IP_RECVDSTADDR socket option, and */
138 /* 3. the index of the interface on which the datagram was received (the IP_RECVIF socket option).' */
139 extern ssize_t
recvfrom_flags(int fd
, void *ptr
, size_t nbytes
, int *flagsp
,
140 struct sockaddr
*sa
, socklen_t
*salenptr
, struct my_in_pktinfo
*pktp
, u_char
*ttl
);
143 char ifi_name
[IFI_NAME
]; /* interface name, null terminated */
144 u_char ifi_haddr
[IFI_HADDR
]; /* hardware address */
145 u_short ifi_hlen
; /* #bytes in hardware address: 0, 6, 8 */
146 short ifi_flags
; /* IFF_xxx constants from <net/if.h> */
147 short ifi_myflags
; /* our own IFI_xxx flags */
148 int ifi_index
; /* interface index */
149 struct sockaddr
*ifi_addr
; /* primary address */
150 struct sockaddr
*ifi_netmask
;
151 struct sockaddr
*ifi_brdaddr
;/* broadcast address */
152 struct sockaddr
*ifi_dstaddr
;/* destination address */
153 struct ifi_info
*ifi_next
; /* next of these structures */
156 #if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
157 #define PROC_IFINET6_PATH "/proc/net/if_inet6"
158 extern struct ifi_info
*get_ifi_info_linuxv6(int family
, int doaliases
);
161 #if defined(AF_INET6) && HAVE_IPV6
162 #define INET6_ADDRSTRLEN 46 /*Maximum length of IPv6 address */
167 #define IFI_ALIAS 1 /* ifi_addr is an alias */
169 /* From the text (Stevens, section 16.6): */
170 /* 'Since many programs need to know all the interfaces on a system, we will develop a */
171 /* function of our own named get_ifi_info that returns a linked list of structures, one */
172 /* for each interface that is currently "up."' */
173 extern struct ifi_info
*get_ifi_info(int family
, int doaliases
);
175 /* 'The free_ifi_info function, which takes a pointer that was */
176 /* returned by get_ifi_info and frees all the dynamic memory.' */
177 extern void free_ifi_info(struct ifi_info
*);
179 #ifdef NOT_HAVE_DAEMON
180 extern int daemon(int nochdir
, int noclose
);