• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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	__MDNS_WIN32__
19 #define	__MDNS_WIN32__
20 
21 #include	"CommonServices.h"
22 
23 #if( !defined( _WIN32_WCE ) )
24 	#include	<mswsock.h>
25 #endif
26 
27 #include	"mDNSEmbeddedAPI.h"
28 #include	"uDNS.h"
29 
30 #ifdef	__cplusplus
31 	extern "C" {
32 #endif
33 
34 
35 typedef struct Overlapped
36 {
37 	BOOL		pending;
38 	OVERLAPPED	data;
39 	WSABUF		wbuf;
40 	DWORD		error;
41 	DWORD		bytesTransferred;
42 	mDNSAddr	srcAddr;
43 	mDNSIPPort	srcPort;
44 	mDNSAddr	dstAddr;
45 	mDNSIPPort	dstPort;
46 } Overlapped;
47 
48 
49 typedef void ( *TCPReadEventHandler )( TCPSocket * sock );
50 typedef void ( *TCPUserCallback )();
51 
52 struct TCPSocket_struct
53 {
54 	TCPSocketFlags				flags;		// MUST BE FIRST FIELD -- mDNSCore expects every TCPSocket_struct to begin with TCPSocketFlags flags
55 	SOCKET						fd;
56 	TCPReadEventHandler			readEventHandler;
57 	HANDLE						connectEvent;
58 	BOOL						connected;
59 	TCPUserCallback				userCallback;
60 	void					*	userContext;
61 	Overlapped					overlapped;
62 	DWORD						lastError;
63 	BOOL						closed;
64 	uint8_t						bbuf[ 4192 ];
65 	uint8_t					*	bptr;
66 	uint8_t					*	eptr;
67 	uint8_t					*	ebuf;
68 	TCPSocket				*	nextDispatchable;
69 	mDNS					*	m;
70 };
71 
72 
73 struct UDPSocket_struct
74 {
75 	mDNSIPPort						port; 			// MUST BE FIRST FIELD -- mDNSCoreReceive expects every UDPSocket_struct to begin with mDNSIPPort port
76 	mDNSAddr						addr;			// This is initialized by our code. If we don't get the
77 													// dstAddr from WSARecvMsg we use this value instead.
78 	SOCKET							fd;
79 	LPFN_WSARECVMSG					recvMsgPtr;
80 	Overlapped						overlapped;
81 	WSAMSG							wmsg;
82 	DNSMessage						packet;
83 	uint8_t							controlBuffer[ 128 ];
84 	struct sockaddr_storage			srcAddr;		// This is filled in by the WSARecv* function
85 	INT								srcAddrLen;		// See above
86 	struct mDNSInterfaceData	*	ifd;
87 	UDPSocket					*	nextDispatchable;
88 	UDPSocket					*	next;
89 	mDNS						*	m;
90 };
91 
92 
93 //---------------------------------------------------------------------------------------------------------------------------
94 /*!	@struct		mDNSInterfaceData
95 
96 	@abstract	Structure containing interface-specific data.
97 */
98 
99 typedef struct	mDNSInterfaceData	mDNSInterfaceData;
100 struct	mDNSInterfaceData
101 {
102 	char						name[ 128 ];
103 	uint32_t					index;
104 	uint32_t					scopeID;
105 	struct UDPSocket_struct		sock;
106 	NetworkInterfaceInfo		interfaceInfo;
107 	mDNSBool					hostRegistered;
108 	mDNSInterfaceData		*	next;
109 };
110 
111 
112 //---------------------------------------------------------------------------------------------------------------------------
113 /*!	@typedef	RegisterWaitableEventHandler
114 */
115 typedef void		(*RegisterWaitableEventHandler)(mDNS * const inMDNS, HANDLE event, void * context );
116 
117 //---------------------------------------------------------------------------------------------------------------------------
118 /*!	@typedef	RegisterWaitableEventFunc
119 */
120 typedef mStatus		(*RegisterWaitableEventFunc)(mDNS * const inMDNS, HANDLE event, void * context, RegisterWaitableEventHandler handler );
121 
122 //---------------------------------------------------------------------------------------------------------------------------
123 /*!	@typedef	UnregisterWaitableEventHandler
124 */
125 typedef void		(*UnregisterWaitableEventFunc)(mDNS * const inMDNS, HANDLE event );
126 
127 //---------------------------------------------------------------------------------------------------------------------------
128 /*!	@typedef	ReportStatusFunc
129 */
130 typedef void		(*ReportStatusFunc)(int inType, const char *inFormat, ...);
131 
132 
133 //---------------------------------------------------------------------------------------------------------------------------
134 /*!	@struct		mDNS_PlatformSupport_struct
135 
136 	@abstract	Structure containing platform-specific data.
137 */
138 
139 struct	mDNS_PlatformSupport_struct
140 {
141 	HANDLE						mainThread;
142 	HANDLE						checkFileSharesTimer;
143 	mDNSs32						checkFileSharesTimeout;
144 	RegisterWaitableEventFunc	registerWaitableEventFunc;
145 	UnregisterWaitableEventFunc	unregisterWaitableEventFunc;
146 	ReportStatusFunc			reportStatusFunc;
147 	time_t						nextDHCPLeaseExpires;
148 	char						nbname[ 32 ];
149 	char						nbdomain[ 32 ];
150 	mDNSBool					smbFileSharing;
151 	mDNSBool					smbPrintSharing;
152 	ServiceRecordSet			smbSRS;
153 	AuthRecord					smbSubTypes[ 2 ];
154 	mDNSBool					registeredLoopback4;
155 	int							interfaceCount;
156 	mDNSInterfaceData *			interfaceList;
157 	mDNSInterfaceData *			inactiveInterfaceList;
158 	struct UDPSocket_struct		unicastSock4;
159 	struct UDPSocket_struct		unicastSock6;
160 };
161 
162 //---------------------------------------------------------------------------------------------------------------------------
163 /*!	@struct		ifaddrs
164 
165 	@abstract	Interface information
166 */
167 
168 struct ifaddrs
169 {
170 	struct ifaddrs *	ifa_next;
171 	char *				ifa_name;
172 	u_int				ifa_flags;
173 	struct sockaddr	*	ifa_addr;
174 	struct sockaddr	*	ifa_netmask;
175 	struct sockaddr	*	ifa_broadaddr;
176 	struct sockaddr	*	ifa_dstaddr;
177 	BYTE				ifa_physaddr[6];
178 	BOOL				ifa_dhcpEnabled;
179 	time_t				ifa_dhcpLeaseExpires;
180 	mDNSu8				ifa_womp;
181 	void *				ifa_data;
182 
183 	struct
184 	{
185 		uint32_t		index;
186 
187 	}	ifa_extra;
188 };
189 
190 
191 extern void		InterfaceListDidChange( mDNS * const inMDNS );
192 extern void		ComputerDescriptionDidChange( mDNS * const inMDNS );
193 extern void		TCPIPConfigDidChange( mDNS * const inMDNS );
194 extern void		DynDNSConfigDidChange( mDNS * const inMDNS );
195 extern void		FileSharingDidChange( mDNS * const inMDNS );
196 extern void		FirewallDidChange( mDNS * const inMDNS );
197 extern mStatus  TCPAddSocket( mDNS * const inMDNS, TCPSocket *sock );
198 extern mStatus	SetupInterfaceList( mDNS * const inMDNS );
199 extern mStatus	TearDownInterfaceList( mDNS * const inMDNS );
200 extern BOOL		IsWOMPEnabled();
201 extern void     DispatchSocketEvents( mDNS * const inMDNS );
202 
203 
204 #ifdef	__cplusplus
205 	}
206 #endif
207 
208 #endif	// __MDNS_WIN32__
209