xref: /titanic_41/usr/src/cmd/cmd-inet/usr.lib/mdnsd/mDNSUNP.h (revision 4c06356b0f0fffb4fc1b6eccc8e5d8e2254a84d6)
1 /* -*- Mode: C; tab-width: 4 -*-
2  *
3  * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16 
17     Change History (most recent first):
18 
19 $Log: mDNSUNP.h,v $
20 Revision 1.19  2006/08/14 23:24:47  cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
22 
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
25 
26 Revision 1.17  2004/12/17 19:32:43  cheshire
27 Add missing semicolon
28 
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
32 
33 Revision 1.15  2004/11/30 22:37:01  cheshire
34 Update copyright dates and add "Mode: C; tab-width: 4" headers
35 
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
38 
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
42 
43 Revision 1.12  2004/01/28 21:12:15  cheshire
44 Reconcile mDNSIPv6Support & HAVE_IPV6 into a single flag (HAVE_IPV6)
45 
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).
49 
50 Revision 1.10  2003/12/11 03:03:51  rpantos
51 Clean up mDNSPosix so that it builds on OS X again.
52 
53 Revision 1.9  2003/12/08 20:47:02  rpantos
54 Add support for mDNSResponder on Linux.
55 
56 Revision 1.8  2003/08/12 19:56:26  cheshire
57 Update to APSL 2.0
58 
59 Revision 1.7  2003/08/06 18:20:51  cheshire
60 Makefile cleanup
61 
62 Revision 1.6  2003/07/02 21:19:59  cheshire
63 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
64 
65 Revision 1.5  2003/03/13 03:46:21  cheshire
66 Fixes to make the code build on Linux
67 
68 Revision 1.4  2002/12/23 22:13:32  jgraessl
69 
70 Reviewed by: Stuart Cheshire
71 Initial IPv6 support for mDNSResponder.
72 
73 Revision 1.3  2002/09/21 20:44:53  zarzycki
74 Added APSL info
75 
76 Revision 1.2  2002/09/19 04:20:44  cheshire
77 Remove high-ascii characters that confuse some systems
78 
79 Revision 1.1  2002/09/17 06:24:35  cheshire
80 First checkin
81 
82 */
83 
84 #pragma ident	"%Z%%M%	%I%	%E% SMI"
85 
86 #ifndef __mDNSUNP_h
87 #define __mDNSUNP_h
88 
89 #include <sys/types.h>
90 #include <sys/socket.h>
91 #include <net/if.h>
92 #include <netinet/in.h>
93 #include <arpa/inet.h>
94 
95 #ifdef HAVE_LINUX
96 #include <linux/socket.h>
97 #endif
98 
99 #ifdef  __cplusplus
100     extern "C" {
101 #endif
102 
103 #ifdef NOT_HAVE_SOCKLEN_T
104     typedef unsigned int socklen_t;
105 #endif
106 
107 #if !defined(_SS_MAXSIZE)
108 #if HAVE_IPV6
109 #define sockaddr_storage sockaddr_in6
110 #else
111 #define sockaddr_storage sockaddr
112 #endif // HAVE_IPV6
113 #endif // !defined(_SS_MAXSIZE)
114 
115 #ifndef NOT_HAVE_SA_LEN
116 #define GET_SA_LEN(X) (sizeof(struct sockaddr) > ((struct sockaddr*)&(X))->sa_len ? \
117                        sizeof(struct sockaddr) : ((struct sockaddr*)&(X))->sa_len   )
118 #elif HAVE_IPV6
119 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET  ? sizeof(struct sockaddr_in) : \
120                        ((struct sockaddr*)&(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
121 #else
122 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr))
123 #endif
124 
125 #define IFI_NAME    16          /* same as IFNAMSIZ in <net/if.h> */
126 #define IFI_HADDR    8          /* allow for 64-bit EUI-64 in future */
127 
128 // Renamed from my_in_pktinfo because in_pktinfo is used by Linux.
129 
130 struct my_in_pktinfo {
131     struct sockaddr_storage ipi_addr;
132     int                     ipi_ifindex;            /* received interface index */
133     char                    ipi_ifname[IFI_NAME];   /* received interface name  */
134 };
135 
136 /* From the text (Stevens, section 20.2): */
137 /* 'As an example of recvmsg we will write a function named recvfrom_flags that */
138 /* is similar to recvfrom but also returns: */
139 /*	1. the returned msg_flags value, */
140 /*	2. the destination addres of the received datagram (from the IP_RECVDSTADDR socket option, and */
141 /*	3. the index of the interface on which the datagram was received (the IP_RECVIF socket option).' */
142 extern ssize_t recvfrom_flags(int fd, void *ptr, size_t nbytes, int *flagsp,
143                struct sockaddr *sa, socklen_t *salenptr, struct my_in_pktinfo *pktp, u_char *ttl);
144 
145 struct ifi_info {
146   char    ifi_name[IFI_NAME];   /* interface name, null terminated */
147   u_char  ifi_haddr[IFI_HADDR]; /* hardware address */
148   u_short ifi_hlen;             /* #bytes in hardware address: 0, 6, 8 */
149   short   ifi_flags;            /* IFF_xxx constants from <net/if.h> */
150   short   ifi_myflags;          /* our own IFI_xxx flags */
151   int     ifi_index;            /* interface index */
152   struct sockaddr  *ifi_addr;   /* primary address */
153   struct sockaddr  *ifi_netmask;
154   struct sockaddr  *ifi_brdaddr;/* broadcast address */
155   struct sockaddr  *ifi_dstaddr;/* destination address */
156   struct ifi_info  *ifi_next;   /* next of these structures */
157 };
158 
159 #if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
160 #define PROC_IFINET6_PATH "/proc/net/if_inet6"
161 extern struct ifi_info  *get_ifi_info_linuxv6(int family, int doaliases);
162 #endif
163 
164 #if defined(AF_INET6) && HAVE_IPV6
165 #define INET6_ADDRSTRLEN 46 /*Maximum length of IPv6 address */
166 #endif
167 
168 
169 
170 #define IFI_ALIAS   1           /* ifi_addr is an alias */
171 
172 /* From the text (Stevens, section 16.6): */
173 /* 'Since many programs need to know all the interfaces on a system, we will develop a */
174 /* function of our own named get_ifi_info that returns a linked list of structures, one */
175 /* for each interface that is currently "up."' */
176 extern struct ifi_info  *get_ifi_info(int family, int doaliases);
177 
178 /* 'The free_ifi_info function, which takes a pointer that was */
179 /* returned by get_ifi_info and frees all the dynamic memory.' */
180 extern void             free_ifi_info(struct ifi_info *);
181 
182 #ifdef NOT_HAVE_DAEMON
183 extern int daemon(int nochdir, int noclose);
184 #endif
185 
186 #ifdef  __cplusplus
187     }
188 #endif
189 
190 #endif
191