1/*
2 * Copyright (c) 1999, Boris Popov
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 *    may be used to endorse or promote products derived from this software
15 *    without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD$
30 */
31#ifndef _IPXSAP_H_
32#define _IPXSAP_H_
33
34#define IPX_SAP_GENERAL_QUERY		1
35#define IPX_SAP_GENERAL_RESPONSE	2
36#define IPX_SAP_NEAREST_QUERY		3
37#define IPX_SAP_NEAREST_RESPONSE	4
38
39
40#define IPX_SAP_MAX_ENTRIES		7
41#define IPX_SAP_SERVER_DOWN		16
42#define IPX_SAP_SERVER_NAME_LEN		48
43#define IPX_SAP_REQUEST_LEN		4
44
45/* Values for server_type */
46#define IPX_SAP_FILE_SERVER		4
47
48struct sap_query {
49	u_short		query_type;	/* net order */
50	u_short		server_type;	/* net order */
51} __packed;
52
53struct sap_entry {
54	u_short		server_type;
55	u_char		server_name[IPX_SAP_SERVER_NAME_LEN];
56	struct ipx_addr	ipx;
57	u_short		hops;
58} __packed;
59
60struct sap_packet {
61	u_short		operation;
62	struct sap_entry sap_entries[1];
63} __packed;
64
65struct sap_rq {
66	struct sockaddr_ipx dest_addr;
67	int		sock;
68	int		entries;
69	struct sap_packet* buffer;
70};
71/*
72#define	sap_name_equal(n1,n2)	(strncmp(n1,n2,IPX_SAP_SERVER_NAME_LEN) == 0);
73#define	sap_type_equal(t1,t2)	(t1==IPX_SAP_GENERAL_RQ || t2==IPX_SAP_GENERAL_RQ || t1==t2);
74*/
75void sap_copy_name(char *dest,char *src);
76int  sap_getsock(int *rsock);
77
78
79int  sap_rq_init(struct sap_rq* out,int sock);
80int  sap_rq_flush(struct sap_rq* out);
81void sap_rq_general(struct sap_rq* out,u_short ser_type);
82void sap_rq_gns_request(struct sap_rq* out,u_short ser_type);
83void sap_rq_response(struct sap_rq* out,u_short type,char *name,struct sockaddr_ipx* addr,u_short hops,int down_allow);
84void sap_rq_gns_response(struct sap_rq* out,u_short type,char * name,struct sockaddr_ipx* addr,u_short hops);
85void sap_rq_set_destination(struct sap_rq* out,struct ipx_addr *dest);
86
87int  sap_find_nearest(int server_type, struct sockaddr_ipx *result,char *server_name);
88
89extern int (*sap_sendto_func)(void* buffer,int size,struct sockaddr_ipx* daddr,int sock);
90int  ipx_iffind(char *ifname, struct ipx_addr *addr);
91
92#endif /* !_IPXSAP_H_ */
93