]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSPosix/mDNSUNP.h
59b5501b37bf5c58a42879893a8f275f3eb94753
[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 * 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
18 #ifndef __mDNSUNP_h
19 #define __mDNSUNP_h
20
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <net/if.h>
24 #include <netinet/in.h>
25
26 #ifdef HAVE_LINUX
27 #include <linux/socket.h>
28 #endif
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #ifdef NOT_HAVE_SOCKLEN_T
35 typedef unsigned int socklen_t;
36 #endif
37
38 #if !defined(_SS_MAXSIZE)
39 #if HAVE_IPV6
40 #define sockaddr_storage sockaddr_in6
41 #else
42 #define sockaddr_storage sockaddr
43 #endif // HAVE_IPV6
44 #endif // !defined(_SS_MAXSIZE)
45
46 #ifndef NOT_HAVE_SA_LEN
47 #define GET_SA_LEN(X) (sizeof(struct sockaddr) > ((struct sockaddr*)&(X))->sa_len ? \
48 sizeof(struct sockaddr) : ((struct sockaddr*)&(X))->sa_len )
49 #elif HAVE_IPV6
50 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : \
51 ((struct sockaddr*)&(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
52 #else
53 #define GET_SA_LEN(X) (((struct sockaddr*)&(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr))
54 #endif
55
56 #define IFI_NAME 16 /* same as IFNAMSIZ in <net/if.h> */
57 #define IFI_HADDR 8 /* allow for 64-bit EUI-64 in future */
58
59 // Renamed from my_in_pktinfo because in_pktinfo is used by Linux.
60
61 struct my_in_pktinfo {
62 struct sockaddr_storage ipi_addr;
63 int ipi_ifindex; /* received interface index */
64 char ipi_ifname[IFI_NAME]; /* received interface name */
65 };
66
67 /* From the text (Stevens, section 20.2): */
68 /* 'As an example of recvmsg we will write a function named recvfrom_flags that */
69 /* is similar to recvfrom but also returns: */
70 /* 1. the returned msg_flags value, */
71 /* 2. the destination addres of the received datagram (from the IP_RECVDSTADDR socket option, and */
72 /* 3. the index of the interface on which the datagram was received (the IP_RECVIF socket option).' */
73 extern ssize_t recvfrom_flags(int fd, void *ptr, size_t nbytes, int *flagsp,
74 struct sockaddr *sa, socklen_t *salenptr, struct my_in_pktinfo *pktp, u_char *ttl);
75
76 struct ifi_info {
77 char ifi_name[IFI_NAME]; /* interface name, null terminated */
78 u_char ifi_haddr[IFI_HADDR]; /* hardware address */
79 u_short ifi_hlen; /* #bytes in hardware address: 0, 6, 8 */
80 short ifi_flags; /* IFF_xxx constants from <net/if.h> */
81 short ifi_myflags; /* our own IFI_xxx flags */
82 int ifi_index; /* interface index */
83 struct sockaddr *ifi_addr; /* primary address */
84 struct sockaddr *ifi_netmask;
85 struct sockaddr *ifi_brdaddr;/* broadcast address */
86 struct sockaddr *ifi_dstaddr;/* destination address */
87 struct ifi_info *ifi_next; /* next of these structures */
88 };
89
90 #if defined(AF_INET6) && HAVE_IPV6 && HAVE_LINUX
91 #define PROC_IFINET6_PATH "/proc/net/if_inet6"
92 extern struct ifi_info *get_ifi_info_linuxv6(int family, int doaliases);
93 #endif
94
95 #if defined(AF_INET6) && HAVE_IPV6
96 #define INET6_ADDRSTRLEN 46 /*Maximum length of IPv6 address */
97 #endif
98
99
100
101 #define IFI_ALIAS 1 /* ifi_addr is an alias */
102
103 /* From the text (Stevens, section 16.6): */
104 /* 'Since many programs need to know all the interfaces on a system, we will develop a */
105 /* function of our own named get_ifi_info that returns a linked list of structures, one */
106 /* for each interface that is currently "up."' */
107 extern struct ifi_info *get_ifi_info(int family, int doaliases);
108
109 /* 'The free_ifi_info function, which takes a pointer that was */
110 /* returned by get_ifi_info and frees all the dynamic memory.' */
111 extern void free_ifi_info(struct ifi_info *);
112
113 #ifdef NOT_HAVE_DAEMON
114 extern int daemon(int nochdir, int noclose);
115 #endif
116
117 #ifdef __cplusplus
118 }
119 #endif
120
121 #endif