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