1/*
2 * Copyright (c) 1983, 1993
3 *	The Regents of the University of California.  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 * 4. Neither the name of the University nor the names of its 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 REGENTS 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 REGENTS 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
30#ifndef lint
31static const char rcsid[] =
32  "$FreeBSD$";
33#endif /* not lint */
34
35#include <sys/types.h>
36#include <sys/ioctl.h>
37#include <sys/socket.h>
38#include <net/if.h>
39
40#include <err.h>
41#include <stdio.h>
42#include <stdlib.h>
43#include <string.h>
44#include <ifaddrs.h>
45
46#include <net/if_var.h>
47#define IPTUNNEL
48#include <netipx/ipx.h>
49#include <netipx/ipx_if.h>
50
51#include "ifconfig.h"
52
53static struct ifaliasreq ipx_addreq;
54static struct ifreq ipx_ridreq;
55
56static void
57ipx_status(int s __unused, const struct ifaddrs *ifa)
58{
59	struct sockaddr_ipx *sipx, null_sipx;
60
61	sipx = (struct sockaddr_ipx *)ifa->ifa_addr;
62	if (sipx == NULL)
63		return;
64
65	printf("\tipx %s ", ipx_ntoa(sipx->sipx_addr));
66
67	if (ifa->ifa_flags & IFF_POINTOPOINT) {
68		sipx = (struct sockaddr_ipx *)ifa->ifa_dstaddr;
69		if (sipx == NULL) {
70			memset(&null_sipx, 0, sizeof(null_sipx));
71			sipx = &null_sipx;
72		}
73		printf("--> %s ", ipx_ntoa(sipx->sipx_addr));
74	}
75	putchar('\n');
76}
77
78#define SIPX(x) ((struct sockaddr_ipx *) &(x))
79struct sockaddr_ipx *sipxtab[] = {
80	SIPX(ipx_ridreq.ifr_addr), SIPX(ipx_addreq.ifra_addr),
81	SIPX(ipx_addreq.ifra_mask), SIPX(ipx_addreq.ifra_broadaddr)
82};
83
84static void
85ipx_getaddr(const char *addr, int which)
86{
87	struct sockaddr_ipx *sipx = sipxtab[which];
88
89	sipx->sipx_family = AF_IPX;
90	sipx->sipx_len = sizeof(*sipx);
91	sipx->sipx_addr = ipx_addr(addr);
92	if (which == MASK)
93		printf("Attempt to set IPX netmask will be ineffectual\n");
94}
95
96static void
97ipx_postproc(int s, const struct afswtch *afp)
98{
99
100}
101
102static struct afswtch af_ipx = {
103	.af_name	= "ipx",
104	.af_af		= AF_IPX,
105	.af_status	= ipx_status,
106	.af_getaddr	= ipx_getaddr,
107	.af_postproc	= ipx_postproc,
108	.af_difaddr	= SIOCDIFADDR,
109	.af_aifaddr	= SIOCAIFADDR,
110	.af_ridreq	= &ipx_ridreq,
111	.af_addreq	= &ipx_addreq,
112};
113
114static __constructor void
115ipx_ctor(void)
116{
117	af_register(&af_ipx);
118}
119