111820Sjulian/*
211820Sjulian * Copyright (c) 1995 John Hay.  All rights reserved.
311820Sjulian *
411820Sjulian * Redistribution and use in source and binary forms, with or without
511820Sjulian * modification, are permitted provided that the following conditions
611820Sjulian * are met:
711820Sjulian * 1. Redistributions of source code must retain the above copyright
811820Sjulian *    notice, this list of conditions and the following disclaimer.
911820Sjulian * 2. Redistributions in binary form must reproduce the above copyright
1011820Sjulian *    notice, this list of conditions and the following disclaimer in the
1111820Sjulian *    documentation and/or other materials provided with the distribution.
1211820Sjulian * 3. All advertising materials mentioning features or use of this software
1311820Sjulian *    must display the following acknowledgement:
1411820Sjulian *	This product includes software developed by John Hay.
1511820Sjulian * 4. Neither the name of the author nor the names of any co-contributors
1611820Sjulian *    may be used to endorse or promote products derived from this software
1711820Sjulian *    without specific prior written permission.
1811820Sjulian *
1911820Sjulian * THIS SOFTWARE IS PROVIDED BY John Hay AND CONTRIBUTORS ``AS IS'' AND
2011820Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2111820Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2211820Sjulian * ARE DISCLAIMED.  IN NO EVENT SHALL John Hay OR CONTRIBUTORS BE LIABLE
2311820Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2411820Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2511820Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2611820Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2711820Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2811820Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2911820Sjulian * SUCH DAMAGE.
3011820Sjulian *
3150479Speter * $FreeBSD$
3211820Sjulian */
3311820Sjulian#ifndef _SAP_H_
3411820Sjulian#define _SAP_H_
3511820Sjulian
3611820Sjulian#define SAP_REQ			1
3711820Sjulian#define SAP_RESP		2
3811820Sjulian#define SAP_REQ_NEAR		3
3911820Sjulian#define SAP_RESP_NEAR		4
4011820Sjulian
4111820Sjulian#define SAPCMD_MAX		5
4211820Sjulian#ifdef SAPCMDS
4311820Sjulianchar *sapcmds[SAPCMD_MAX] =
4411820Sjulian	{ "#0", "REQUEST", "RESPONSE", "REQ NEAREST", "RESP NEAREST"};
4511820Sjulian#endif
4611820Sjulian
4715248Sjhay#define MAXSAPENTRIES		7
4811820Sjulian#define SAP_WILDCARD		0xFFFF
4911820Sjulian#define SERVNAMELEN		48
5011820Sjuliantypedef struct sap_info {
5111820Sjulian	u_short ServType;
5211820Sjulian	char    ServName[SERVNAMELEN];
5311820Sjulian	struct ipx_addr ipx;
5411820Sjulian	u_short hops;
5511820Sjulian	}sap_info;
5611820Sjulian
5711820Sjuliantypedef struct sap_packet {
5811820Sjulian	u_short sap_cmd;
5911820Sjulian	sap_info sap[0]; /* Variable length. */
6011820Sjulian	}sap_packet;
6111820Sjulian
6211820Sjuliantypedef struct sap_entry {
6311820Sjulian	struct sap_entry *forw;
6411820Sjulian	struct sap_entry *back;
6511820Sjulian	struct sap_entry *clone;
6611820Sjulian	struct interface *ifp;
6711820Sjulian	struct sap_info   sap;
6811820Sjulian	struct sockaddr   source;
6911820Sjulian	int hash;
7011820Sjulian	int state;
7111820Sjulian	int timer;
7211820Sjulian	}sap_entry;
7311820Sjulian
7427244Sjhay#define SAPHASHSIZ		256		/* Should be a power of 2 */
7511820Sjulian#define SAPHASHMASK		(SAPHASHSIZ-1)
7611820Sjuliantypedef struct sap_hash {
7711820Sjulian	struct sap_entry *forw;
7811820Sjulian	struct sap_entry *back;
7911820Sjulian	}sap_hash;
8011820Sjulian
8111820Sjulianextern sap_hash sap_head[SAPHASHSIZ];
8211820Sjulian
8311820Sjulianextern struct   sap_packet *sap_msg;
8411820Sjulian
8511820Sjulianvoid sapinit(void);
8611820Sjulianvoid sap_input(struct sockaddr *from, int size);
8727244Sjhayvoid sapsndmsg(struct sockaddr *dst, int flags, struct interface *ifp,
8827244Sjhay		int changesonly);
8927244Sjhayvoid sap_supply_toall(int changesonly);
9011820Sjulianvoid sap_supply(struct sockaddr *dst,
9111820Sjulian                int flags,
9211820Sjulian		struct interface *ifp,
9327244Sjhay		int ServType,
9427244Sjhay		int changesonly);
9511820Sjulian
9611820Sjulianstruct sap_entry *sap_lookup(u_short ServType, char *ServName);
9711820Sjulianstruct sap_entry *sap_nearestserver(ushort ServType, struct interface *ifp);
9811820Sjulianvoid sap_add(struct sap_info *si, struct sockaddr *from);
9911820Sjulianvoid sap_change(struct sap_entry *sap,
10011820Sjulian                struct sap_info *si,
10111820Sjulian		struct sockaddr *from);
10211820Sjulianvoid sap_add_clone(struct sap_entry *sap,
10311820Sjulian                   struct sap_info *clone,
10411820Sjulian		   struct sockaddr *from);
10511820Sjulianvoid sap_delete(struct sap_entry *sap);
10611820Sjulian
10711820Sjulian#endif /*_SAP_H_*/
10811820Sjulian
109