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.16 2004/12/01 04:25:05 cheshire
28 <rdar://problem/3872803> Darwin patches for Solaris and Suse
29 Provide daemon() for platforms that don't have it
31 Revision 1.15 2004/11/30 22:37:01 cheshire
32 Update copyright dates and add "Mode: C; tab-width: 4" headers
34 Revision 1.14 2004/10/16 00:17:01 cheshire
35 <rdar://problem/3770558> Replace IP TTL 255 check with local subnet source address check
37 Revision 1.13 2004/03/20 05:37:09 cheshire
38 Fix contributed by Terry Lambert & Alfred Perlstein:
39 Don't use uint8_t -- it requires stdint.h, which doesn't exist on FreeBSD 4.x
41 Revision 1.12 2004/01/28 21:12:15 cheshire
42 Reconcile mDNSIPv6Support & HAVE_IPV6 into a single flag (HAVE_IPV6)
44 Revision 1.11 2003/12/13 05:43:09 bradley
45 Fixed non-sa_len and non-IPv6 version of GET_SA_LEN macro to cast as sockaddr to access
46 sa_family so it works with any sockaddr-compatible address structure (e.g. sockaddr_storage).
48 Revision 1.10 2003/12/11 03:03:51 rpantos
49 Clean up mDNSPosix so that it builds on OS X again.
51 Revision 1.9 2003/12/08 20:47:02 rpantos
52 Add support for mDNSResponder on Linux.
54 Revision 1.8 2003/08/12 19:56:26 cheshire
57 Revision 1.7 2003/08/06 18:20:51 cheshire
60 Revision 1.6 2003/07/02 21:19:59 cheshire
61 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
63 Revision 1.5 2003/03/13 03:46:21 cheshire
64 Fixes to make the code build on Linux
66 Revision 1.4 2002/12/23 22:13:32 jgraessl
68 Reviewed by: Stuart Cheshire
69 Initial IPv6 support for mDNSResponder.
71 Revision 1.3 2002/09/21 20:44:53 zarzycki
74 Revision 1.2 2002/09/19 04:20:44 cheshire
75 Remove high-ascii characters that confuse some systems
77 Revision 1.1 2002/09/17 06:24:35 cheshire
85 #include <sys/types.h>
86 #include <sys/socket.h>
88 #include <netinet/in.h>
94 #ifdef NOT_HAVE_SOCKLEN_T
95 typedef unsigned int socklen_t
;
98 #if !defined(_SS_MAXSIZE)
99 #define sockaddr_storage sockaddr
102 #ifndef NOT_HAVE_SA_LEN
103 #define GET_SA_LEN(X) (sizeof(struct sockaddr) > ((struct sockaddr*)&(X))->sa_len ? \
104 sizeof(struct sockaddr) : ((struct sockaddr*)&(X))->sa_len )
106 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : \
107 ((struct sockaddr*)&(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
109 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr))
112 #define IFI_NAME 16 /* same as IFNAMSIZ in <net/if.h> */
113 #define IFI_HADDR 8 /* allow for 64-bit EUI-64 in future */
115 // Renamed from my_in_pktinfo because in_pktinfo is used by Linux.
117 struct my_in_pktinfo
{
118 struct sockaddr_storage ipi_addr
;
119 int ipi_ifindex
; /* received interface index */
120 char ipi_ifname
[IFI_NAME
]; /* received interface name */
123 /* From the text (Stevens, section 20.2): */
124 /* 'As an example of recvmsg we will write a function named recvfrom_flags that */
125 /* is similar to recvfrom but also returns: */
126 /* 1. the returned msg_flags value, */
127 /* 2. the destination addres of the received datagram (from the IP_RECVDSTADDR socket option, and */
128 /* 3. the index of the interface on which the datagram was received (the IP_RECVIF socket option).' */
129 extern ssize_t
recvfrom_flags(int fd
, void *ptr
, size_t nbytes
, int *flagsp
,
130 struct sockaddr
*sa
, socklen_t
*salenptr
, struct my_in_pktinfo
*pktp
, u_char
*ttl
);
133 char ifi_name
[IFI_NAME
]; /* interface name, null terminated */
134 u_char ifi_haddr
[IFI_HADDR
]; /* hardware address */
135 u_short ifi_hlen
; /* #bytes in hardware address: 0, 6, 8 */
136 short ifi_flags
; /* IFF_xxx constants from <net/if.h> */
137 short ifi_myflags
; /* our own IFI_xxx flags */
138 int ifi_index
; /* interface index */
139 struct sockaddr
*ifi_addr
; /* primary address */
140 struct sockaddr
*ifi_netmask
;
141 struct sockaddr
*ifi_brdaddr
;/* broadcast address */
142 struct sockaddr
*ifi_dstaddr
;/* destination address */
143 struct ifi_info
*ifi_next
; /* next of these structures */
146 #define IFI_ALIAS 1 /* ifi_addr is an alias */
148 /* From the text (Stevens, section 16.6): */
149 /* 'Since many programs need to know all the interfaces on a system, we will develop a */
150 /* function of our own named get_ifi_info that returns a linked list of structures, one */
151 /* for each interface that is currently "up."' */
152 extern struct ifi_info
*get_ifi_info(int family
, int doaliases
);
154 /* 'The free_ifi_info function, which takes a pointer that was */
155 /* returned by get_ifi_info and frees all the dynamic memory.' */
156 extern void free_ifi_info(struct ifi_info
*);
158 #ifdef NOT_HAVE_DAEMON
159 extern int daemon(int nochdir
, int noclose
)