1138593Ssam/*
2138593Ssam * Copyright (c) 1983, 1993
3138593Ssam *	The Regents of the University of California.  All rights reserved.
4138593Ssam *
5138593Ssam * Redistribution and use in source and binary forms, with or without
6138593Ssam * modification, are permitted provided that the following conditions
7138593Ssam * are met:
8138593Ssam * 1. Redistributions of source code must retain the above copyright
9138593Ssam *    notice, this list of conditions and the following disclaimer.
10138593Ssam * 2. Redistributions in binary form must reproduce the above copyright
11138593Ssam *    notice, this list of conditions and the following disclaimer in the
12138593Ssam *    documentation and/or other materials provided with the distribution.
13138593Ssam * 4. Neither the name of the University nor the names of its contributors
14138593Ssam *    may be used to endorse or promote products derived from this software
15138593Ssam *    without specific prior written permission.
16138593Ssam *
17138593Ssam * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18138593Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19138593Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20138593Ssam * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21138593Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22138593Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23138593Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24138593Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25138593Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26138593Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27138593Ssam * SUCH DAMAGE.
28138593Ssam */
29138593Ssam
30138593Ssam#ifndef lint
31138593Ssamstatic const char rcsid[] =
32138593Ssam  "$FreeBSD$";
33138593Ssam#endif /* not lint */
34138593Ssam
35138593Ssam#include <sys/types.h>
36138593Ssam#include <sys/ioctl.h>
37138593Ssam#include <sys/socket.h>
38138593Ssam#include <net/if.h>
39138593Ssam
40138593Ssam#include <err.h>
41138593Ssam#include <stdio.h>
42138593Ssam#include <stdlib.h>
43138593Ssam#include <string.h>
44166956Ssam#include <ifaddrs.h>
45138593Ssam
46138593Ssam#include <net/if_var.h>
47138593Ssam#define IPTUNNEL
48138593Ssam#include <netipx/ipx.h>
49138593Ssam#include <netipx/ipx_if.h>
50138593Ssam
51138593Ssam#include "ifconfig.h"
52138593Ssam
53138593Ssamstatic struct ifaliasreq ipx_addreq;
54138593Ssamstatic struct ifreq ipx_ridreq;
55138593Ssam
56138593Ssamstatic void
57166956Ssamipx_status(int s __unused, const struct ifaddrs *ifa)
58138593Ssam{
59138593Ssam	struct sockaddr_ipx *sipx, null_sipx;
60138593Ssam
61166956Ssam	sipx = (struct sockaddr_ipx *)ifa->ifa_addr;
62138593Ssam	if (sipx == NULL)
63138593Ssam		return;
64138593Ssam
65138593Ssam	printf("\tipx %s ", ipx_ntoa(sipx->sipx_addr));
66138593Ssam
67166956Ssam	if (ifa->ifa_flags & IFF_POINTOPOINT) {
68167388Ssam		sipx = (struct sockaddr_ipx *)ifa->ifa_dstaddr;
69166956Ssam		if (sipx == NULL) {
70138593Ssam			memset(&null_sipx, 0, sizeof(null_sipx));
71138593Ssam			sipx = &null_sipx;
72138593Ssam		}
73138593Ssam		printf("--> %s ", ipx_ntoa(sipx->sipx_addr));
74138593Ssam	}
75138593Ssam	putchar('\n');
76138593Ssam}
77138593Ssam
78138593Ssam#define SIPX(x) ((struct sockaddr_ipx *) &(x))
79138593Ssamstruct sockaddr_ipx *sipxtab[] = {
80138593Ssam	SIPX(ipx_ridreq.ifr_addr), SIPX(ipx_addreq.ifra_addr),
81138593Ssam	SIPX(ipx_addreq.ifra_mask), SIPX(ipx_addreq.ifra_broadaddr)
82138593Ssam};
83138593Ssam
84138593Ssamstatic void
85138593Ssamipx_getaddr(const char *addr, int which)
86138593Ssam{
87138593Ssam	struct sockaddr_ipx *sipx = sipxtab[which];
88138593Ssam
89138593Ssam	sipx->sipx_family = AF_IPX;
90138593Ssam	sipx->sipx_len = sizeof(*sipx);
91138593Ssam	sipx->sipx_addr = ipx_addr(addr);
92138593Ssam	if (which == MASK)
93138593Ssam		printf("Attempt to set IPX netmask will be ineffectual\n");
94138593Ssam}
95138593Ssam
96138593Ssamstatic void
97138593Ssamipx_postproc(int s, const struct afswtch *afp)
98138593Ssam{
99138593Ssam
100138593Ssam}
101138593Ssam
102138593Ssamstatic struct afswtch af_ipx = {
103138593Ssam	.af_name	= "ipx",
104138593Ssam	.af_af		= AF_IPX,
105138593Ssam	.af_status	= ipx_status,
106138593Ssam	.af_getaddr	= ipx_getaddr,
107138593Ssam	.af_postproc	= ipx_postproc,
108138593Ssam	.af_difaddr	= SIOCDIFADDR,
109138593Ssam	.af_aifaddr	= SIOCAIFADDR,
110138593Ssam	.af_ridreq	= &ipx_ridreq,
111138593Ssam	.af_addreq	= &ipx_addreq,
112138593Ssam};
113138593Ssam
114138593Ssamstatic __constructor void
115138593Ssamipx_ctor(void)
116138593Ssam{
117138593Ssam	af_register(&af_ipx);
118138593Ssam}
119