2 * Copyright (c) 2008-2009 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef __SI_MODULE_H__
25 #define __SI_MODULE_H__
29 #include <netinet/in.h>
30 #include <sys/socket.h>
36 #include <mach/mach.h>
40 #define forever for(;;)
41 #define string_equal(A,B) (strcmp(A,B)==0)
42 #define string_not_equal(A,B) (strcmp(A,B)!=0)
44 #define SI_CALL_USER_BYNAME 0
45 #define SI_CALL_USER_BYUID 1
46 #define SI_CALL_USER_ALL 2
47 #define SI_CALL_GROUP_BYNAME 3
48 #define SI_CALL_GROUP_BYGID 4
49 #define SI_CALL_GROUP_ALL 5
50 #define SI_CALL_NETGROUP_BYNAME 6
51 #define SI_CALL_IN_NETGROUP 7
52 #define SI_CALL_GROUPLIST 8
53 #define SI_CALL_ALIAS_BYNAME 9
54 #define SI_CALL_ALIAS_ALL 10
55 #define SI_CALL_HOST_BYNAME 11
56 #define SI_CALL_HOST_BYADDR 12
57 #define SI_CALL_HOST_ALL 13
58 #define SI_CALL_NETWORK_BYNAME 14
59 #define SI_CALL_NETWORK_BYADDR 15
60 #define SI_CALL_NETWORK_ALL 16
61 #define SI_CALL_SERVICE_BYNAME 17
62 #define SI_CALL_SERVICE_BYPORT 18
63 #define SI_CALL_SERVICE_ALL 19
64 #define SI_CALL_PROTOCOL_BYNAME 20
65 #define SI_CALL_PROTOCOL_BYNUMBER 21
66 #define SI_CALL_PROTOCOL_ALL 22
67 #define SI_CALL_RPC_BYNAME 23
68 #define SI_CALL_RPC_BYNUMBER 24
69 #define SI_CALL_RPC_ALL 25
70 #define SI_CALL_FS_BYSPEC 26
71 #define SI_CALL_FS_BYFILE 27
72 #define SI_CALL_FS_ALL 28
73 #define SI_CALL_ADDRINFO 29
74 #define SI_CALL_NAMEINFO 30
75 #define SI_CALL_IPNODE_BYNAME 31
76 #define SI_CALL_MAC_BYNAME 32
77 #define SI_CALL_MAC_BYMAC 33
78 #define SI_CALL_MAC_ALL 34
79 #define SI_CALL_DNS_QUERY 35
80 #define SI_CALL_DNS_SEARCH 36
82 #define si_call_returns_list(A) \
83 ((A==SI_CALL_USER_ALL)||(A==SI_CALL_GROUP_ALL)||(A==SI_CALL_HOST_ALL)||(A==SI_CALL_NETWORK_ALL)||\
84 (A==SI_CALL_SERVICE_ALL)||(A==SI_CALL_PROTOCOL_ALL)||(A==SI_CALL_RPC_ALL)||(A==SI_CALL_FS_ALL)||\
85 (A==SI_CALL_ALIAS_ALL)||(A==SI_CALL_NETGROUP_BYNAME)||(A==SI_CALL_ADDRINFO)||(A==SI_CALL_MAC_ALL))
87 #define si_call_str1_is_buffer(A) \
88 ((A==SI_CALL_HOST_BYADDR)||(A==SI_CALL_NAMEINFO))
90 #define CATEGORY_INVALID (-1)
91 #define CATEGORY_DEFAULT 0
92 #define CATEGORY_USER 1
93 #define CATEGORY_GROUP 2
94 #define CATEGORY_GROUPLIST 3
95 #define CATEGORY_NETGROUP 4
96 #define CATEGORY_ALIAS 5
97 #define CATEGORY_HOST_IPV4 6
98 #define CATEGORY_HOST_IPV6 7
99 #define CATEGORY_NETWORK 8
100 #define CATEGORY_SERVICE 9
101 #define CATEGORY_PROTOCOL 10
102 #define CATEGORY_RPC 11
103 #define CATEGORY_FS 12
104 #define CATEGORY_MAC 13
105 #define CATEGORY_NAMEINFO 14
106 #define CATEGORY_ADDRINFO 15
107 #define CATEGORY_DNSPACKET 16
108 #define CATEGORY_SRV 17
109 #define CATEGORY_COUNT 18
112 #define CATEGORY_HOST CATEGORY_HOST_IPV4
118 /* host, getaddrinfo, and getnameinfo status codes */
119 #define SI_STATUS_NO_ERROR 0
120 #define SI_STATUS_H_ERRNO_HOST_NOT_FOUND 1
121 #define SI_STATUS_H_ERRNO_TRY_AGAIN 2
122 #define SI_STATUS_H_ERRNO_NO_RECOVERY 3
123 #define SI_STATUS_H_ERRNO_NO_DATA 4
124 #define SI_STATUS_INTERNAL 10
125 #define SI_STATUS_WORKITEM_NOT_FOUND 11
126 #define SI_STATUS_RETURNS_ITEM 12
127 #define SI_STATUS_RETURNS_LIST 13
128 #define SI_STATUS_CALL_IN_PROGRESS 14
129 #define SI_STATUS_CALL_CANCELLED 15
130 #define SI_STATUS_EAI_PLUS_100 100
131 #define SI_STATUS_EAI_ADDRFAMILY 101
132 #define SI_STATUS_EAI_AGAIN 102
133 #define SI_STATUS_EAI_BADFLAGS 103
134 #define SI_STATUS_EAI_FAIL 104
135 #define SI_STATUS_EAI_FAMILY 105
136 #define SI_STATUS_EAI_MEMORY 106
137 #define SI_STATUS_EAI_NODATA 107
138 #define SI_STATUS_EAI_NONAME 108
139 #define SI_STATUS_EAI_SERVICE 109
140 #define SI_STATUS_EAI_SOCKTYPE 110
141 #define SI_STATUS_EAI_SYSTEM 111
142 #define SI_STATUS_EAI_BADHINTS 112
143 #define SI_STATUS_EAI_PROTOCOL 113
144 #define SI_STATUS_EAI_OVERFLOW 114
145 #define SI_STATUS_ERRNO_PLUS_200 200
147 typedef void (*item_async_callback
)(si_item_t
*, uint32_t, void *);
148 typedef void (*list_async_callback
)(si_list_t
*, uint32_t, void *);
150 typedef struct grouplist_s
158 typedef struct addrinfo_s
165 socket_data_t ai_addr
;
169 typedef struct nameinfo_s
181 typedef struct netgrent_s
188 typedef struct dnspacket_s
193 struct sockaddr
*dns_server
;
196 typedef struct si_srv_s
206 struct si_mod_vtable_s
208 void (*sim_close
)(struct si_mod_s
*si
);
210 int (*sim_is_valid
)(struct si_mod_s
*si
, si_item_t
*item
);
212 si_item_t
*(*sim_user_byname
)(struct si_mod_s
*si
, const char *name
);
213 si_item_t
*(*sim_user_byuid
)(struct si_mod_s
*si
, uid_t uid
);
214 si_list_t
*(*sim_user_all
)(struct si_mod_s
*si
);
216 si_item_t
*(*sim_group_byname
)(struct si_mod_s
*si
, const char *name
);
217 si_item_t
*(*sim_group_bygid
)(struct si_mod_s
*si
, gid_t gid
);
218 si_list_t
*(*sim_group_all
)(struct si_mod_s
*si
);
220 si_item_t
*(*sim_grouplist
)(struct si_mod_s
*si
, const char *name
);
222 si_list_t
*(*sim_netgroup_byname
)(struct si_mod_s
*si
, const char *name
);
223 int (*sim_in_netgroup
)(struct si_mod_s
*si
, const char *name
, const char *host
, const char *user
, const char *domain
);
225 si_item_t
*(*sim_alias_byname
)(struct si_mod_s
*si
, const char *name
);
226 si_list_t
*(*sim_alias_all
)(struct si_mod_s
*si
);
228 si_item_t
*(*sim_host_byname
)(struct si_mod_s
*si
, const char *name
, int af
, const char *interface
, uint32_t *err
);
229 si_item_t
*(*sim_host_byaddr
)(struct si_mod_s
*si
, const void *addr
, int af
, const char *interface
, uint32_t *err
);
230 si_list_t
*(*sim_host_all
)(struct si_mod_s
*si
);
232 si_item_t
*(*sim_network_byname
)(struct si_mod_s
*si
, const char *name
);
233 si_item_t
*(*sim_network_byaddr
)(struct si_mod_s
*si
, uint32_t addr
);
234 si_list_t
*(*sim_network_all
)(struct si_mod_s
*si
);
236 si_item_t
*(*sim_service_byname
)(struct si_mod_s
*si
, const char *name
, const char *proto
);
237 si_item_t
*(*sim_service_byport
)(struct si_mod_s
*si
, int port
, const char *proto
);
238 si_list_t
*(*sim_service_all
)(struct si_mod_s
*si
);
240 si_item_t
*(*sim_protocol_byname
)(struct si_mod_s
*si
, const char *name
);
241 si_item_t
*(*sim_protocol_bynumber
)(struct si_mod_s
*si
, int number
);
242 si_list_t
*(*sim_protocol_all
)(struct si_mod_s
*si
);
244 si_item_t
*(*sim_rpc_byname
)(struct si_mod_s
*si
, const char *name
);
245 si_item_t
*(*sim_rpc_bynumber
)(struct si_mod_s
*si
, int number
);
246 si_list_t
*(*sim_rpc_all
)(struct si_mod_s
*si
);
248 si_item_t
*(*sim_fs_byspec
)(struct si_mod_s
*si
, const char *spec
);
249 si_item_t
*(*sim_fs_byfile
)(struct si_mod_s
*si
, const char *file
);
250 si_list_t
*(*sim_fs_all
)(struct si_mod_s
*si
);
252 si_item_t
*(*sim_mac_byname
)(struct si_mod_s
*si
, const char *name
);
253 si_item_t
*(*sim_mac_bymac
)(struct si_mod_s
*si
, const char *mac
);
254 si_list_t
*(*sim_mac_all
)(struct si_mod_s
*si
);
256 si_list_t
*(*sim_addrinfo
)(struct si_mod_s
*si
, const void *node
, const void *serv
, uint32_t family
, uint32_t socktype
, uint32_t protocol
, uint32_t flags
, const char *interface
, uint32_t *err
);
257 int (*sim_wants_addrinfo
)(struct si_mod_s
*si
);
259 si_item_t
*(*sim_nameinfo
)(struct si_mod_s
*si
, const struct sockaddr
*sa
, int flags
, const char *interface
, uint32_t *err
);
261 si_list_t
*(*sim_srv_byname
)(struct si_mod_s
*si
, const char *qname
, const char *interface
, uint32_t *err
);
263 si_item_t
*(*sim_item_call
)(struct si_mod_s
*si
, int call
, const char *str1
, const char *str2
, const char *str3
, uint32_t num1
, uint32_t num2
, uint32_t *err
);
264 si_list_t
*(*sim_list_call
)(struct si_mod_s
*si
, int call
, const char *str1
, const char *str2
, const char *str3
, uint32_t num1
, uint32_t num2
, uint32_t num3
, uint32_t num4
, uint32_t *err
);
266 mach_port_t (*sim_async_call
)(struct si_mod_s
*si
, int call
, const char *str1
, const char *str2
, const char *str3
, uint32_t num1
, uint32_t num2
, uint32_t num3
, uint32_t num4
, void *callback
, void *context
);
267 void (*sim_async_cancel
)(mach_port_t p
);
268 void (*sim_async_handle_reply
)(mach_msg_header_t
*msg
);
271 #define SI_MOD_FLAG_STATIC 0x00000001
273 typedef struct si_mod_s
283 const struct si_mod_vtable_s
*vtable
;
286 si_mod_t
*si_module_with_name(const char *name
);
287 si_mod_t
*si_module_retain(si_mod_t
*si
);
288 void si_module_release(si_mod_t
*si
);
289 const char *si_module_name(si_mod_t
*si
);
290 int si_module_vers(si_mod_t
*si
);
292 si_mod_t
*si_search(void);
294 int si_item_match(si_item_t
*item
, int cat
, const void *name
, uint32_t num
, int which
);
295 int si_item_is_valid(si_item_t
*item
);
297 si_item_t
*si_user_byname(si_mod_t
*si
, const char *name
);
298 si_item_t
*si_user_byuid(si_mod_t
*si
, uid_t uid
);
299 si_list_t
*si_user_all(si_mod_t
*si
);
301 si_item_t
*si_group_byname(si_mod_t
*si
, const char *name
);
302 si_item_t
*si_group_bygid(si_mod_t
*si
, gid_t gid
);
303 si_list_t
*si_group_all(si_mod_t
*si
);
305 si_item_t
*si_grouplist(si_mod_t
*si
, const char *name
);
307 int si_in_netgroup(struct si_mod_s
*si
, const char *name
, const char *host
, const char *user
, const char *domain
);
308 si_list_t
*si_netgroup_byname(struct si_mod_s
*si
, const char *name
);
310 si_item_t
*si_alias_byname(struct si_mod_s
*si
, const char *name
);
311 si_list_t
*si_alias_all(struct si_mod_s
*si
);
313 si_item_t
*si_host_byname(si_mod_t
*si
, const char *name
, int af
, const char *interface
, uint32_t *err
);
314 si_item_t
*si_host_byaddr(si_mod_t
*si
, const void *addr
, int af
, const char *interface
, uint32_t *err
);
315 si_list_t
*si_host_all(si_mod_t
*si
);
317 si_item_t
*si_mac_byname(struct si_mod_s
*si
, const char *name
);
318 si_item_t
*si_mac_bymac(struct si_mod_s
*si
, const char *mac
);
319 si_list_t
*si_mac_all(struct si_mod_s
*si
);
321 si_item_t
*si_network_byname(si_mod_t
*si
, const char *name
);
322 si_item_t
*si_network_byaddr(si_mod_t
*si
, uint32_t addr
);
323 si_list_t
*si_network_all(si_mod_t
*si
);
325 si_item_t
*si_service_byname(si_mod_t
*si
, const char *name
, const char *proto
);
326 si_item_t
*si_service_byport(si_mod_t
*si
, int port
, const char *proto
);
327 si_list_t
*si_service_all(si_mod_t
*si
);
329 si_item_t
*si_protocol_byname(si_mod_t
*si
, const char *name
);
330 si_item_t
*si_protocol_bynumber(si_mod_t
*si
, uint32_t number
);
331 si_list_t
*si_protocol_all(si_mod_t
*si
);
333 si_item_t
*si_rpc_byname(si_mod_t
*si
, const char *name
);
334 si_item_t
*si_rpc_bynumber(si_mod_t
*si
, int number
);
335 si_list_t
*si_rpc_all(si_mod_t
*si
);
337 si_item_t
*si_fs_byspec(si_mod_t
*si
, const char *spec
);
338 si_item_t
*si_fs_byfile(si_mod_t
*si
, const char *file
);
339 si_list_t
*si_fs_all(si_mod_t
*si
);
341 int si_wants_addrinfo(si_mod_t
*s
);
342 si_list_t
*si_addrinfo(si_mod_t
*si
, const char *node
, const char *serv
, uint32_t family
, uint32_t socktype
, uint32_t protocol
, uint32_t flags
, const char *interface
, uint32_t *err
);
344 si_item_t
*si_nameinfo(si_mod_t
*si
, const struct sockaddr
*sa
, int flags
, const char *interface
, uint32_t *err
);
345 si_item_t
*si_ipnode_byname(si_mod_t
*si
, const char *name
, int family
, int flags
, const char *interface
, uint32_t *err
);
347 si_list_t
*si_srv_byname(si_mod_t
*si
, const char *qname
, const char *interface
, uint32_t *err
);
349 si_item_t
*si_item_call(si_mod_t
*si
, int call
, const char *str1
, const char *str2
, const char *str3
, uint32_t num1
, uint32_t num2
, uint32_t *err
);
350 si_list_t
*si_list_call(si_mod_t
*si
, int call
, const char *str1
, const char *str2
, const char *str3
, uint32_t num1
, uint32_t num2
, uint32_t num3
, uint32_t num4
, uint32_t *err
);
352 extern mach_port_t
si_async_call(si_mod_t
*si
, int call
, const char *str1
, const char *str2
, const char *str3
, uint32_t num1
, uint32_t num2
, uint32_t num3
, uint32_t num4
, void *callback
, void *context
);
353 extern void si_async_cancel(mach_port_t p
);
354 extern void si_async_handle_reply(mach_msg_header_t
*msg
);
356 char *si_standardize_mac_address(const char *addr
);
357 si_item_t
*si_addrinfo_v4(si_mod_t
*si
, int32_t flags
, int32_t sock
, int32_t proto
, uint16_t port
, struct in_addr
*addr
, uint16_t iface
, const char *cname
);
358 si_item_t
*si_addrinfo_v6(si_mod_t
*si
, int32_t flags
, int32_t sock
, int32_t proto
, uint16_t port
, struct in6_addr
*addr
, uint16_t iface
, const char *cname
);
359 si_item_t
*si_addrinfo_v4_mapped(si_mod_t
*si
, int32_t flags
, int32_t sock
, int32_t proto
, uint16_t port
, struct in_addr
*addr
, uint16_t iface
, const char *cname
);
360 si_list_t
*si_addrinfo_list(si_mod_t
*si
, uint32_t flags
, int socktype
, int proto
, struct in_addr
*a4
, struct in6_addr
*a6
, int port
, int scopeid
, const char *cname4
, const char *cname6
);
361 si_list_t
*si_addrinfo_list_from_hostent(si_mod_t
*si
, uint32_t flags
, uint32_t socktype
, uint32_t proto
, uint16_t port
, uint16_t scope
, const struct hostent
*h4
, const struct hostent
*h6
);
363 int _gai_serv_to_port(const char *serv
, uint32_t proto
, uint16_t *port
);
364 si_list_t
*_gai_simple(si_mod_t
*si
, const void *nodeptr
, const void *servptr
, uint32_t family
, uint32_t socktype
, uint32_t proto
, uint32_t flags
, const char *interface
, uint32_t *err
);
365 int si_inet_config(uint32_t *inet4
, uint32_t *inet6
);
367 #endif /* ! __SI_MODULE_H__ */