route.8: Remove NS remains.
[dragonfly.git] / sbin / ifconfig / af_ipx.c
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  * 3. 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  * $FreeBSD: src/sbin/ifconfig/af_ipx.c,v 1.1 2004/12/08 19:18:07 sam Exp $
30  */
31
32 #include <sys/types.h>
33 #include <sys/ioctl.h>
34 #include <sys/socket.h>
35 #include <net/if.h>
36 #include <net/route.h>
37
38 #include <err.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42
43 #include <net/if_var.h>
44 #define IPXIP
45 #define IPTUNNEL
46 #include <netipx/ipx.h>
47 #include <netipx/ipx_if.h>
48
49 #include "ifconfig.h"
50
51 static struct ifaliasreq ipx_addreq;
52 static struct ifreq ipx_ridreq;
53
54 static void
55 ipx_status(int s __unused, const struct rt_addrinfo * info)
56 {
57         struct sockaddr_ipx *sipx, null_sipx;
58
59         sipx = (struct sockaddr_ipx *)info->rti_info[RTAX_IFA];
60         if (sipx == NULL)
61                 return;
62
63         printf("\tipx %s ", ipx_ntoa(sipx->sipx_addr));
64
65         if (flags & IFF_POINTOPOINT) {
66                 sipx = (struct sockaddr_ipx *)info->rti_info[RTAX_BRD];
67                 if (!sipx) {
68                         memset(&null_sipx, 0, sizeof(null_sipx));
69                         sipx = &null_sipx;
70                 }
71                 printf("--> %s ", ipx_ntoa(sipx->sipx_addr));
72         }
73         putchar('\n');
74 }
75
76 #define SIPX(x) ((struct sockaddr_ipx *) &(x))
77 struct sockaddr_ipx *sipxtab[] = {
78         SIPX(ipx_ridreq.ifr_addr), SIPX(ipx_addreq.ifra_addr),
79         SIPX(ipx_addreq.ifra_mask), SIPX(ipx_addreq.ifra_broadaddr)
80 };
81
82 static void
83 ipx_getaddr(const char *addr, int which)
84 {
85         struct sockaddr_ipx *sipx = sipxtab[which];
86
87         sipx->sipx_family = AF_IPX;
88         sipx->sipx_len = sizeof(*sipx);
89         sipx->sipx_addr = ipx_addr(addr);
90         if (which == MASK)
91                 printf("Attempt to set IPX netmask will be ineffectual\n");
92 }
93
94 static void
95 ipx_postproc(int s, const struct afswtch *afp)
96 {
97         if (setipdst) {
98                 struct ipxip_req rq;
99                 int size = sizeof(rq);
100
101                 rq.rq_ipx = ipx_addreq.ifra_addr;
102                 rq.rq_ip = ipx_addreq.ifra_dstaddr;
103
104                 if (setsockopt(s, 0, SO_IPXIP_ROUTE, &rq, size) < 0)
105                         Perror("Encapsulation Routing");
106         }
107 }
108
109 static struct afswtch af_ipx = {
110         .af_name        = "ipx",
111         .af_af          = AF_IPX,
112         .af_status      = ipx_status,
113         .af_getaddr     = ipx_getaddr,
114         .af_postproc    = ipx_postproc,
115         .af_difaddr     = SIOCDIFADDR,
116         .af_aifaddr     = SIOCAIFADDR,
117         .af_ridreq      = &ipx_ridreq,
118         .af_addreq      = &ipx_addreq,
119 };
120
121 static __constructor(101) void
122 ipx_ctor(void)
123 {
124         af_register(&af_ipx);
125 }