af_ipx.c revision 166956
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: head/sbin/ifconfig/af_ipx.c 166956 2007-02-24 23:55:46Z sam $"; 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 IPXIP 48138593Ssam#define IPTUNNEL 49138593Ssam#include <netipx/ipx.h> 50138593Ssam#include <netipx/ipx_if.h> 51138593Ssam 52138593Ssam#include "ifconfig.h" 53138593Ssam 54138593Ssamstatic struct ifaliasreq ipx_addreq; 55138593Ssamstatic struct ifreq ipx_ridreq; 56138593Ssam 57138593Ssamstatic void 58166956Ssamipx_status(int s __unused, const struct ifaddrs *ifa) 59138593Ssam{ 60138593Ssam struct sockaddr_ipx *sipx, null_sipx; 61138593Ssam 62166956Ssam sipx = (struct sockaddr_ipx *)ifa->ifa_addr; 63138593Ssam if (sipx == NULL) 64138593Ssam return; 65138593Ssam 66138593Ssam printf("\tipx %s ", ipx_ntoa(sipx->sipx_addr)); 67138593Ssam 68166956Ssam if (ifa->ifa_flags & IFF_POINTOPOINT) { 69166956Ssam sipx = (struct sockaddr_ipx *)ifa->ifa_broadaddr; 70166956Ssam if (sipx == NULL) { 71138593Ssam memset(&null_sipx, 0, sizeof(null_sipx)); 72138593Ssam sipx = &null_sipx; 73138593Ssam } 74138593Ssam printf("--> %s ", ipx_ntoa(sipx->sipx_addr)); 75138593Ssam } 76138593Ssam putchar('\n'); 77138593Ssam} 78138593Ssam 79138593Ssam#define SIPX(x) ((struct sockaddr_ipx *) &(x)) 80138593Ssamstruct sockaddr_ipx *sipxtab[] = { 81138593Ssam SIPX(ipx_ridreq.ifr_addr), SIPX(ipx_addreq.ifra_addr), 82138593Ssam SIPX(ipx_addreq.ifra_mask), SIPX(ipx_addreq.ifra_broadaddr) 83138593Ssam}; 84138593Ssam 85138593Ssamstatic void 86138593Ssamipx_getaddr(const char *addr, int which) 87138593Ssam{ 88138593Ssam struct sockaddr_ipx *sipx = sipxtab[which]; 89138593Ssam 90138593Ssam sipx->sipx_family = AF_IPX; 91138593Ssam sipx->sipx_len = sizeof(*sipx); 92138593Ssam sipx->sipx_addr = ipx_addr(addr); 93138593Ssam if (which == MASK) 94138593Ssam printf("Attempt to set IPX netmask will be ineffectual\n"); 95138593Ssam} 96138593Ssam 97138593Ssamstatic void 98138593Ssamipx_postproc(int s, const struct afswtch *afp) 99138593Ssam{ 100138593Ssam if (setipdst) { 101138593Ssam struct ipxip_req rq; 102138593Ssam int size = sizeof(rq); 103138593Ssam 104138593Ssam rq.rq_ipx = ipx_addreq.ifra_addr; 105138593Ssam rq.rq_ip = ipx_addreq.ifra_dstaddr; 106138593Ssam 107138593Ssam if (setsockopt(s, 0, SO_IPXIP_ROUTE, &rq, size) < 0) 108138593Ssam Perror("Encapsulation Routing"); 109138593Ssam } 110138593Ssam} 111138593Ssam 112138593Ssamstatic struct afswtch af_ipx = { 113138593Ssam .af_name = "ipx", 114138593Ssam .af_af = AF_IPX, 115138593Ssam .af_status = ipx_status, 116138593Ssam .af_getaddr = ipx_getaddr, 117138593Ssam .af_postproc = ipx_postproc, 118138593Ssam .af_difaddr = SIOCDIFADDR, 119138593Ssam .af_aifaddr = SIOCAIFADDR, 120138593Ssam .af_ridreq = &ipx_ridreq, 121138593Ssam .af_addreq = &ipx_addreq, 122138593Ssam}; 123138593Ssam 124138593Ssamstatic __constructor void 125138593Ssamipx_ctor(void) 126138593Ssam{ 127138593Ssam af_register(&af_ipx); 128138593Ssam} 129