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