From 591fd60492abf36e4c07d349b836ff40228df09e Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Fri, 28 Apr 2017 19:47:09 +0200 Subject: mopd: add new package for alpha netboot --- package/mopd/Makefile | 26 ++ package/mopd/src/Makefile | 34 ++ package/mopd/src/README | 20 + package/mopd/src/common/Makefile | 14 + package/mopd/src/common/VERSION | 1 + package/mopd/src/common/cmp.c | 45 ++ package/mopd/src/common/cmp.h | 42 ++ package/mopd/src/common/common.h | 100 +++++ package/mopd/src/common/device.c | 350 +++++++++++++++ package/mopd/src/common/device.h | 53 +++ package/mopd/src/common/dl.c | 322 +++++++++++++ package/mopd/src/common/dl.h | 42 ++ package/mopd/src/common/file.c | 820 ++++++++++++++++++++++++++++++++++ package/mopd/src/common/file.h | 56 +++ package/mopd/src/common/get.c | 152 +++++++ package/mopd/src/common/get.h | 49 ++ package/mopd/src/common/loop-bsd.c | 183 ++++++++ package/mopd/src/common/loop-linux2.c | 162 +++++++ package/mopd/src/common/mopdef.c | 54 +++ package/mopd/src/common/mopdef.h | 198 ++++++++ package/mopd/src/common/nma.c | 227 ++++++++++ package/mopd/src/common/nma.h | 43 ++ package/mopd/src/common/nmadef.h | 183 ++++++++ package/mopd/src/common/os.h | 53 +++ package/mopd/src/common/pf-linux2.c | 321 +++++++++++++ package/mopd/src/common/pf.c | 264 +++++++++++ package/mopd/src/common/pf.h | 48 ++ package/mopd/src/common/print.c | 707 +++++++++++++++++++++++++++++ package/mopd/src/common/print.h | 51 +++ package/mopd/src/common/put.c | 185 ++++++++ package/mopd/src/common/put.h | 48 ++ package/mopd/src/common/rc.c | 322 +++++++++++++ package/mopd/src/common/rc.h | 42 ++ package/mopd/src/mopa.out/Makefile | 5 + package/mopd/src/mopa.out/mopa.out.1 | 58 +++ package/mopd/src/mopa.out/mopa.out.c | 147 ++++++ package/mopd/src/mopchk/Makefile | 23 + package/mopd/src/mopchk/mopchk.1 | 64 +++ package/mopd/src/mopchk/mopchk.c | 167 +++++++ package/mopd/src/mopd/Makefile | 24 + package/mopd/src/mopd/TODO | 1 + package/mopd/src/mopd/mopd.8 | 109 +++++ package/mopd/src/mopd/mopd.c | 216 +++++++++ package/mopd/src/mopd/process.c | 684 ++++++++++++++++++++++++++++ package/mopd/src/mopd/process.h | 45 ++ package/mopd/src/mopprobe/Makefile | 23 + package/mopd/src/mopprobe/mopprobe.1 | 68 +++ package/mopd/src/mopprobe/mopprobe.c | 283 ++++++++++++ package/mopd/src/moptrace/Makefile | 23 + package/mopd/src/moptrace/moptrace.1 | 83 ++++ package/mopd/src/moptrace/moptrace.c | 157 +++++++ 51 files changed, 7397 insertions(+) create mode 100644 package/mopd/Makefile create mode 100644 package/mopd/src/Makefile create mode 100644 package/mopd/src/README create mode 100644 package/mopd/src/common/Makefile create mode 100644 package/mopd/src/common/VERSION create mode 100644 package/mopd/src/common/cmp.c create mode 100644 package/mopd/src/common/cmp.h create mode 100644 package/mopd/src/common/common.h create mode 100644 package/mopd/src/common/device.c create mode 100644 package/mopd/src/common/device.h create mode 100644 package/mopd/src/common/dl.c create mode 100644 package/mopd/src/common/dl.h create mode 100644 package/mopd/src/common/file.c create mode 100644 package/mopd/src/common/file.h create mode 100644 package/mopd/src/common/get.c create mode 100644 package/mopd/src/common/get.h create mode 100644 package/mopd/src/common/loop-bsd.c create mode 100644 package/mopd/src/common/loop-linux2.c create mode 100644 package/mopd/src/common/mopdef.c create mode 100644 package/mopd/src/common/mopdef.h create mode 100644 package/mopd/src/common/nma.c create mode 100644 package/mopd/src/common/nma.h create mode 100644 package/mopd/src/common/nmadef.h create mode 100644 package/mopd/src/common/os.h create mode 100644 package/mopd/src/common/pf-linux2.c create mode 100644 package/mopd/src/common/pf.c create mode 100644 package/mopd/src/common/pf.h create mode 100644 package/mopd/src/common/print.c create mode 100644 package/mopd/src/common/print.h create mode 100644 package/mopd/src/common/put.c create mode 100644 package/mopd/src/common/put.h create mode 100644 package/mopd/src/common/rc.c create mode 100644 package/mopd/src/common/rc.h create mode 100644 package/mopd/src/mopa.out/Makefile create mode 100644 package/mopd/src/mopa.out/mopa.out.1 create mode 100644 package/mopd/src/mopa.out/mopa.out.c create mode 100644 package/mopd/src/mopchk/Makefile create mode 100644 package/mopd/src/mopchk/mopchk.1 create mode 100644 package/mopd/src/mopchk/mopchk.c create mode 100644 package/mopd/src/mopd/Makefile create mode 100644 package/mopd/src/mopd/TODO create mode 100644 package/mopd/src/mopd/mopd.8 create mode 100644 package/mopd/src/mopd/mopd.c create mode 100644 package/mopd/src/mopd/process.c create mode 100644 package/mopd/src/mopd/process.h create mode 100644 package/mopd/src/mopprobe/Makefile create mode 100644 package/mopd/src/mopprobe/mopprobe.1 create mode 100644 package/mopd/src/mopprobe/mopprobe.c create mode 100644 package/mopd/src/moptrace/Makefile create mode 100644 package/mopd/src/moptrace/moptrace.1 create mode 100644 package/mopd/src/moptrace/moptrace.c diff --git a/package/mopd/Makefile b/package/mopd/Makefile new file mode 100644 index 000000000..e3ffe9dd3 --- /dev/null +++ b/package/mopd/Makefile @@ -0,0 +1,26 @@ +# This file is part of the OpenADK project. OpenADK is copyrighted +# material, please see the LICENCE file in the top-level directory. + +include $(ADK_TOPDIR)/rules.mk + +PKG_NAME:= mopd +PKG_VERSION:= 1.3.5 +PKG_RELEASE:= 1 +PKG_DESCR:= mop daemon +PKG_SECTION:= net/misc + +NO_DISTFILES:= 1 + +include $(ADK_TOPDIR)/mk/package.mk + +$(eval $(call PKG_template,MOPD,mopd,$(PKG_VERSION)-$(PKG_RELEASE),$(PKG_DEPENDS),$(PKG_DESCR),$(PKG_SECTION))) + +CONFIG_STYLE:= manual +INSTALL_STYLE:= manual + +mopd-install: + $(INSTALL_DIR) $(IDIR_MOPD)/usr/sbin + $(INSTALL_BIN) $(WRKBUILD)/mopd/mopd \ + $(IDIR_MOPD)/usr/sbin + +include $(ADK_TOPDIR)/mk/pkg-bottom.mk diff --git a/package/mopd/src/Makefile b/package/mopd/src/Makefile new file mode 100644 index 000000000..980579251 --- /dev/null +++ b/package/mopd/src/Makefile @@ -0,0 +1,34 @@ + +# uncomment this to send the correct hostname to the client +# otherwise 'DEFAULT_HOSTNAME' will be sent +# REAL_HOSTNAME = "-DSEND_REAL_HOSTNAME" +REAL_HOSTNAME ="" +DEFAULT_HOSTNAME="-DDEFAULT_HOSTNAME=\\\"ipc\\\"" + +# this is the path mopd will look for files in +MOP_PATH="-DMOP_FILE_PATH=\\\"/tftpboot/mop\\\"" + +# compiling on Alpha Linux 2.2.17 i needed the following: +# AOUT_SUPPORT="-DNOAOUT" +AOUT_SUPPORT="" + +CFLAGS="-g ${AOUT_SUPPORT} ${MOP_PATH} ${DEFAULT_HOSTNAME} ${REAL_HOSTNAME}" + +#make file to build linux-mopd +SUBDIRS=common mopd mopchk mopprobe moptrace + +all: + for dir in ${SUBDIRS}; \ + do \ + echo making $$dir; \ + (cd $$dir; make CFLAGS=$(CFLAGS) ) ; \ + done + + +clean: + for dir in ${SUBDIRS} ; \ + do \ + (cd $$dir ; make clean); \ + done + + diff --git a/package/mopd/src/README b/package/mopd/src/README new file mode 100644 index 000000000..e89184fd9 --- /dev/null +++ b/package/mopd/src/README @@ -0,0 +1,20 @@ +mopd-linux-20000808 + + This is the Linux version of Mats Jansens' Mopd. + + The sources here are taken from the NetBSD version of mopd 2.5.3/4 + in CVS, plus some bits from the OpenBSD port, and the security + fixes reported on BUGTRAQ on 08 Aug 2000. + + I had to rewrite the Makefiles, and hack things about a bit to compile + under Linux, So if this version doesnt work for you, send email to the + Linux/VAX list detailing the problem. + + The mopa.out program does not work. The a.out structures have different + names under NetBSD and Linux (see /usr/include/a.out.h), and so the + code needs re-writing. + + atp@pergamentum.com 8/Aug/2000 + + Patches from John Nall added for Alpha/Linux + diff --git a/package/mopd/src/common/Makefile b/package/mopd/src/common/Makefile new file mode 100644 index 000000000..3b8022378 --- /dev/null +++ b/package/mopd/src/common/Makefile @@ -0,0 +1,14 @@ +#simple make file for linux + + +OBJS=cmp.o dl.o get.o mopdef.o pf-linux2.o put.o device.o file.o loop-linux2.o nma.o print.o rc.o + +libcommon.a: ${OBJS} + ar -rs libcommon.a ${OBJS} + +.c.o: .o + $(CC) -c $(CFLAGS) $< + +clean: + rm -f *.o *.a *~ + diff --git a/package/mopd/src/common/VERSION b/package/mopd/src/common/VERSION new file mode 100644 index 000000000..aedc15bb0 --- /dev/null +++ b/package/mopd/src/common/VERSION @@ -0,0 +1 @@ +2.5.3 diff --git a/package/mopd/src/common/cmp.c b/package/mopd/src/common/cmp.c new file mode 100644 index 000000000..cefa542b9 --- /dev/null +++ b/package/mopd/src/common/cmp.c @@ -0,0 +1,45 @@ +/* $NetBSD: cmp.c,v 1.2 1997/03/25 03:07:02 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: cmp.c,v 1.2 1997/03/25 03:07:02 thorpej Exp $"; +#endif + +#include "os.h" +#include "cmp.h" + +int +mopCmpEAddr(addr1, addr2) + u_char *addr1, *addr2; +{ + return(memcmp((char *)addr1, (char *)addr2, 6)); +} diff --git a/package/mopd/src/common/cmp.h b/package/mopd/src/common/cmp.h new file mode 100644 index 000000000..555403350 --- /dev/null +++ b/package/mopd/src/common/cmp.h @@ -0,0 +1,42 @@ +/* $NetBSD: cmp.h,v 1.2 1997/03/25 03:07:04 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: cmp.h,v 1.2 1997/03/25 03:07:04 thorpej Exp $ + * + */ + +#ifndef _CMP_H_ +#define _CMP_H_ + +__BEGIN_DECLS +int mopCmpEAddr __P((u_char *, u_char *)); +__END_DECLS + +#endif _CMP_H_ diff --git a/package/mopd/src/common/common.h b/package/mopd/src/common/common.h new file mode 100644 index 000000000..ed37f95b9 --- /dev/null +++ b/package/mopd/src/common/common.h @@ -0,0 +1,100 @@ +/* $NetBSD: common.h,v 1.3 1997/10/16 23:24:26 lukem Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: common.h,v 1.3 1997/10/16 23:24:26 lukem Exp $ + * + */ + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#define MAXDL 16 /* maximum number concurrent load */ +#define IFNAME_SIZE 32 /* maximum size if interface name */ +#define BUFSIZE 1600 /* main receive buffer size */ +#define HDRSIZ 22 /* room for 803.2 header */ + +#ifndef DEFAULT_HOSTNAME +#define DEFAULT_HOSTNAME "ipc" +#endif + +#ifndef MOP_FILE_PATH +#define MOP_FILE_PATH "/tftpboot/mop" +#endif + +#define DEBUG_ONELINE 1 +#define DEBUG_HEADER 2 +#define DEBUG_INFO 3 + +/* + * structure per interface + * + */ + +struct if_info { + int fd; /* File Descriptor */ + int trans; /* Transport type Ethernet/802.3 */ + u_char eaddr[6]; /* Ethernet addr of this interface */ + char if_name[IFNAME_SIZE]; /* Interface Name */ + int (*iopen) __P((char *, int, u_short, int)); + /* Interface Open Routine */ + int (*write) __P((int, u_char *, int, int)); + /* Interface Write Routine */ + void (*read) __P((void)); /* Interface Read Routine */ + struct if_info *next; /* Next Interface */ +}; + +#define DL_STATUS_FREE 0 +#define DL_STATUS_READ_IMGHDR 1 +#define DL_STATUS_SENT_MLD 2 +#define DL_STATUS_SENT_PLT 3 + +struct dllist { + u_char status; /* Status byte */ + struct if_info *ii; /* interface pointer */ + u_char eaddr[6]; /* targets ethernet addres */ + int ldfd; /* filedescriptor for loadfile */ + u_short dl_bsz; /* Data Link Buffer Size */ + int timeout; /* Timeout counter */ + u_char count; /* Packet Counter */ + u_int32_t loadaddr; /* Load Address */ + u_int32_t xferaddr; /* Transfer Address */ + u_int32_t nloadaddr; /* Next Load Address */ + off_t lseek; /* Seek before last read */ + int aout; /* Is it an a.out file */ + u_int32_t a_text; /* Size of text segment */ + u_int32_t a_text_fill; /* Size of text segment fill */ + u_int32_t a_data; /* Size of data segment */ + u_int32_t a_data_fill; /* Size of data segment fill */ + u_int32_t a_bss; /* Size of bss segment */ + u_int32_t a_bss_fill; /* Size of bss segment fill */ + off_t a_lseek; /* Keep track of pos in newfile */ +}; + +#endif /* _COMMON_H_ */ diff --git a/package/mopd/src/common/device.c b/package/mopd/src/common/device.c new file mode 100644 index 000000000..536c474cb --- /dev/null +++ b/package/mopd/src/common/device.c @@ -0,0 +1,350 @@ +/* $NetBSD: device.c,v 1.2 1997/03/25 03:07:06 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: device.c,v 1.2 1997/03/25 03:07:06 thorpej Exp $"; +#endif + +#include "os.h" +#include "common.h" +#include "device.h" +#include "mopdef.h" +#include "pf.h" + +struct if_info *iflist; /* Interface List */ + +void deviceOpen __P((char *, u_short, int)); + +/* + * Return ethernet adress for interface + */ + +void +deviceEthAddr(ifname, eaddr) + char *ifname; + u_char *eaddr; +{ + char inbuf[8192]; + struct ifconf ifc; + struct ifreq *ifr; + struct sockaddr_dl *sdl; + int fd; + int i, len; + +#ifdef DEV_NEW_CONF + /* We cannot use SIOCGIFADDR on the BPF descriptor. + We must instead get all the interfaces with SIOCGIFCONF + and find the right one. */ + + /* Use datagram socket to get Ethernet address. */ + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "deviceEthAddr: socket: %m"); + exit(1); + } + + ifc.ifc_len = sizeof(inbuf); + ifc.ifc_buf = inbuf; + if (ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc) < 0 || + ifc.ifc_len < sizeof(struct ifreq)) { + syslog(LOG_ERR, "deviceEthAddr: SIOGIFCONF: %m"); + (void) close(fd); + exit(1); + } + ifr = ifc.ifc_req; + for (i = 0; i < ifc.ifc_len; + i += len, ifr = (struct ifreq *)((caddr_t)ifr + len)) { + len = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len; + sdl = (struct sockaddr_dl *)&ifr->ifr_addr; + if (sdl->sdl_family != AF_LINK || sdl->sdl_type != IFT_ETHER || + sdl->sdl_alen != 6) + continue; + if (!strncmp(ifr->ifr_name, ifname, sizeof(ifr->ifr_name))) { + memmove((caddr_t)eaddr, (caddr_t)LLADDR(sdl), 6); + (void) close(fd); + return; + } + } + + syslog(LOG_ERR, "deviceEthAddr: Never saw interface `%s'!", ifname); + (void) close(fd); + exit(1); + +#else + int j = 0; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "deviceEthAddr: old socket: %m"); + exit(1); + } + ifc.ifc_len = sizeof inbuf; + ifc.ifc_buf = (caddr_t)inbuf; + if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 || + ifc.ifc_len < sizeof(struct ifreq)) { + syslog(LOG_ERR, "deviceEthAddr: old SIOCGIFCONF: %m"); + (void) close(fd); + exit(1); + } + + ifr = ifc.ifc_req; + for(i=0;i<(ifc.ifc_len / sizeof(struct ifreq));i++,ifr++){ + if (ioctl(fd, SIOCGIFHWADDR, (char *)ifr) < 0) { + syslog(LOG_ERR,"deviceEthAddr: SIOGIFHWADDR failed. ERRNO: %d\n",errno); + continue; + } + if(memmove((caddr_t)eaddr, (caddr_t)ifr->ifr_hwaddr.sa_data, 6) == NULL){ + syslog(LOG_ERR, "deviceEthAddr: memmove returned NULL: %m"); + (void) close(fd); + exit(1); + } + } + + (void) close(fd); + return; +#endif /* DEV_NEW_CONF */ +} + +void +deviceOpen(ifname, proto, trans) + char *ifname; + u_short proto; + int trans; +{ + struct if_info *p, tmp; + + strcpy(tmp.if_name,ifname); + tmp.iopen = pfInit; + + switch (proto) { + case MOP_K_PROTO_RC: + tmp.read = mopReadRC; + tmp.fd = mopOpenRC(&tmp, trans); + break; + case MOP_K_PROTO_DL: + tmp.read = mopReadDL; + tmp.fd = mopOpenDL(&tmp, trans); + break; + default: + break; + } + + if (tmp.fd != -1) { + + p = (struct if_info *)malloc(sizeof(*p)); + if (p == 0) { + syslog(LOG_ERR, "deviceOpen: malloc: %m"); + exit(1); + } + + p->next = iflist; + iflist = p; + + strcpy(p->if_name,tmp.if_name); + p->iopen = tmp.iopen; + p->write = pfWrite; + p->read = tmp.read; + memset((char *)p->eaddr, 0, sizeof(p->eaddr)); + p->fd = tmp.fd; + + deviceEthAddr(p->if_name,&p->eaddr[0]); + } +} + +void +deviceInitOne(ifname) + char *ifname; +{ + char interface[IFNAME_SIZE]; + struct if_info *p; + int trans; +#ifdef _AIX + char dev[IFNAME_SIZE]; + int unit,j; + + unit = 0; + for (j = 0; j < strlen(ifname); j++) { + if (isalpha(ifname[j])) { + dev[j] = ifname[j]; + } else { + if (isdigit(ifname[j])) { + unit = unit*10 + ifname[j] - '0'; + dev[j] = '\0'; + } + } + } + + if ((strlen(dev) == 2) && + (dev[0] == 'e') && + ((dev[1] == 'n') || (dev[1] == 't'))) { + sprintf(interface,"ent%d\0",unit); + } else { + sprintf(interface,"%s%d\0",dev,unit); + } +#else + sprintf(interface,"%s",ifname); +#endif /* _AIX */ + + /* Ok, init it just once */ + + p = iflist; + for (p = iflist; p; p = p->next) { + if (strcmp(p->if_name,interface) == 0) { + return; + } + } + + syslog(LOG_INFO, "Initialized %s", interface); + + /* Ok, get transport information */ + + trans = pfTrans(interface); + +#ifndef NORC + /* Start with MOP Remote Console */ + + switch (trans) { + case TRANS_ETHER: + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_ETHER); + break; + case TRANS_8023: + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_8023); + break; + case TRANS_ETHER+TRANS_8023: + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_ETHER); + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_8023); + break; + case TRANS_ETHER+TRANS_8023+TRANS_AND: + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_ETHER+TRANS_8023); + break; + } +#endif + +#ifndef NODL + /* and next MOP Dump/Load */ + + switch (trans) { + case TRANS_ETHER: + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_ETHER); + break; + case TRANS_8023: + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_8023); + break; + case TRANS_ETHER+TRANS_8023: + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_ETHER); + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_8023); + break; + case TRANS_ETHER+TRANS_8023+TRANS_AND: + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_ETHER+TRANS_8023); + break; + } +#endif + +} + +/* + * Initialize all "candidate" interfaces that are in the system + * configuration list. A "candidate" is up, not loopback and not + * point to point. + */ +void +deviceInitAll() +{ +#ifdef DEV_NEW_CONF + char inbuf[8192]; + struct ifconf ifc; + struct ifreq *ifr; + struct sockaddr_dl *sdl; + int fd; + int i, len; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "deviceInitAll: socket: %m"); + exit(1); + } + + ifc.ifc_len = sizeof(inbuf); + ifc.ifc_buf = inbuf; + if (ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc) < 0 || + ifc.ifc_len < sizeof(struct ifreq)) { + syslog(LOG_ERR, "deviceInitAll: SIOCGIFCONF: %m"); + exit(1); + } + ifr = ifc.ifc_req; + for (i = 0; i < ifc.ifc_len; + i += len, ifr = (struct ifreq *)((caddr_t)ifr + len)) { + len = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len; + sdl = (struct sockaddr_dl *)&ifr->ifr_addr; + if (sdl->sdl_family != AF_LINK || sdl->sdl_type != IFT_ETHER || + sdl->sdl_alen != 6) + continue; + if (ioctl(fd, SIOCGIFFLAGS, (caddr_t)ifr) < 0) { + syslog(LOG_ERR, "deviceInitAll: SIOCGIFFLAGS: %m"); + continue; + } + if ((ifr->ifr_flags & + (IFF_UP | IFF_LOOPBACK | IFF_POINTOPOINT)) != IFF_UP) + continue; + deviceInitOne(ifr->ifr_name); + } + (void) close(fd); +#else + int fd; + int n; + struct ifreq ibuf[8], *ifrp; + struct ifconf ifc; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "deviceInitAll: old socket: %m"); + exit(1); + } + ifc.ifc_len = sizeof ibuf; + ifc.ifc_buf = (caddr_t)ibuf; + if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 || + ifc.ifc_len < sizeof(struct ifreq)) { + syslog(LOG_ERR, "deviceInitAll: old SIOCGIFCONF: %m"); + exit(1); + } + ifrp = ibuf; + n = ifc.ifc_len / sizeof(*ifrp); + for (; --n >= 0; ++ifrp) { + if (ioctl(fd, SIOCGIFFLAGS, (char *)ifrp) < 0) { + continue; + } + if (/*(ifrp->ifr_flags & IFF_UP) == 0 ||*/ + ifrp->ifr_flags & IFF_LOOPBACK || + ifrp->ifr_flags & IFF_POINTOPOINT) + continue; + deviceInitOne(ifrp->ifr_name); + } + + (void) close(fd); +#endif /* DEV_NEW_CONF */ +} diff --git a/package/mopd/src/common/device.h b/package/mopd/src/common/device.h new file mode 100644 index 000000000..59c6990b9 --- /dev/null +++ b/package/mopd/src/common/device.h @@ -0,0 +1,53 @@ +/* $NetBSD: device.h,v 1.2 1997/03/25 03:07:07 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: device.h,v 1.2 1997/03/25 03:07:07 thorpej Exp $ + * + */ + +#ifndef _DEVICE_H_ +#define _DEVICE_H_ + +__BEGIN_DECLS +#ifdef DEV_NEW_CONF +void deviceEthAddr __P((char *, u_char *)); +#endif +void deviceInitOne __P((char *)); +void deviceInitAll __P((void)); + +/* from loop-bsd.c */ +void Loop __P((void)); +int mopOpenDL __P((struct if_info *, int)); +int mopOpenRC __P((struct if_info *, int)); +void mopReadDL __P((void)); +void mopReadRC __P((void)); +__END_DECLS + +#endif _DEVICE_H_ diff --git a/package/mopd/src/common/dl.c b/package/mopd/src/common/dl.c new file mode 100644 index 000000000..58774dc14 --- /dev/null +++ b/package/mopd/src/common/dl.c @@ -0,0 +1,322 @@ +/* $NetBSD: dl.c,v 1.3 1997/10/16 23:24:31 lukem Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: dl.c,v 1.3 1997/10/16 23:24:31 lukem Exp $"; +#endif + +#include "os.h" +#include "dl.h" +#include "get.h" +#include "mopdef.h" +#include "print.h" + +void +mopDumpDL(fd, pkt, trans) + FILE *fd; + u_char *pkt; + int trans; +{ + int i,index = 0; + u_int32_t tmpl; + u_char tmpc,c,program[257],code,*ucp; + u_short len,tmps,moplen; + + len = mopGetLength(pkt, trans); + + switch (trans) { + case TRANS_8023: + index = 22; + moplen = len - 8; + break; + default: + index = 16; + moplen = len; + } + code = mopGetChar(pkt,&index); + + /* see above, if (len < 8) then moplen ends up around 65535 */ + if (moplen > len) moplen = len; + + switch (code) { + case MOP_K_CODE_MLT: + + tmpc = mopGetChar(pkt,&index); /* Load Number */ + (void)fprintf(fd,"Load Number : %02x\n",tmpc); + + if (moplen > 6) { + tmpl = mopGetLong(pkt,&index);/* Load Address */ + (void)fprintf(fd,"Load Address : %08x\n", tmpl); + } + + if (moplen > 10) { +#ifndef SHORT_PRINT + for (i = 0; i < (moplen - 10); i++) { + if ((i % 16) == 0) { + if ((i / 16) == 0) { + (void)fprintf(fd, + "Image Data : %04x ", + moplen-10); + } else { + (void)fprintf(fd, + " "); + } + } + + (void)fprintf(fd, "%02x ", + mopGetChar(pkt,&index)); + if ((i % 16) == 15) + (void)fprintf(fd,"\n"); + } + + if ((i % 16) != 15) + (void)fprintf(fd,"\n"); +#else + index = index + moplen - 10; +#endif + } + + tmpl = mopGetLong(pkt,&index); /* Load Address */ + (void)fprintf(fd,"Xfer Address : %08x\n", tmpl); + + break; + case MOP_K_CODE_DCM: + + /* Empty Message */ + + break; + case MOP_K_CODE_MLD: + + tmpc = mopGetChar(pkt,&index); /* Load Number */ + (void)fprintf(fd,"Load Number : %02x\n",tmpc); + + tmpl = mopGetLong(pkt,&index); /* Load Address */ + (void)fprintf(fd,"Load Address : %08x\n", tmpl); + + if (moplen > 6) { +#ifndef SHORT_PRINT + for (i = 0; i < (moplen - 6); i++) { + if ((i % 16) == 0) { + if ((i / 16) == 0) { + (void)fprintf(fd, + "Image Data : %04x ", + moplen-6); + } else { + (void)fprintf(fd, + " "); + } + } + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + if ((i % 16) == 15) + (void)fprintf(fd,"\n"); + } + + if ((i % 16) != 15) + (void)fprintf(fd,"\n"); +#else + index = index + moplen - 6; +#endif + } + + break; + case MOP_K_CODE_ASV: + + /* Empty Message */ + + break; + case MOP_K_CODE_RMD: + + tmpl = mopGetLong(pkt,&index); /* Memory Address */ + (void)fprintf(fd,"Mem Address : %08x\n", tmpl); + + tmps = mopGetShort(pkt,&index); /* Count */ + (void)fprintf(fd,"Count : %04x (%d)\n",tmps,tmps); + + break; + case MOP_K_CODE_RPR: + + tmpc = mopGetChar(pkt,&index); /* Device Type */ + (void)fprintf(fd, "Device Type : %02x ",tmpc); + mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n"); + + tmpc = mopGetChar(pkt,&index); /* Format Version */ + (void)fprintf(fd,"Format : %02x\n",tmpc); + + tmpc = mopGetChar(pkt,&index); /* Program Type */ + (void)fprintf(fd,"Program Type : %02x ",tmpc); + mopPrintPGTY(fd, tmpc); (void)fprintf(fd, "\n"); + + program[0] = 0; + tmpc = mopGetChar(pkt,&index); /* Software ID Len */ + for (i = 0; i < tmpc; i++) { + program[i] = mopGetChar(pkt,&index); + program[i+1] = '\0'; + } + + (void)fprintf(fd,"Software : %02x '%s'\n",tmpc,program); + + tmpc = mopGetChar(pkt,&index); /* Processor */ + (void)fprintf(fd,"Processor : %02x ",tmpc); + mopPrintBPTY(fd, tmpc); (void)fprintf(fd, "\n"); + + mopPrintInfo(fd, pkt, &index, moplen, code, trans); + + break; + case MOP_K_CODE_RML: + + tmpc = mopGetChar(pkt,&index); /* Load Number */ + (void)fprintf(fd,"Load Number : %02x\n",tmpc); + + tmpc = mopGetChar(pkt,&index); /* Error */ + (void)fprintf(fd,"Error : %02x (",tmpc); + if ((tmpc == 0)) { + (void)fprintf(fd,"no error)\n"); + } else { + (void)fprintf(fd,"error)\n"); + } + + break; + case MOP_K_CODE_RDS: + + tmpc = mopGetChar(pkt,&index); /* Device Type */ + (void)fprintf(fd, "Device Type : %02x ",tmpc); + mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n"); + + tmpc = mopGetChar(pkt,&index); /* Format Version */ + (void)fprintf(fd,"Format : %02x\n",tmpc); + + tmpl = mopGetLong(pkt,&index); /* Memory Size */ + (void)fprintf(fd,"Memory Size : %08x\n", tmpl); + + tmpc = mopGetChar(pkt,&index); /* Bits */ + (void)fprintf(fd,"Bits : %02x\n",tmpc); + + mopPrintInfo(fd, pkt, &index, moplen, code, trans); + + break; + case MOP_K_CODE_MDD: + + tmpl = mopGetLong(pkt,&index); /* Memory Address */ + (void)fprintf(fd,"Mem Address : %08x\n", tmpl); + + if (moplen > 5) { +#ifndef SHORT_PRINT + for (i = 0; i < (moplen - 5); i++) { + if ((i % 16) == 0) { + if ((i / 16) == 0) { + (void)fprintf(fd, + "Image Data : %04x ", + moplen-5); + } else { + (void)fprintf(fd, + " "); + } + } + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + if ((i % 16) == 15) + (void)fprintf(fd,"\n"); + } + if ((i % 16) != 15) + (void)fprintf(fd,"\n"); +#else + index = index + moplen - 5; +#endif + } + + break; + case MOP_K_CODE_PLT: + + tmpc = mopGetChar(pkt,&index); /* Load Number */ + (void)fprintf(fd,"Load Number : %02x\n",tmpc); + + tmpc = mopGetChar(pkt,&index); /* Parameter Type */ + while (tmpc != MOP_K_PLTP_END) { + c = mopGetChar(pkt,&index); /* Parameter Length */ + switch(tmpc) { + case MOP_K_PLTP_TSN: /* Target Name */ + (void)fprintf(fd,"Target Name : %02x '", + tmpc); + for (i = 0; i < ((int) c); i++) { + (void)fprintf(fd,"%c", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"'\n"); + break; + case MOP_K_PLTP_TSA: /* Target Address */ + (void)fprintf(fd,"Target Addr : %02x ",c); + for (i = 0; i < ((int) c); i++) { + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"\n"); + break; + case MOP_K_PLTP_HSN: /* Host Name */ + (void)fprintf(fd,"Host Name : %02x '", + tmpc); + for (i = 0; i < ((int) c); i++) { + (void)fprintf(fd,"%c", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"'\n"); + break; + case MOP_K_PLTP_HSA: /* Host Address */ + (void)fprintf(fd,"Host Addr : %02x ",c); + for (i = 0; i < ((int) c); i++) { + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"\n"); + break; + case MOP_K_PLTP_HST: /* Host Time */ + ucp = pkt + index; index = index + 10; + (void)fprintf(fd,"Host Time : "); + mopPrintTime(fd, ucp); + (void)fprintf(fd,"\n"); + break; + default: + break; + } + tmpc = mopGetChar(pkt,&index);/* Parameter Type */ + } + + tmpl = mopGetLong(pkt,&index); /* Transfer Address */ + (void)fprintf(fd,"Transfer Addr: %08x\n", tmpl); + + break; + default: + break; + } +} + + diff --git a/package/mopd/src/common/dl.h b/package/mopd/src/common/dl.h new file mode 100644 index 000000000..16a9e0e56 --- /dev/null +++ b/package/mopd/src/common/dl.h @@ -0,0 +1,42 @@ +/* $NetBSD: dl.h,v 1.2 1997/03/25 03:07:10 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: dl.h,v 1.2 1997/03/25 03:07:10 thorpej Exp $ + * + */ + +#ifndef _DL_H_ +#define _DL_H_ + +__BEGIN_DECLS +void mopDumpDL __P((FILE *, u_char *, int)); +__END_DECLS + +#endif _DL_H_ diff --git a/package/mopd/src/common/file.c b/package/mopd/src/common/file.c new file mode 100644 index 000000000..8d2ffcd94 --- /dev/null +++ b/package/mopd/src/common/file.c @@ -0,0 +1,820 @@ +/* $NetBSD: file.c,v 1.5 1998/02/07 00:03:22 cgd Exp $ */ + +/* + * Copyright (c) 1995-96 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: file.c,v 1.5 1998/02/07 00:03:22 cgd Exp $"; +#endif + +#include "os.h" +#include "common.h" +#include "file.h" +#include "mopdef.h" + +#ifndef NOAOUT +#if defined(__NetBSD__) || defined(__OpenBSD__) +#include +#endif +#if defined(__bsdi__) +#define NOAOUT +#endif +#if defined(__FreeBSD__) +#include +#endif +#if !defined(MID_VAX) +#define MID_VAX 140 +#endif +#if defined(__linux__) +#define NOAOUT +#include +#define MID_I386 100 +#define MID_SPARC 3 +#endif +#endif + +int getCLBYTES __P((int)); +int getMID __P((int, int)); + +void +mopFilePutLX(buf, index, value, cnt) + u_char *buf; + int index, cnt; + u_int32_t value; +{ + int i; + for (i = 0; i < cnt; i++) { + buf[index+i] = value % 256; + value = value / 256; + } +} + +void +mopFilePutBX(buf, index, value, cnt) + u_char *buf; + int index, cnt; + u_int32_t value; +{ + int i; + for (i = 0; i < cnt; i++) { + buf[index+cnt-1-i] = value % 256; + value = value / 256; + } +} + +u_int32_t +mopFileGetLX(buf, index, cnt) + u_char *buf; + int index, cnt; +{ + u_int32_t ret = 0; + int i; + + for (i = 0; i < cnt; i++) { + ret = ret*256 + buf[index+cnt-1-i]; + } + + return(ret); +} + +u_int32_t +mopFileGetBX(buf, index, cnt) + u_char *buf; + int index, cnt; +{ + u_int32_t ret = 0; + int i; + + for (i = 0; i < cnt; i++) { + ret = ret*256 + buf[index+i]; + } + + return(ret); +} + +void +mopFileSwapX(buf, index, cnt) + u_char *buf; + int index, cnt; +{ + int i; + u_char c; + + for (i = 0; i < (cnt / 2); i++) { + c = buf[index+i]; + buf[index+i] = buf[index+cnt-1-i]; + buf[index+cnt-1-i] = c; + } + +} + +int +CheckMopFile(fd) + int fd; +{ + u_char header[512]; + short image_type; + + if (read(fd, header, 512) != 512) + return(-1); + + (void)lseek(fd, (off_t) 0, SEEK_SET); + + image_type = (u_short)(header[IHD_W_ALIAS+1]*256 + + header[IHD_W_ALIAS]); + + switch(image_type) { + case IHD_C_NATIVE: /* Native mode image (VAX) */ + case IHD_C_RSX: /* RSX image produced by TKB */ + case IHD_C_BPA: /* BASIC plus analog */ + case IHD_C_ALIAS: /* Alias */ + case IHD_C_CLI: /* Image is CLI */ + case IHD_C_PMAX: /* PMAX system image */ + case IHD_C_ALPHA: /* ALPHA system image */ + break; + default: + return(-1); + } + + return(0); +} + +int +GetMopFileInfo(fd, load, xfr) + int fd; + u_int32_t *load, *xfr; +{ + u_char header[512]; + short image_type; + u_int32_t load_addr, xfr_addr, isd, iha, hbcnt, isize; + + if (read(fd, header, 512) != 512) + return(-1); + + image_type = (u_short)(header[IHD_W_ALIAS+1]*256 + + header[IHD_W_ALIAS]); + + switch(image_type) { + case IHD_C_NATIVE: /* Native mode image (VAX) */ + isd = (header[IHD_W_SIZE+1]*256 + + header[IHD_W_SIZE]); + iha = (header[IHD_W_ACTIVOFF+1]*256 + + header[IHD_W_ACTIVOFF]); + hbcnt = (header[IHD_B_HDRBLKCNT]); + isize = (header[isd+ISD_W_PAGCNT+1]*256 + + header[isd+ISD_W_PAGCNT]) * 512; + load_addr = ((header[isd+ISD_V_VPN+1]*256 + + header[isd+ISD_V_VPN]) & ISD_M_VPN) + * 512; + xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 + + header[iha+IHA_L_TFRADR1+2]*0x10000 + + header[iha+IHA_L_TFRADR1+1]*0x100 + + header[iha+IHA_L_TFRADR1]) & 0x7fffffff; + printf("Native Image (VAX)\n"); + printf("Header Block Count: %d\n",hbcnt); + printf("Image Size: %08x\n",isize); + printf("Load Address: %08x\n",load_addr); + printf("Transfer Address: %08x\n",xfr_addr); + break; + case IHD_C_RSX: /* RSX image produced by TKB */ + hbcnt = header[L_BBLK+1]*256 + header[L_BBLK]; + isize = (header[L_BLDZ+1]*256 + header[L_BLDZ]) * 64; + load_addr = header[L_BSA+1]*256 + header[L_BSA]; + xfr_addr = header[L_BXFR+1]*256 + header[L_BXFR]; + printf("RSX Image\n"); + printf("Header Block Count: %d\n",hbcnt); + printf("Image Size: %08x\n",isize); + printf("Load Address: %08x\n",load_addr); + printf("Transfer Address: %08x\n",xfr_addr); + break; + case IHD_C_BPA: /* BASIC plus analog */ + printf("BASIC-Plus Image, not supported\n"); + return(-1); + break; + case IHD_C_ALIAS: /* Alias */ + printf("Alias, not supported\n"); + return(-1); + break; + case IHD_C_CLI: /* Image is CLI */ + printf("CLI, not supported\n"); + return(-1); + break; + case IHD_C_PMAX: /* PMAX system image */ + isd = (header[IHD_W_SIZE+1]*256 + + header[IHD_W_SIZE]); + iha = (header[IHD_W_ACTIVOFF+1]*256 + + header[IHD_W_ACTIVOFF]); + hbcnt = (header[IHD_B_HDRBLKCNT]); + isize = (header[isd+ISD_W_PAGCNT+1]*256 + + header[isd+ISD_W_PAGCNT]) * 512; + load_addr = (header[isd+ISD_V_VPN+1]*256 + + header[isd+ISD_V_VPN]) * 512; + xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 + + header[iha+IHA_L_TFRADR1+2]*0x10000 + + header[iha+IHA_L_TFRADR1+1]*0x100 + + header[iha+IHA_L_TFRADR1]); + printf("PMAX Image \n"); + printf("Header Block Count: %d\n",hbcnt); + printf("Image Size: %08x\n",isize); + printf("Load Address: %08x\n",load_addr); + printf("Transfer Address: %08x\n",xfr_addr); + break; + case IHD_C_ALPHA: /* ALPHA system image */ + isd = (header[EIHD_L_ISDOFF+3]*0x1000000 + + header[EIHD_L_ISDOFF+2]*0x10000 + + header[EIHD_L_ISDOFF+1]*0x100 + + header[EIHD_L_ISDOFF]); + hbcnt = (header[EIHD_L_HDRBLKCNT+3]*0x1000000 + + header[EIHD_L_HDRBLKCNT+2]*0x10000 + + header[EIHD_L_HDRBLKCNT+1]*0x100 + + header[EIHD_L_HDRBLKCNT]); + isize = (header[isd+EISD_L_SECSIZE+3]*0x1000000 + + header[isd+EISD_L_SECSIZE+2]*0x10000 + + header[isd+EISD_L_SECSIZE+1]*0x100 + + header[isd+EISD_L_SECSIZE]); + load_addr = 0; + xfr_addr = 0; + printf("Alpha Image \n"); + printf("Header Block Count: %d\n",hbcnt); + printf("Image Size: %08x\n",isize); + printf("Load Address: %08x\n",load_addr); + printf("Transfer Address: %08x\n",xfr_addr); + break; + default: + printf("Unknown Image (%d)\n",image_type); + return(-1); + } + + if (load != NULL) { + *load = load_addr; + } + + if (xfr != NULL) { + *xfr = xfr_addr; + } + + return(0); +} + +#ifndef NOAOUT +int +getMID(old_mid,new_mid) + int old_mid, new_mid; +{ + int mid; + + mid = old_mid; + + switch (new_mid) { + case MID_I386: + mid = MID_I386; + break; +#ifdef MID_M68K + case MID_M68K: + mid = MID_M68K; + break; +#endif +#ifdef MID_M68K4K + case MID_M68K4K: + mid = MID_M68K4K; + break; +#endif +#ifdef MID_NS32532 + case MID_NS32532: + mid = MID_NS32532; + break; +#endif + case MID_SPARC: + mid = MID_SPARC; + break; +#ifdef MID_PMAX + case MID_PMAX: + mid = MID_PMAX; + break; +#endif +#ifdef MID_VAX + case MID_VAX: + mid = MID_VAX; + break; +#endif +#ifdef MID_ALPHA + case MID_ALPHA: + mid = MID_ALPHA; + break; +#endif +#ifdef MID_MIPS + case MID_MIPS: + mid = MID_MIPS; + break; +#endif +#ifdef MID_ARM6 + case MID_ARM6: + mid = MID_ARM6; + break; +#endif + default: + break; + } + + return(mid); +} + +int +getCLBYTES(mid) + int mid; +{ + int clbytes; + + switch (mid) { +#ifdef MID_VAX + case MID_VAX: + clbytes = 1024; + break; +#endif +#ifdef MID_I386 + case MID_I386: +#endif +#ifdef MID_M68K4K + case MID_M68K4K: +#endif +#ifdef MID_NS32532 + case MID_NS32532: +#endif +#ifdef MID_PMAX + case MID_PMAX: +#endif +#ifdef MID_MIPS + case MID_MIPS: +#endif +#ifdef MID_ARM6 + case MID_ARM6: +#endif +#if defined(MID_I386) || defined(MID_M68K4K) || defined(MID_NS32532) || \ + defined(MID_PMAX) || defined(MID_MIPS) || defined(MID_ARM6) + clbytes = 4096; + break; +#endif +#ifdef MID_M68K + case MID_M68K: +#endif +#ifdef MID_ALPHA + case MID_ALPHA: +#endif +#ifdef MID_SPARC + case MID_SPARC: +#endif +#if defined(MID_M68K) || defined(MID_ALPHA) || defined(MID_SPARC) + clbytes = 8192; + break; +#endif + default: + clbytes = 0; + } + + return(clbytes); +} +#endif + +int +CheckAOutFile(fd) + int fd; +{ +#ifdef NOAOUT + return(-1); +#else + struct exec ex, ex_swap; + int mid = -1; + + if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex)) + return(-1); + + (void)lseek(fd, (off_t) 0, SEEK_SET); + + if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap)) + return(-1); + + (void)lseek(fd, (off_t) 0, SEEK_SET); + + mid = getMID(mid, N_GETMID (ex)); + + if (mid == -1) { + mid = getMID(mid, N_GETMID (ex_swap)); + } + + if (mid != -1) { + return(0); + } else { + return(-1); + } +#endif NOAOUT +} + +int +GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill, + a_data, a_data_fill, a_bss, a_bss_fill, aout) + int fd; + u_int32_t *load, *xfr, *a_text, *a_text_fill; + u_int32_t *a_data, *a_data_fill, *a_bss, *a_bss_fill; + int *aout; +{ +#ifdef NOAOUT + return(-1); +#else + struct exec ex, ex_swap; + u_int32_t mid = -1; + u_int32_t magic, clbytes, clofset; + + if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex)) + return(-1); + + (void)lseek(fd, (off_t) 0, SEEK_SET); + + if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap)) + return(-1); + + mopFileSwapX((u_char *)&ex_swap, 0, 4); + + mid = getMID(mid, N_GETMID (ex)); + + if (mid == -1) { + mid = getMID(mid, N_GETMID (ex_swap)); + if (mid != -1) { + mopFileSwapX((u_char *)&ex, 0, 4); + } + } + + if (mid == -1) { + return(-1); + } + + if (N_BADMAG (ex)) { + return(-1); + } + + switch (mid) { + case MID_I386: +#ifdef MID_NS32532 + case MID_NS32532: +#endif +#ifdef MID_PMAX + case MID_PMAX: +#endif +#ifdef MID_VAX + case MID_VAX: +#endif +#ifdef MID_ALPHA + case MID_ALPHA: +#endif +#ifdef MID_ARM6 + case MID_ARM6: +#endif + ex.a_text = mopFileGetLX((u_char *)&ex_swap, 4, 4); + ex.a_data = mopFileGetLX((u_char *)&ex_swap, 8, 4); + ex.a_bss = mopFileGetLX((u_char *)&ex_swap, 12, 4); + ex.a_syms = mopFileGetLX((u_char *)&ex_swap, 16, 4); + ex.a_entry = mopFileGetLX((u_char *)&ex_swap, 20, 4); + ex.a_trsize= mopFileGetLX((u_char *)&ex_swap, 24, 4); + ex.a_drsize= mopFileGetLX((u_char *)&ex_swap, 28, 4); + break; +#ifdef MID_M68K + case MID_M68K: +#endif +#ifdef MID_M68K4K + case MID_M68K4K: +#endif + case MID_SPARC: +#ifdef MID_MIPS + case MID_MIPS: +#endif + ex.a_text = mopFileGetBX((u_char *)&ex_swap, 4, 4); + ex.a_data = mopFileGetBX((u_char *)&ex_swap, 8, 4); + ex.a_bss = mopFileGetBX((u_char *)&ex_swap, 12, 4); + ex.a_syms = mopFileGetBX((u_char *)&ex_swap, 16, 4); + ex.a_entry = mopFileGetBX((u_char *)&ex_swap, 20, 4); + ex.a_trsize= mopFileGetBX((u_char *)&ex_swap, 24, 4); + ex.a_drsize= mopFileGetBX((u_char *)&ex_swap, 28, 4); + break; + default: + break; + } + + printf("a.out image ("); + switch (N_GETMID (ex)) { + case MID_I386: + printf("i386"); + break; +#ifdef MID_M68K + case MID_M68K: + printf("m68k"); + break; +#endif +#ifdef MID_M68K4K + case MID_M68K4K: + printf("m68k 4k"); + break; +#endif +#ifdef MID_NS32532 + case MID_NS32532: + printf("pc532"); + break; +#endif + case MID_SPARC: + printf("sparc"); + break; +#ifdef MID_PMAX + case MID_PMAX: + printf("pmax"); + break; +#endif +#ifdef MID_VAX + case MID_VAX: + printf("vax"); + break; +#endif +#ifdef MID_ALPHA + case MID_ALPHA: + printf("alpha"); + break; +#endif +#ifdef MID_MIPS + case MID_MIPS: + printf("mips"); + break; +#endif +#ifdef MID_ARM6 + case MID_ARM6: + printf("arm32"); + break; +#endif + default: + break; + } + printf(") Magic: "); + switch (N_GETMAGIC (ex)) { + case OMAGIC: + printf("OMAGIC"); + break; + case NMAGIC: + printf("NMAGIC"); + break; + case ZMAGIC: + printf("ZMAGIC"); + break; + case QMAGIC: + printf("QMAGIC"); + break; + default: + printf("Unknown %ld", (long) N_GETMAGIC (ex)); + } + printf("\n"); + printf("Size of text: %08lx\n", (long)ex.a_text); + printf("Size of data: %08lx\n", (long)ex.a_data); + printf("Size of bss: %08lx\n", (long)ex.a_bss); + printf("Size of symbol tab: %08lx\n", (long)ex.a_syms); + printf("Transfer Address: %08lx\n", (long)ex.a_entry); + printf("Size of reloc text: %08lx\n", (long)ex.a_trsize); + printf("Size of reloc data: %08lx\n", (long)ex.a_drsize); + + magic = N_GETMAGIC (ex); + clbytes = getCLBYTES(mid); + clofset = clbytes - 1; + + if (load != NULL) { + *load = 0; + } + + if (xfr != NULL) { + *xfr = ex.a_entry; + } + + if (a_text != NULL) { + *a_text = ex.a_text; + } + + if (a_text_fill != NULL) { + if (magic == ZMAGIC || magic == NMAGIC) { + *a_text_fill = clbytes - (ex.a_text & clofset); + if (*a_text_fill == clbytes) { + *a_text_fill = 0; + } + } else { + *a_text_fill = 0; + } + } + + if (a_data != NULL) { + *a_data = ex.a_data; + } + + if (a_data_fill != NULL) { + if (magic == ZMAGIC || magic == NMAGIC) { + *a_data_fill = clbytes - (ex.a_data & clofset); + if (*a_data_fill == clbytes) { + *a_data_fill = 0; + } + } else { + *a_data_fill = 0; + } + } + + if (a_bss != NULL) { + *a_bss = ex.a_bss; + } + + if (a_bss_fill != NULL) { + if (magic == ZMAGIC || magic == NMAGIC) { + *a_bss_fill = clbytes - (ex.a_bss & clofset); + if (*a_bss_fill == clbytes) { + *a_bss_fill = 0; + } + } else { + *a_bss_fill = clbytes - + ((ex.a_text+ex.a_data+ex.a_bss) & clofset); + if (*a_text_fill == clbytes) { + *a_text_fill = 0; + } + } + } + + if (aout != NULL) { + *aout = mid; + } + + return(0); +#endif NOAOUT +} + +int +GetFileInfo(fd, load, xfr, aout, + a_text, a_text_fill, a_data, a_data_fill, a_bss, a_bss_fill) + int fd, *aout; + u_int32_t *load, *xfr, *a_text, *a_text_fill; + u_int32_t *a_data, *a_data_fill, *a_bss, *a_bss_fill; +{ + int err; + + err = CheckAOutFile(fd); + + if (err == 0) { + err = GetAOutFileInfo(fd, load, xfr, + a_text, a_text_fill, + a_data, a_data_fill, + a_bss, a_bss_fill, + aout); + if (err != 0) { + return(-1); + } + } else { + err = CheckMopFile(fd); + + if (err == 0) { + err = GetMopFileInfo(fd, load, xfr); + if (err != 0) { + return(-1); + } + *aout = -1; + } else { + return(-1); + } + } + + return(0); +} + +ssize_t +mopFileRead(dlslot, buf) + struct dllist *dlslot; + u_char *buf; +{ + ssize_t len, outlen; + int bsz; + int32_t pos, notdone, total; + + if (dlslot->aout == -1) { + len = read(dlslot->ldfd,buf,dlslot->dl_bsz); + } else { + bsz = dlslot->dl_bsz; + pos = dlslot->a_lseek; + len = 0; + + total = dlslot->a_text; + + if (pos < total) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = read(dlslot->ldfd,&buf[len],notdone); + } else { + outlen = read(dlslot->ldfd,&buf[len],bsz); + } + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_text_fill; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = notdone; + } else { + outlen = bsz; + } + memset(&buf[len], 0, outlen); + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_data; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = read(dlslot->ldfd,&buf[len],notdone); + } else { + outlen = read(dlslot->ldfd,&buf[len],bsz); + } + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_data_fill; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = notdone; + } else { + outlen = bsz; + } + memset(&buf[len], 0, outlen); + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_bss; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = notdone; + } else { + outlen = bsz; + } + memset(&buf[len], 0, outlen); + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_bss_fill; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = notdone; + } else { + outlen = bsz; + } + memset(&buf[len], 0, outlen); + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + dlslot->a_lseek = pos; + + } + + return(len); +} diff --git a/package/mopd/src/common/file.h b/package/mopd/src/common/file.h new file mode 100644 index 000000000..1f012f3a2 --- /dev/null +++ b/package/mopd/src/common/file.h @@ -0,0 +1,56 @@ +/* $NetBSD: file.h,v 1.2 1997/03/25 03:07:13 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: file.h,v 1.2 1997/03/25 03:07:13 thorpej Exp $ + * + */ + +#ifndef _FILE_H_ +#define _FILE_H_ + +__BEGIN_DECLS +void mopFilePutLX __P((u_char *, int, u_int32_t, int)); +void mopFilePutBX __P((u_char *, int, u_int32_t, int)); +u_int32_t mopFileGetLX __P((u_char *, int, int)); +u_int32_t mopFileGetBX __P((u_char *, int, int)); +ssize_t mopFileRead __P((struct dllist *, u_char *)); +void mopFileSwapX __P((u_char *, int, int)); +int CheckMopFile __P((int)); +int GetMopFileInfo __P((int, u_int32_t *, u_int32_t *)); +int CheckAOutFile __P((int)); +int GetAOutFileInfo __P((int, u_int32_t *, u_int32_t *, + u_int32_t *, u_int32_t *, u_int32_t *, u_int32_t *, + u_int32_t *, u_int32_t *, int *)); +int GetFileInfo __P((int, u_int32_t *, u_int32_t *, int *, + u_int32_t *, u_int32_t *, u_int32_t *, u_int32_t *, + u_int32_t *, u_int32_t *)); +__END_DECLS + +#endif /* _FILE_H_ */ diff --git a/package/mopd/src/common/get.c b/package/mopd/src/common/get.c new file mode 100644 index 000000000..995f20a44 --- /dev/null +++ b/package/mopd/src/common/get.c @@ -0,0 +1,152 @@ +/* $NetBSD: get.c,v 1.2 1997/03/25 03:07:15 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: get.c,v 1.2 1997/03/25 03:07:15 thorpej Exp $"; +#endif + +#include "os.h" +#include "get.h" +#include "mopdef.h" + +u_char +mopGetChar(pkt, index) + u_char *pkt; + int *index; +{ + u_char ret; + + ret = pkt[*index]; + *index = *index + 1; + return(ret); +} + +u_short +mopGetShort(pkt, index) + u_char *pkt; + int *index; +{ + u_short ret; + + ret = pkt[*index] + pkt[*index+1]*256; + *index = *index + 2; + return(ret); +} + +u_int32_t +mopGetLong(pkt, index) + u_char *pkt; + int *index; +{ + u_int32_t ret; + + ret = pkt[*index] + + pkt[*index+1]*0x100 + + pkt[*index+2]*0x10000 + + pkt[*index+3]*0x1000000; + *index = *index + 4; + return(ret); +} + +void +mopGetMulti(pkt, index, dest, size) + u_char *pkt,*dest; + int *index,size; +{ + int i; + + for (i = 0; i < size; i++) { + dest[i] = pkt[*index+i]; + } + *index = *index + size; + +} + +int +mopGetTrans(pkt, trans) + u_char *pkt; + int trans; +{ + u_short *ptype; + + if (trans == 0) { + ptype = (u_short *)(pkt+12); + if (ntohs(*ptype) < 1600) { + trans = TRANS_8023; + } else { + trans = TRANS_ETHER; + } + } + return(trans); +} + +void +mopGetHeader(pkt, index, dst, src, proto, len, trans) + u_char *pkt, **dst, **src; + int *index, *len, trans; + u_short *proto; +{ + *dst = pkt; + *src = pkt + 6; + *index = *index + 12; + + switch(trans) { + case TRANS_ETHER: + *proto = (u_short)(pkt[*index]*256 + pkt[*index+1]); + *index = *index + 2; + *len = (int)(pkt[*index+1]*256 + pkt[*index]); + *index = *index + 2; + break; + case TRANS_8023: + *len = (int)(pkt[*index]*256 + pkt[*index+1]); + *index = *index + 8; + *proto = (u_short)(pkt[*index]*256 + pkt[*index+1]); + *index = *index + 2; + break; + } +} + +u_short +mopGetLength(pkt, trans) + u_char *pkt; + int trans; +{ + switch(trans) { + case TRANS_ETHER: + return(pkt[15]*256 + pkt[14]); + break; + case TRANS_8023: + return(pkt[12]*256 + pkt[13]); + break; + } + return(0); +} diff --git a/package/mopd/src/common/get.h b/package/mopd/src/common/get.h new file mode 100644 index 000000000..54ec18dbe --- /dev/null +++ b/package/mopd/src/common/get.h @@ -0,0 +1,49 @@ +/* $NetBSD: get.h,v 1.2 1997/03/25 03:07:16 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: get.h,v 1.2 1997/03/25 03:07:16 thorpej Exp $ + * + */ + +#ifndef _GET_H_ +#define _GET_H_ + +__BEGIN_DECLS +u_char mopGetChar __P((u_char *, int *)); +u_short mopGetShort __P((u_char *, int *)); +u_int32_t mopGetLong __P((u_char *, int *)); +void mopGetMulti __P((u_char *, int *, u_char *, int)); +int mopGetTrans __P((u_char *, int)); +void mopGetHeader __P((u_char *, int *, u_char **, u_char **, + u_short *, int *, int)); +u_short mopGetLength __P((u_char *, int)); +__END_DECLS + +#endif /* _GET_H_ */ diff --git a/package/mopd/src/common/loop-bsd.c b/package/mopd/src/common/loop-bsd.c new file mode 100644 index 000000000..a4cbee6b4 --- /dev/null +++ b/package/mopd/src/common/loop-bsd.c @@ -0,0 +1,183 @@ +/* $NetBSD: loop-bsd.c,v 1.4 1998/02/03 04:51:29 perry Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: loop-bsd.c,v 1.4 1998/02/03 04:51:29 perry Exp $"); +#endif + +#include +#include +#include +#include +#if defined(__bsdi__) || defined(__FreeBSD__) || defined(__NetBSD__) +#include +#endif +#include +#include + +#include "os.h" +#include "common.h" +#include "device.h" +#include "mopdef.h" + +int +mopOpenRC(p, trans) + struct if_info *p; + int trans; +{ +#ifndef NORC + return (*(p->iopen))(p->if_name, + O_RDWR, + MOP_K_PROTO_RC, + trans); +#else + return -1; +#endif +} + +int +mopOpenDL(p, trans) + struct if_info *p; + int trans; +{ +#ifndef NODL + return (*(p->iopen))(p->if_name, + O_RDWR, + MOP_K_PROTO_DL, + trans); +#else + return -1; +#endif +} + +void +mopReadRC() +{ +} + +void +mopReadDL() +{ +} + +/* + * The list of all interfaces that are being listened to. loop() + * "selects" on the descriptors in this list. + */ +struct if_info *iflist; + +void mopProcess __P((struct if_info *, u_char *)); + +/* + * Loop indefinitely listening for MOP requests on the + * interfaces in 'iflist'. + */ +void +Loop() +{ + u_char *buf, *bp, *ep; + int cc; + fd_set fds, listeners; + int bufsize, maxfd = 0; + struct if_info *ii; + + if (iflist == 0) { + syslog(LOG_ERR, "no interfaces"); + exit(0); + } + if (iflist->fd != -1) { + if (ioctl(iflist->fd, BIOCGBLEN, (caddr_t) & bufsize) < 0) { + syslog(LOG_ERR, "BIOCGBLEN: %m"); + exit(0); + } + } + buf = (u_char *) malloc((unsigned) bufsize); + if (buf == 0) { + syslog(LOG_ERR, "malloc: %m"); + exit(0); + } + /* + * Find the highest numbered file descriptor for select(). + * Initialize the set of descriptors to listen to. + */ + FD_ZERO(&fds); + for (ii = iflist; ii; ii = ii->next) { + if (ii->fd != -1) { + FD_SET(ii->fd, &fds); + if (ii->fd > maxfd) + maxfd = ii->fd; + } + } + while (1) { + listeners = fds; + if (select(maxfd + 1, &listeners, (struct fd_set *) 0, + (struct fd_set *) 0, (struct timeval *) 0) < 0) { + syslog(LOG_ERR, "select: %m"); + exit(0); + } + for (ii = iflist; ii; ii = ii->next) { + if (ii->fd != -1) { + if (!FD_ISSET(ii->fd, &listeners)) + continue; + } + again: + cc = read(ii->fd, (char *) buf, bufsize); + /* Don't choke when we get ptraced */ + if (cc < 0 && errno == EINTR) + goto again; + /* Due to a SunOS bug, after 2^31 bytes, the file + * offset overflows and read fails with EINVAL. The + * lseek() to 0 will fix things. */ + if (cc < 0) { + if (errno == EINVAL && + (lseek(ii->fd, 0, SEEK_CUR) + bufsize) < 0) { + (void) lseek(ii->fd, 0, 0); + goto again; + } + syslog(LOG_ERR, "read: %m"); + exit(0); + } + /* Loop through the packet(s) */ +#define bhp ((struct bpf_hdr *)bp) + bp = buf; + ep = bp + cc; + while (bp < ep) { + int caplen, hdrlen; + + caplen = bhp->bh_caplen; + hdrlen = bhp->bh_hdrlen; + mopProcess(ii, bp + hdrlen); + bp += BPF_WORDALIGN(hdrlen + caplen); + } + } + } +} diff --git a/package/mopd/src/common/loop-linux2.c b/package/mopd/src/common/loop-linux2.c new file mode 100644 index 000000000..04654510c --- /dev/null +++ b/package/mopd/src/common/loop-linux2.c @@ -0,0 +1,162 @@ +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LINT +static char rcsid[] = "$Id: loop-linux2.c,v 1.1.1.1 2001/06/24 19:33:53 atp Exp $"; +#endif + +#include +#include +#include +#if defined(__bsdi__) || defined(__FreeBSD__) +#include +#endif +#include +#include + +#include "os.h" +#include "common.h" +#include "mopdef.h" + +int +mopOpenRC(p, trans) + struct if_info *p; + int trans; +{ +#ifndef NORC + return (*(p->iopen))(p->if_name, + O_RDWR, + MOP_K_PROTO_RC, + trans); +#else + return -1; +#endif +} + +int +mopOpenDL(p, trans) + struct if_info *p; + int trans; +{ +#ifndef NODL + return (*(p->iopen))(p->if_name, + O_RDWR, + MOP_K_PROTO_DL, + trans); +#else + return -1; +#endif +} + +void +mopReadRC() +{ +} + +void +mopReadDL() +{ +} + +/* + * The list of all interfaces that are being listened to. loop() + * "selects" on the descriptors in this list. + */ +struct if_info *iflist; + +void mopProcess __P((struct if_info *, u_char *)); + +/* + * Loop indefinitely listening for MOP requests on the + * interfaces in 'iflist'. + */ +void +Loop() +{ + u_char *buf, *bp, *ep; + int cc; + fd_set fds, listeners; + int bufsize = 1100, maxfd =0; + struct if_info *ii; + + + if (iflist == 0) { + syslog(LOG_ERR, "no interfaces"); + exit(0); + } + + buf = (u_char *) malloc((unsigned) bufsize); + + if (buf == 0) { + syslog(LOG_ERR, "malloc: %m"); + exit(0); + } + /* + * Find the highest numbered file descriptor for select(). + * Initialize the set of descriptors to listen to. + */ + FD_ZERO(&fds); + for (ii = iflist; ii; ii = ii->next) { + if (ii->fd != -1) { + FD_SET(ii->fd, &fds); + if (ii->fd > maxfd) + maxfd = ii->fd; + } + } + while (1) { + listeners = fds; + if (select(maxfd + 1, &listeners, (fd_set *) 0, + (fd_set *) 0, (struct timeval *) 0) < 0) { + syslog(LOG_ERR, "select: %m"); + exit(0); + } + for (ii = iflist; ii; ii = ii->next) { + if (ii->fd != -1) { + if (!FD_ISSET(ii->fd, &listeners)) + continue; + } + again: + cc = read(ii->fd, (char *) buf, bufsize); + /* Don't choke when we get ptraced */ + if (cc < 0 && errno == EINTR) + goto again; + + bp = buf; + ep = bp + cc; + +if(bp < ep) + { + mopProcess(ii,buf); + } + +} + +} +} + diff --git a/package/mopd/src/common/mopdef.c b/package/mopd/src/common/mopdef.c new file mode 100644 index 000000000..87423fc51 --- /dev/null +++ b/package/mopd/src/common/mopdef.c @@ -0,0 +1,54 @@ +/* $NetBSD: mopdef.c,v 1.2 1997/03/25 03:07:19 thorpej Exp $ */ + +/* + * Copyright (c) 1995 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: mopdef.c,v 1.2 1997/03/25 03:07:19 thorpej Exp $"; +#endif + +#define MOPDEF_SURPESS_EXTERN +#include "mopdef.h" + +char dl_mcst[6] = MOP_DL_MULTICAST; /* Dump/Load Multicast */ +char rc_mcst[6] = MOP_RC_MULTICAST; /* Remote Console Multicast */ +char dl_802_proto[5] = MOP_K_PROTO_802_DL; /* MOP Dump/Load 802.2 */ +char rc_802_proto[5] = MOP_K_PROTO_802_RC; /* MOP Remote Console 802.2 */ +char lp_802_proto[5] = MOP_K_PROTO_802_LP; /* Loopback 802.2 */ + +#if 0 +int +mopdef_dummy() +{ + /* Just to keep them as variables */ + return(dl_mcst[0]-rc_mcst[0]- + lp_802_proto[1]-rc_802_proto[1]-lp_802_proto[1]); +} +#endif diff --git a/package/mopd/src/common/mopdef.h b/package/mopd/src/common/mopdef.h new file mode 100644 index 000000000..34a3f7ae8 --- /dev/null +++ b/package/mopd/src/common/mopdef.h @@ -0,0 +1,198 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: mopdef.h,v 1.1.1.1 1997/03/16 22:23:36 cjs Exp $ + * + */ + +#ifndef _MOPDEF_H_ +#define _MOPDEF_H_ + +#define MOP_K_PROTO_DL 0x6001 /* MOP Load/Dump Protocol */ +#define MOP_K_PROTO_RC 0x6002 /* MOP Remote Console Protocol */ +#define MOP_K_PROTO_LP 0x9000 /* MOP Loopback Protocol */ + +#define MOP_K_PROTO_802_DL { 0x08, 0x00, 0x2b, 0x60, 0x01 } +#define MOP_K_PROTO_802_RC { 0x08, 0x00, 0x2b, 0x60, 0x02 } +#define MOP_K_PROTO_802_LP { 0x08, 0x00, 0x2b, 0x90, 0x00 } + +#define MOP_K_PROTO_802_DSAP 0xaa +#define MOP_K_PROTO_802_SSAP 0xaa +#define MOP_K_PROTO_802_CNTL 0x03 + +#define TRANS_ETHER 1 /* Packet in Ethernet format */ +#define TRANS_8023 2 /* Packet in 802.3 format */ +#define TRANS_AND 0x1000 /* Both Ethernet and 802.3 */ + +/* The following constants are defined in module MOPDEF.SDL in MOM */ + +#define MOP_K_CODE_MIN 0 +#define MOP_K_CODE_MLT 0 /* Memory Load with transfer address */ +#define MOP_K_CODE_DCM 1 /* Dump Complete */ +#define MOP_K_CODE_MLD 2 /* Memory Load */ +#define MOP_K_CODE_ASV 3 /* Assistance volunteer (NI only */ +#define MOP_K_CODE_RMD 4 /* Request memory dump */ +#define MOP_K_CODE_RID 5 /* Request ID */ +#define MOP_K_CODE_BOT 6 /* Boot */ +#define MOP_K_CODE_SID 7 /* System ID */ +#define MOP_K_CODE_RPR 8 /* Request program */ +#define MOP_K_CODE_RQC 9 /* Request Counters */ +#define MOP_K_CODE_RML 10 /* Request memory load */ +#define MOP_K_CODE_CNT 11 /* Counters */ +#define MOP_K_CODE_RDS 12 /* Request Dump Service */ +#define MOP_K_CODE_MMR 12 /* MOP Mode Running */ +#define MOP_K_CODE_RVC 13 /* Reserve Console */ +#define MOP_K_CODE_MDD 14 /* Memory dump data */ +#define MOP_K_CODE_RLC 15 /* Release Console */ +#define MOP_K_CODE_CCP 17 /* Console Command and Poll */ +#define MOP_K_CODE_CRA 19 /* Console Response and Acknnowledge */ +#define MOP_K_CODE_PLT 20 /* Parameter load with transfer address*/ +#define MOP_K_CODE_ALD 24 /* Active loop data */ +#define MOP_K_CODE_PLD 26 /* Passive looped data */ +#define MOP_K_CODE_MAX 26 + +#define MOP_K_PGTY_MIN 0 +#define MOP_K_PGTY_SECLDR 0 /* Secondary Loader */ +#define MOP_K_PGTY_TERLDR 1 /* Tertiary Loader */ +#define MOP_K_PGTY_OPRSYS 2 /* Operating System */ +#define MOP_K_PGTY_MGNTFL 3 /* Management File */ +#define MOP_K_PGTY_MAX 3 + +#define MOP_K_BPTY_MIN 0 +#define MOP_K_BPTY_SYS 0 /* System Processor */ +#define MOP_K_BPTY_COM 1 /* Communication Processor */ +#define MOP_K_BPTY_MAX 1 + +#define MOP_K_RML_ERROR_MIN 0 +#define MOP_K_RML_ERROR_NONE 0 /* None */ +#define MOP_K_RML_ERROR_NO_LOAD 1 /* Image data not properly loaded */ +#define MOP_K_RML_ERROR_MAX 1 + +#define MOP_K_PLTP_MIN 0 +#define MOP_K_PLTP_END 0 /* End Mark */ +#define MOP_K_PLTP_TSN 1 /* Target System Name */ +#define MOP_K_PLTP_TSA 2 /* Target System Address */ +#define MOP_K_PLTP_HSN 3 /* Host System Name */ +#define MOP_K_PLTP_HSA 4 /* Host System Address */ +#define MOP_K_PLTP_HST 5 /* Host System Time */ +#define MOP_K_PLTP_MAX 5 + +#define MOP_K_BOT_CNTL_MIN 0 +#define MOP_K_BOT_CNTL_SERVER 0 /* Boot-Server */ +#define MOP_K_BOT_CNTL_DEVICE 1 /* Boot-Device */ +#define MOP_K_BOT_CNTL_MAX 1 + +#define MOP_K_INFO_VER 1 /* Maintenance Version */ +#define MOP_K_INFO_MFCT 2 /* Maintenance Functions */ +#define MOP_K_INFO_CNU 3 /* Console User */ +#define MOP_K_INFO_RTM 4 /* Reservation Timer */ +#define MOP_K_INFO_CSZ 5 /* Console Command Size */ +#define MOP_K_INFO_RSZ 6 /* Console Response Size */ +#define MOP_K_INFO_HWA 7 /* Hardware Address */ +#define MOP_K_INFO_TIME 8 /* System Time */ +#define MOP_K_INFO_SOFD 100 /* Communication Device */ +#define MOP_K_INFO_SFID 200 /* Software ID */ +#define MOP_K_INFO_PRTY 300 /* System Processor */ +#define MOP_K_INFO_DLTY 400 /* Data Link Type */ +#define MOP_K_INFO_DLBSZ 401 /* Data Link Buffer Size */ + +#define MOP_K_DLTY_MIN 1 +#define MOP_K_DLTY_NI 1 /* Ethernet */ +#define MOP_K_DLTY_DDCMP 2 /* DDCMP */ +#define MOP_K_DLTY_LAPB 3 /* LAPB (frame level of X.25) */ +#define MOP_K_DLTY_MAX 3 + +#define MOP_K_PRTY_MIN 0 +#define MOP_K_PRTY_11 1 /* PDP-11 (UNIBUS) */ +#define MOP_K_PRTY_CMSV 2 /* Communication Server */ +#define MOP_K_PRTY_PRO 3 /* Professional */ +#define MOP_K_PRTY_SCO 4 /* Scorpio */ +#define MOP_K_PRTY_AMB 5 /* Amber */ +#define MOP_K_PRTY_BRI 6 /* XLII Bridge */ +#define MOP_K_PRTY_MAX 6 + +#define MOP_K_SFID_FORM_MIN -2 +#define MOP_K_SFID_FORM_MAINT -2 /* Maintenance System */ +#define MOP_K_SFID_FORM_OPRSYS -1 /* Standard Operating System */ +#define MOP_K_SFID_FORM_NONE 0 /* None */ +#define MOP_K_SFID_FORM_MAX 0 + +#define MOP_K_SFID_CUST 'CP' /* Customer product */ +#define MOP_K_SFID_DEC 'DP' /* DEC product */ +#define MOP_K_SFID_DELIM_ID '#' /* Delimiter identifier */ + +#define MOP_K_DLBSZ_DEFAULT 262 /* Buffersize */ + +#define MOP_K_NILOOP_REPLY 1 /* Response */ +#define MOP_K_NILOOP_FORWARD 2 /* Forward Data */ + +#define MOP_DL_MULTICAST { 0xab, 0x00, 0x00, 0x01, 0x00, 0x00 } +#define MOP_RC_MULTICAST { 0xab, 0x00, 0x00, 0x02, 0x00, 0x00 } +#define MOP_LP_MULTICAST { 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00 } + +#define MOP_K_RPR_FORMAT_V3 1 /* Format Version of RPR */ +#define MOP_K_RPR_FORMAT 4 /* Format Version of RPR */ + +#define IHD_C_MINCODE -1 /* Low bound of ALIAS value */ +#define IHD_C_NATIVE -1 /* Native mode image */ +#define IHD_C_RSX 0 /* RSX image produced by TKB */ +#define IHD_C_BPA 1 /* BASIC plus analog */ +#define IHD_C_ALIAS 2 /* Last 126 bytes contains ASCIC of image to activate */ +#define IHD_C_CLI 3 /* Image is CLI, run LOGINOUT */ +#define IHD_C_PMAX 4 /* PMAX system image */ +#define IHD_C_ALPHA 5 /* ALPHA system image */ +#define IHD_C_MAXCODE 5 /* High bound of ALIAS value */ + +#define IHD_W_SIZE 0 +#define IHD_W_ACTIVOFF 2 +#define IHD_B_HDRBLKCNT 16 +#define IHD_W_ALIAS 510 +#define ISD_W_PAGCNT 2 +#define ISD_V_VPN 4 +#define ISD_M_VPN 0x1fffff +#define IHA_L_TFRADR1 0 +#define EISD_L_SECSIZE 12 +#define EIHD_L_ISDOFF 12 +#define EIHD_L_HDRBLKCNT 76 + +#define L_BSA 0x08 /* RSX base address */ +#define L_BLDZ 0x0e /* RSX image size (* 64) */ +#define L_BXFR 0xe8 /* RSX transfer address */ +#define L_BBLK 0xf0 /* RSX header block count */ + +#ifndef MOPDEF_SUPRESS_EXTERN +extern char dl_mcst[]; +extern char rc_mcst[]; +extern char dl_802_proto[]; +extern char rc_802_proto[]; +extern char lp_802_proto[]; +#endif MOPDEF_SUPRESS_EXTERN + +#endif _MOPDEF_H_ diff --git a/package/mopd/src/common/nma.c b/package/mopd/src/common/nma.c new file mode 100644 index 000000000..a992f5a32 --- /dev/null +++ b/package/mopd/src/common/nma.c @@ -0,0 +1,227 @@ +/* $NetBSD: nma.c,v 1.2 1997/03/25 03:07:22 thorpej Exp $ */ + +/* + * Copyright (c) 1995 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: nma.c,v 1.2 1997/03/25 03:07:22 thorpej Exp $"; +#endif + +#include "os.h" +#include "nma.h" +#include "nmadef.h" + +struct commDev { + int val; + char *sname; + char *name; +}; + +struct commDev nmaCommDev[] = { + { NMA_C_SOFD_DP , "DP ", "DP11-DA" }, + { NMA_C_SOFD_UNA, "UNA", "DEUNA" }, + { NMA_C_SOFD_DU , "DU ", "DU11-DA" }, + { NMA_C_SOFD_CNA, "CNA", "DECNA" }, + { NMA_C_SOFD_DL , "DL ", "DL11-C, -E, or -WA" }, + { NMA_C_SOFD_QNA, "QNA", "DEQNA" }, + { NMA_C_SOFD_DQ , "DQ ", "DQ11-DA" }, + { NMA_C_SOFD_CI , "CI ", "Computer Interconnect" }, + { NMA_C_SOFD_DA , "DA ", "DA11-B or -AL" }, + { NMA_C_SOFD_PCL, "PCL", "PCL11-B" }, + { NMA_C_SOFD_DUP, "DUP", "DUP11-DA" }, + { NMA_C_SOFD_LUA, "LUA", "DELUA" }, + { NMA_C_SOFD_DMC, "DMC", "DMC11-DA/AR, -FA/AR, -MA/AL or -MD/AL" }, + { NMA_C_SOFD_LNA, "LNA", "MicroServer Lance" }, + { NMA_C_SOFD_DN , "DN ", "DN11-BA or -AA" }, + { NMA_C_SOFD_DLV, "DLV", "DLV11-E, -F, -J, MXV11-A or -B" }, + { NMA_C_SOFD_LCS, "LCS", "DECServer 100" }, + { NMA_C_SOFD_DMP, "DMP", "DMP11" }, + { NMA_C_SOFD_AMB, "AMB", "AMBER" }, + { NMA_C_SOFD_DTE, "DTE", "DTE20" }, + { NMA_C_SOFD_DBT, "DBT", "DEBET" }, + { NMA_C_SOFD_DV , "DV ", "DV11-AA/BA" }, + { NMA_C_SOFD_BNA, "BNA", "DEBNA" }, + { NMA_C_SOFD_BNT, "BNT", "DEBNT" }, + { NMA_C_SOFD_DZ , "DZ ", "DZ11-A, -B, -C, -D" }, + { NMA_C_SOFD_LPC, "LPC", "PCXX" }, + { NMA_C_SOFD_DSV, "DSV", "DSV11" }, + { NMA_C_SOFD_CEC, "CEC", "3-COM/IBM-PC" }, + { NMA_C_SOFD_KDP, "KDP", "KMC11/DUP11-DA" }, + { NMA_C_SOFD_IEC, "IEC", "Interlan/IBM-PC" }, + { NMA_C_SOFD_KDZ, "KDZ", "KMC11/DZ11-A, -B, -C, or -D" }, + { NMA_C_SOFD_UEC, "UEC", "Univation/RAINBOW-100" }, + { NMA_C_SOFD_KL8, "KL8", "KL8-J" }, + { NMA_C_SOFD_DS2, "DS2", "DECServer 200" }, + { NMA_C_SOFD_DMV, "DMV", "DMV11" }, + { NMA_C_SOFD_DS5, "DS5", "DECServer 500" }, + { NMA_C_SOFD_DPV, "DPV", "DPV11" }, + { NMA_C_SOFD_LQA, "LQA", "DELQA" }, + { NMA_C_SOFD_DMF, "DMF", "DMF32" }, + { NMA_C_SOFD_SVA, "SVA", "DESVA" }, + { NMA_C_SOFD_DMR, "DMR", "DMR11-AA, -AB, -AC, or -AE" }, + { NMA_C_SOFD_MUX, "MUX", "MUXserver" }, + { NMA_C_SOFD_KMY, "KMY", "KMS11-PX" }, + { NMA_C_SOFD_DEP, "DEP", "DEPCA PCSG/IBM-PC" }, + { NMA_C_SOFD_KMX, "KMX", "KMS11-BD/BE" }, + { NMA_C_SOFD_LTM, "LTM", "LTM Ethernet monitor" }, + { NMA_C_SOFD_DMB, "DMB", "DMB-32" }, + { NMA_C_SOFD_DES, "DES", "DESNC" }, + { NMA_C_SOFD_KCP, "KCP", "KCP" }, + { NMA_C_SOFD_MX3, "MX3", "MUXServer 300" }, + { NMA_C_SOFD_SYN, "SYN", "MicroServer" }, + { NMA_C_SOFD_MEB, "MEB", "DEMEB" }, + { NMA_C_SOFD_DSB, "DSB", "DSB32" }, + { NMA_C_SOFD_BAM, "BAM", "DEBAM LANBridge-200" }, + { NMA_C_SOFD_DST, "DST", "DST-32 TEAMmate" }, + { NMA_C_SOFD_FAT, "FAT", "DEFAT" }, + { NMA_C_SOFD_RSM, "RSM", "DERSM - Remote Segment Monitor" }, + { NMA_C_SOFD_RES, "RES", "DERES - Remote Environmental Sensor" }, + { NMA_C_SOFD_3C2, "3C2", "3COM Etherlink II (3C503)" }, + { NMA_C_SOFD_3CM, "3CM", "3COM Etherlink/MC (3C523)" }, + { NMA_C_SOFD_DS3, "DS3", "DECServer 300" }, + { NMA_C_SOFD_MF2, "MF2", "Mayfair-2" }, + { NMA_C_SOFD_MMR, "MMR", "DEMMR" }, + { NMA_C_SOFD_VIT, "VIT", "Vitalink TransLAN III/IV (NP3A) Bridge " }, + { NMA_C_SOFD_VT5, "VT5", "Vitalink TransLAN 350 (NPC25) Bridge " }, + { NMA_C_SOFD_BNI, "BNI", "DEBNI" }, + { NMA_C_SOFD_MNA, "MNA", "DEMNA" }, + { NMA_C_SOFD_PMX, "PMX", "PMAX (KN01)" }, + { NMA_C_SOFD_NI5, "NI5", "Interlan NI5210-8" }, + { NMA_C_SOFD_NI9, "NI9", "Interlan NI9210" }, + { NMA_C_SOFD_KMK, "KMK", "KMS11-K" }, + { NMA_C_SOFD_3CP, "3CP", "3COM Etherlink Plus (3C505) " }, + { NMA_C_SOFD_DP2, "DP2", "DPNserver-200" }, + { NMA_C_SOFD_ISA, "ISA", "SGEC" }, + { NMA_C_SOFD_DIV, "DIV", "DIV-32 DEC WAN controller-100" }, + { NMA_C_SOFD_QTA, "QTA", "DEQTA" }, + { NMA_C_SOFD_B15, "B15", "LANbridge-150" }, + { NMA_C_SOFD_WD8, "WD8", "WD8003 Family" }, + { NMA_C_SOFD_ILA, "ILA", "BICC ISOLAN 4110-2" }, + { NMA_C_SOFD_ILM, "ILM", "BICC ISOLAN 4110-3" }, + { NMA_C_SOFD_APR, "APR", "Apricot Xen-S and Qi" }, + { NMA_C_SOFD_ASN, "ASN", "AST EtherNode" }, + { NMA_C_SOFD_ASE, "ASE", "AST Ethernet" }, + { NMA_C_SOFD_TRW, "TRW", "TRW HC-2001" }, + { NMA_C_SOFD_EDX, "EDX", "Ethernet-XT/AT" }, + { NMA_C_SOFD_EDA, "EDA", "Ethernet-AT" }, + { NMA_C_SOFD_DR2, "DR2", "DECrouter-250" }, + { NMA_C_SOFD_SCC, "SCC", "DECrouter-250 DUSCC" }, + { NMA_C_SOFD_DCA, "DCA", "DCA Series 300" }, + { NMA_C_SOFD_TIA, "TIA", "LANcard/E" }, + { NMA_C_SOFD_FBN, "FBN", "DEFEB DECbridge-500" }, + { NMA_C_SOFD_FEB, "FEB", "DEFEB DECbridge-500 FDDI" }, + { NMA_C_SOFD_FCN, "FCN", "DEFCN DECconcentrator-500" }, + { NMA_C_SOFD_MFA, "MFA", "DEMFA" }, + { NMA_C_SOFD_MXE, "MXE", "MIPS workstation family" }, + { NMA_C_SOFD_CED, "CED", "Cabletron Ethernet Desktop" }, + { NMA_C_SOFD_C20, "C20", "3Com CS/200" }, + { NMA_C_SOFD_CS1, "CS1", "3Com CS/1" }, + { NMA_C_SOFD_C2M, "C2M", "3Com CS/210, CS/2000, CS/2100" }, + { NMA_C_SOFD_ACA, "ACA", "ACA/32000 system" }, + { NMA_C_SOFD_GSM, "GSM", "Gandalf StarMaster" }, + { NMA_C_SOFD_DSF, "DSF", "DSF32" }, + { NMA_C_SOFD_CS5, "CS5", "3Com CS/50" }, + { NMA_C_SOFD_XIR, "XIR", "XIRCOM PE10B2" }, + { NMA_C_SOFD_KFE, "KFE", "KFE52" }, + { NMA_C_SOFD_RT3, "RT3", "rtVAX-300" }, + { NMA_C_SOFD_SPI, "SPI", "Spiderport M250" }, + { NMA_C_SOFD_FOR, "FOR", "LAT gateway" }, + { NMA_C_SOFD_MER, "MER", "Meridian" }, + { NMA_C_SOFD_PER, "PER", "Persoft" }, + { NMA_C_SOFD_STR, "STR", "AT&T StarLan-10" }, + { NMA_C_SOFD_MPS, "MPS", "MIPSfair" }, + { NMA_C_SOFD_L20, "L20", "LPS20 print server" }, + { NMA_C_SOFD_VT2, "VT2", "Vitalink TransLAN 320 Bridge" }, + { NMA_C_SOFD_DWT, "DWT", "VT-1000" }, + { NMA_C_SOFD_WGB, "WGB", "DEWGB" }, + { NMA_C_SOFD_ZEN, "ZEN", "Zenith Z-LAN4000, Z-LAN" }, + { NMA_C_SOFD_TSS, "TSS", "Thursby Software Systems" }, + { NMA_C_SOFD_MNE, "MNE", "3MIN (KN02-BA)" }, + { NMA_C_SOFD_FZA, "FZA", "DEFZA" }, + { NMA_C_SOFD_90L, "90L", "DS90L" }, + { NMA_C_SOFD_CIS, "CIS", "Cisco Systems" }, + { NMA_C_SOFD_STC, "STC", "STRTC" }, + { NMA_C_SOFD_UBE, "UBE", "Ungermann-Bass PC2030, PC3030" }, + { NMA_C_SOFD_DW2, "DW2", "DECwindows terminal II" }, + { NMA_C_SOFD_FUE, "FUE", "Fujitsu Etherstar MB86950" }, + { NMA_C_SOFD_M38, "M38", "MUXServer 380" }, + { NMA_C_SOFD_NTI, "NTI", "NTI Group PC Ethernet Card" }, + { NMA_C_SOFD_RAD, "RAD", "RADLINX LAN Gateway" }, + { NMA_C_SOFD_INF, "INF", "Infotron Commix" }, + { NMA_C_SOFD_XMX, "XMX", "Xyplex MAXserver" }, + { NMA_C_SOFD_NDI, "NDI", "NDIS data link driver for MS/DOS systems" }, + { NMA_C_SOFD_ND2, "ND2", "NDIS data link driver for OS/2 systems" }, + { NMA_C_SOFD_TRN, "TRN", "DEC LANcontroller 520" }, + { NMA_C_SOFD_DEV, "DEV", "Develcon Electronics Ltd. LAT gateway" }, + { NMA_C_SOFD_ACE, "ACE", "Acer 5220, 5270 adapter" }, + { NMA_C_SOFD_PNT, "PNT", "ProNet-4/18 #1390" }, + { NMA_C_SOFD_ISE, "ISE", "Network Integration Server 600" }, + { NMA_C_SOFD_IST, "IST", "Network Integration Server 600 T1" }, + { NMA_C_SOFD_ISH, "ISH", "Network Integration Server 64 kb HDLC" }, + { NMA_C_SOFD_ISF, "ISF", "Network Integration Server 600 FDDI" }, + { NMA_C_SOFD_DSW, "DSW", "DSW-21" }, + { NMA_C_SOFD_DW4, "DW4", "DSW-41/42" }, + { NMA_C_SOFD_TRA, "TRA", "DETRA-AA" }, + { 0, 0, 0 }, +}; + +char * +nmaGetShort(devno) + int devno; +{ + struct commDev *current; + + current = nmaCommDev; + + while (current->sname != NULL) { + if (current->val == devno) + break; + current++; + } + + return(current->sname); +} + +char * +nmaGetDevice(devno) + int devno; +{ + struct commDev *current; + + current = nmaCommDev; + + while (current->name != NULL) { + if (current->val == devno) + break; + current++; + } + + return(current->name); +} diff --git a/package/mopd/src/common/nma.h b/package/mopd/src/common/nma.h new file mode 100644 index 000000000..6f14cc1bb --- /dev/null +++ b/package/mopd/src/common/nma.h @@ -0,0 +1,43 @@ +/* $NetBSD: nma.h,v 1.2 1997/03/25 03:07:23 thorpej Exp $ */ + +/* + * Copyright (c) 1995 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: nma.h,v 1.2 1997/03/25 03:07:23 thorpej Exp $ + * + */ + +#ifndef _NMA_H_ +#define _NMA_H_ + +__BEGIN_DECLS +char *nmaGetShort __P((int)); +char *nmaGetDevice __P((int)); +__END_DECLS + +#endif _NMA_H_ diff --git a/package/mopd/src/common/nmadef.h b/package/mopd/src/common/nmadef.h new file mode 100644 index 000000000..844545622 --- /dev/null +++ b/package/mopd/src/common/nmadef.h @@ -0,0 +1,183 @@ +/* $NetBSD$ */ + +/* + * Copyright (c) 1995 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: nmadef.h,v 1.1.1.1 1997/03/16 22:23:37 cjs Exp $ + * + */ + +#ifndef _NMADEF_H_ +#define _NMADEF_H_ + +#define NMA_C_SOFD_DP 0 /* DP11-DA */ +#define NMA_C_SOFD_UNA 1 /* DEUNA */ +#define NMA_C_SOFD_DU 2 /* DU11-DA */ +#define NMA_C_SOFD_CNA 3 /* DECNA */ +#define NMA_C_SOFD_DL 4 /* DL11-C, -E, or -WA */ +#define NMA_C_SOFD_QNA 5 /* DEQNA */ +#define NMA_C_SOFD_DQ 6 /* DQ11-DA */ +#define NMA_C_SOFD_CI 7 /* Computer Interconnect */ +#define NMA_C_SOFD_DA 8 /* DA11-B or -AL */ +#define NMA_C_SOFD_PCL 9 /* PCL11-B */ +#define NMA_C_SOFD_DUP 10 /* DUP11-DA */ +#define NMA_C_SOFD_LUA 11 /* DELUA */ +#define NMA_C_SOFD_DMC 12 /* DMC11-DA/AR, -FA/AR, -MA/AL or -MD/AL */ +#define NMA_C_SOFD_LNA 13 /* MicroServer Lance */ +#define NMA_C_SOFD_DN 14 /* DN11-BA or -AA */ +#define NMA_C_SOFD_DLV 16 /* DLV11-E, -F, -J, MXV11-A or -B */ +#define NMA_C_SOFD_LCS 17 /* DECServer 100 */ +#define NMA_C_SOFD_DMP 18 /* DMP11 */ +#define NMA_C_SOFD_AMB 19 /* AMBER */ +#define NMA_C_SOFD_DTE 20 /* DTE20 */ +#define NMA_C_SOFD_DBT 21 /* DEBET */ +#define NMA_C_SOFD_DV 22 /* DV11-AA/BA */ +#define NMA_C_SOFD_BNA 23 /* DEBNA */ +#define NMA_C_SOFD_BNT 23 /* DEBNT */ +#define NMA_C_SOFD_DZ 24 /* DZ11-A, -B, -C, -D */ +#define NMA_C_SOFD_LPC 25 /* PCXX */ +#define NMA_C_SOFD_DSV 26 /* DSV11 */ +#define NMA_C_SOFD_CEC 27 /* 3-COM/IBM-PC */ +#define NMA_C_SOFD_KDP 28 /* KMC11/DUP11-DA */ +#define NMA_C_SOFD_IEC 29 /* Interlan/IBM-PC */ +#define NMA_C_SOFD_KDZ 30 /* KMC11/DZ11-A, -B, -C, or -D */ +#define NMA_C_SOFD_UEC 31 /* Univation/RAINBOW-100 */ +#define NMA_C_SOFD_KL8 32 /* KL8-J */ +#define NMA_C_SOFD_DS2 33 /* DECServer 200 */ +#define NMA_C_SOFD_DMV 34 /* DMV11 */ +#define NMA_C_SOFD_DS5 35 /* DECServer 500 */ +#define NMA_C_SOFD_DPV 36 /* DPV11 */ +#define NMA_C_SOFD_LQA 37 /* DELQA */ +#define NMA_C_SOFD_DMF 38 /* DMF32 */ +#define NMA_C_SOFD_SVA 39 /* DESVA */ +#define NMA_C_SOFD_DMR 40 /* DMR11-AA, -AB, -AC, or -AE */ +#define NMA_C_SOFD_MUX 41 /* MUXserver */ +#define NMA_C_SOFD_KMY 42 /* KMS11-PX */ +#define NMA_C_SOFD_DEP 43 /* DEPCA PCSG/IBM-PC */ +#define NMA_C_SOFD_KMX 44 /* KMS11-BD/BE */ +#define NMA_C_SOFD_LTM 45 /* LTM Ethernet monitor */ +#define NMA_C_SOFD_DMB 46 /* DMB-32 */ +#define NMA_C_SOFD_DES 47 /* DESNC */ +#define NMA_C_SOFD_KCP 48 /* KCP */ +#define NMA_C_SOFD_MX3 49 /* MUXServer 300 */ +#define NMA_C_SOFD_SYN 50 /* MicroServer */ +#define NMA_C_SOFD_MEB 51 /* DEMEB */ +#define NMA_C_SOFD_DSB 52 /* DSB32 */ +#define NMA_C_SOFD_BAM 53 /* DEBAM LANBridge-200 */ +#define NMA_C_SOFD_DST 54 /* DST-32 TEAMmate */ +#define NMA_C_SOFD_FAT 55 /* DEFAT */ +#define NMA_C_SOFD_RSM 56 /* DERSM - Remote Segment Monitor */ +#define NMA_C_SOFD_RES 57 /* DERES - Remote Environmental Sensor */ +#define NMA_C_SOFD_3C2 58 /* 3COM Etherlink II (3C503) */ +#define NMA_C_SOFD_3CM 59 /* 3COM Etherlink/MC (3C523) */ +#define NMA_C_SOFD_DS3 60 /* DECServer 300 */ +#define NMA_C_SOFD_MF2 61 /* Mayfair-2 */ +#define NMA_C_SOFD_MMR 62 /* DEMMR */ +#define NMA_C_SOFD_VIT 63 /* Vitalink TransLAN III/IV (NP3A) Bridge */ +#define NMA_C_SOFD_VT5 64 /* Vitalink TransLAN 350 (NPC25) Bridge */ +#define NMA_C_SOFD_BNI 65 /* DEBNI */ +#define NMA_C_SOFD_MNA 66 /* DEMNA */ +#define NMA_C_SOFD_PMX 67 /* PMAX (KN01) */ +#define NMA_C_SOFD_NI5 68 /* Interlan NI5210-8 */ +#define NMA_C_SOFD_NI9 69 /* Interlan NI9210 */ +#define NMA_C_SOFD_KMK 70 /* KMS11-K */ +#define NMA_C_SOFD_3CP 71 /* 3COM Etherlink Plus (3C505) */ +#define NMA_C_SOFD_DP2 72 /* DPNserver-200 */ +#define NMA_C_SOFD_ISA 73 /* SGEC */ +#define NMA_C_SOFD_DIV 74 /* DIV-32 DEC WAN controller-100 */ +#define NMA_C_SOFD_QTA 75 /* DEQTA */ +#define NMA_C_SOFD_B15 76 /* LANbridge-150 */ +#define NMA_C_SOFD_WD8 77 /* WD8003 Family */ +#define NMA_C_SOFD_ILA 78 /* BICC ISOLAN 4110-2 */ +#define NMA_C_SOFD_ILM 79 /* BICC ISOLAN 4110-3 */ +#define NMA_C_SOFD_APR 80 /* Apricot Xen-S and Qi */ +#define NMA_C_SOFD_ASN 81 /* AST EtherNode */ +#define NMA_C_SOFD_ASE 82 /* AST Ethernet */ +#define NMA_C_SOFD_TRW 83 /* TRW HC-2001 */ +#define NMA_C_SOFD_EDX 84 /* Ethernet-XT/AT */ +#define NMA_C_SOFD_EDA 85 /* Ethernet-AT */ +#define NMA_C_SOFD_DR2 86 /* DECrouter-250 */ +#define NMA_C_SOFD_SCC 87 /* DECrouter-250 DUSCC */ +#define NMA_C_SOFD_DCA 88 /* DCA Series 300 */ +#define NMA_C_SOFD_TIA 89 /* LANcard/E */ +#define NMA_C_SOFD_FBN 90 /* DEFEB DECbridge-500 */ +#define NMA_C_SOFD_FEB 91 /* DEFEB DECbridge-500 FDDI */ +#define NMA_C_SOFD_FCN 92 /* DEFCN DECconcentrator-500 */ +#define NMA_C_SOFD_MFA 93 /* DEMFA */ +#define NMA_C_SOFD_MXE 94 /* MIPS workstation family */ +#define NMA_C_SOFD_CED 95 /* Cabletron Ethernet Desktop */ +#define NMA_C_SOFD_C20 96 /* 3Com CS/200 */ +#define NMA_C_SOFD_CS1 97 /* 3Com CS/1 */ +#define NMA_C_SOFD_C2M 98 /* 3Com CS/210, CS/2000, CS/2100 */ +#define NMA_C_SOFD_ACA 99 /* ACA/32000 system */ +#define NMA_C_SOFD_GSM 100 /* Gandalf StarMaster */ +#define NMA_C_SOFD_DSF 101 /* DSF32 */ +#define NMA_C_SOFD_CS5 102 /* 3Com CS/50 */ +#define NMA_C_SOFD_XIR 103 /* XIRCOM PE10B2 */ +#define NMA_C_SOFD_KFE 104 /* KFE52 */ +#define NMA_C_SOFD_RT3 105 /* rtVAX-300 */ +#define NMA_C_SOFD_SPI 106 /* Spiderport M250 */ +#define NMA_C_SOFD_FOR 107 /* LAT gateway */ +#define NMA_C_SOFD_MER 108 /* Meridian */ +#define NMA_C_SOFD_PER 109 /* Persoft */ +#define NMA_C_SOFD_STR 110 /* AT&T StarLan-10 */ +#define NMA_C_SOFD_MPS 111 /* MIPSfair */ +#define NMA_C_SOFD_L20 112 /* LPS20 print server */ +#define NMA_C_SOFD_VT2 113 /* Vitalink TransLAN 320 Bridge */ +#define NMA_C_SOFD_DWT 114 /* VT-1000 */ +#define NMA_C_SOFD_WGB 115 /* DEWGB */ +#define NMA_C_SOFD_ZEN 116 /* Zenith Z-LAN4000, Z-LAN */ +#define NMA_C_SOFD_TSS 117 /* Thursby Software Systems */ +#define NMA_C_SOFD_MNE 118 /* 3MIN (KN02-BA) */ +#define NMA_C_SOFD_FZA 119 /* DEFZA */ +#define NMA_C_SOFD_90L 120 /* DS90L */ +#define NMA_C_SOFD_CIS 121 /* Cisco Systems */ +#define NMA_C_SOFD_STC 122 /* STRTC */ +#define NMA_C_SOFD_UBE 123 /* Ungermann-Bass PC2030, PC3030 */ +#define NMA_C_SOFD_DW2 124 /* DECwindows terminal II */ +#define NMA_C_SOFD_FUE 125 /* Fujitsu Etherstar MB86950 */ +#define NMA_C_SOFD_M38 126 /* MUXServer 380 */ +#define NMA_C_SOFD_NTI 127 /* NTI Group PC Ethernet Card */ +#define NMA_C_SOFD_RAD 130 /* RADLINX LAN Gateway */ +#define NMA_C_SOFD_INF 131 /* Infotron Commix */ +#define NMA_C_SOFD_XMX 132 /* Xyplex MAXserver */ +#define NMA_C_SOFD_NDI 133 /* NDIS data link driver for MS/DOS systems */ +#define NMA_C_SOFD_ND2 134 /* NDIS data link driver for OS/2 systems */ +#define NMA_C_SOFD_TRN 135 /* DEC LANcontroller 520 */ +#define NMA_C_SOFD_DEV 136 /* Develcon Electronics Ltd. LAT gateway */ +#define NMA_C_SOFD_ACE 137 /* Acer 5220, 5270 adapter */ +#define NMA_C_SOFD_PNT 138 /* ProNet-4/18 #1390 */ +#define NMA_C_SOFD_ISE 139 /* Network Integration Server 600 */ +#define NMA_C_SOFD_IST 140 /* Network Integration Server 600 T1 */ +#define NMA_C_SOFD_ISH 141 /* Network Integration Server 64 kb HDLC */ +#define NMA_C_SOFD_ISF 142 /* Network Integration Server 600 FDDI */ +#define NMA_C_SOFD_DSW 149 /* DSW-21 */ +#define NMA_C_SOFD_DW4 150 /* DSW-41/42 */ +#define NMA_C_SOFD_TRA 175 /* DETRA-AA */ + +#endif _NMADEF_H_ diff --git a/package/mopd/src/common/os.h b/package/mopd/src/common/os.h new file mode 100644 index 000000000..d2658be2d --- /dev/null +++ b/package/mopd/src/common/os.h @@ -0,0 +1,53 @@ +/* $OpenBSD: os-linux2.h,v 1.1 1999/03/27 14:31:22 maja Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * @(#) $OpenBSD: os-linux2.h,v 1.1 1999/03/27 14:31:22 maja Exp $ + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define LINUX2_PF +#define SETPGRP_NOPARAM + diff --git a/package/mopd/src/common/pf-linux2.c b/package/mopd/src/common/pf-linux2.c new file mode 100644 index 000000000..1ae82ff90 --- /dev/null +++ b/package/mopd/src/common/pf-linux2.c @@ -0,0 +1,321 @@ +/* + * General Purpose AppleTalk Packet Filter Interface + * + * Copyright (c) 1992-1995, The University of Melbourne. + * All Rights Reserved. Permission to redistribute or + * use any part of this software for any purpose must + * be obtained in writing from the copyright owner. + * + * This software is supplied "as is" without express + * or implied warranty. + * + * djh@munnari.OZ.AU + * + * Supports: + * Linux SOCK_PACKET + * + * $Author: atp $ + * $Revision: 1.1.1.1 $ + * + * + * Modified for use with the linux-mopd port by Karl Maftoum + * u963870@student.canberra.edu.au + * + */ + +/* + * include header files + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MOPDEF_SUPRESS_EXTERN +#include "mopdef.h" + +/* + * definitions + * + */ + +#define READBUFSIZ 4096 +#define NUMRDS 32 + +struct RDS { + u_short dataLen; + u_char *dataPtr; +}; + +/* + * variables + * + */ + +struct socklist { + int iflen; + struct sockaddr sa; +} socklist[32]; + +struct ifreq ifr; +extern int errno; +extern int promisc; + +struct RDS RDS[NUMRDS]; + +/* + * Open and initialize packet filter + * for a particular protocol type. + * + */ + + +int +pfInit(interface, mode, protocol, typ) +char *interface; +u_short protocol; +int typ, mode; +{ + int s; + int ioarg; + char device[64]; + unsigned long if_flags; + + + { u_short prot; + + prot = ((typ == TRANS_8023) ? htons(ETH_P_802_2) : htons(protocol)); + if ((s = socket(AF_INET, SOCK_PACKET, prot)) < 0) { + perror(interface); + return(-1); + } + if (s >= 32) { + close(s); + return(-1); + } + } + + /* + * set filter for protocol and type (IPTalk, Phase 1/2) + * + */ + + if (setup_pf(s, protocol, typ) < 0) + return(-1); + + /* + * set options, bind to underlying interface + * + */ + + strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); + + /* record socket interface name and length */ + strncpy(socklist[s].sa.sa_data, interface, sizeof(socklist[s].sa.sa_data)); + socklist[s].iflen = strlen(interface); + + return(s); +} + +/* + * establish protocol filter + * + */ + +int +setup_pf(s, prot, typ) +int s, typ; +u_short prot; +{ + int ioarg; + u_short offset; + return(0); +} + +/* + * get the interface ethernet address + * + */ + +int +pfEthAddr(s, interface, addr) +int s; +char *interface; +u_char *addr; +{ + strncpy(ifr.ifr_name, interface, sizeof (ifr.ifr_name) -1); + ifr.ifr_name[sizeof(ifr.ifr_name)] = 0; + ifr.ifr_addr.sa_family = AF_INET; + if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { + perror("SIOCGIFHWADDR"); + return(-1); + } + memcpy((char *)addr, ifr.ifr_hwaddr.sa_data, 6); + return(0); +} + +/* + * add a multicast address to the interface + * + */ + +int +pfAddMulti(s, interface, addr) +int s; +char *interface; +u_char *addr; +{ + int sock; + + strncpy(ifr.ifr_name, interface, sizeof (ifr.ifr_name) - 1); + ifr.ifr_name[sizeof(ifr.ifr_name)] = 0; + + ifr.ifr_addr.sa_family = AF_UNSPEC; + bcopy((char *)addr, ifr.ifr_addr.sa_data, 6); + + /* + * open a socket, temporarily, to use for SIOC* ioctls + * + */ + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + perror("socket()"); + return(-1); + } + if (ioctl(sock, SIOCADDMULTI, (caddr_t)&ifr) < 0) { + perror("SIOCADDMULTI"); + close(sock); + return(-1); + } + close(sock); + + return(0); +} + +/* + * delete a multicast address from the interface + * + */ + +int +pfDelMulti(s, interface, addr) +int s; +char *interface; +u_char *addr; +{ + int sock; + + strncpy(ifr.ifr_name, interface, sizeof (ifr.ifr_name) - 1); + ifr.ifr_name[sizeof(ifr.ifr_name)] = 0; + + ifr.ifr_addr.sa_family = AF_UNSPEC; + bcopy((char *)addr, ifr.ifr_addr.sa_data, 6); + + /* + * open a socket, temporarily, to use for SIOC* ioctls + * + */ + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + perror("socket()"); + return(-1); + } + if (ioctl(sock, SIOCDELMULTI, (caddr_t)&ifr) < 0) { + perror("SIOCDELMULTI"); + close(sock); + return(-1); + } + close(sock); + + return(0); +} + +/* + * return 1 if ethernet interface capable of multiple opens + * + */ + +int +eth_mopen(phase) +int phase; +{ + if (phase == 2) + return(0); + return(1); +} + +/* + * read a packet + * Read Data Structure describes packet(s) received + * + */ + + + + +int +pfRead(fd, buf, len) +int fd, len; +u_char *buf; +{ + int i, cc; + + int fromlen; + struct sockaddr sa; + + RDS[0].dataLen = 0; + fromlen = sizeof(struct sockaddr); + + if ((cc = recvfrom(fd, (char *)buf, len, 0, &sa, &fromlen)) <= 0) + return(cc); + + /* check if from right interface */ + for (i = socklist[fd].iflen-1; i >= 0; i--) + if (sa.sa_data[i] != socklist[fd].sa.sa_data[i]) + return(0); + + RDS[0].dataLen = cc; + RDS[0].dataPtr = buf; + RDS[1].dataLen = 0; + + return(cc); +} + +/* + * write a packet + * + */ + +int +pfWrite(fd, buf, len) +int fd, len; +u_char *buf; +{ + + if (sendto(fd, buf, len, 0, &socklist[fd].sa, sizeof(struct sockaddr)) == len) + return(len); + + return(-1); +} + +/* + * Return information to device.c how to open device. + * In this case the driver can handle both Ethernet type II and + * IEEE 802.3 frames (SNAP) in a single pfOpen. + */ + +int +pfTrans(interface) + char *interface; +{ + return TRANS_ETHER+TRANS_8023; +} + diff --git a/package/mopd/src/common/pf.c b/package/mopd/src/common/pf.c new file mode 100644 index 000000000..41ec4e1e1 --- /dev/null +++ b/package/mopd/src/common/pf.c @@ -0,0 +1,264 @@ +/* $NetBSD: pf.c,v 1.4 1997/10/16 23:24:55 lukem Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is partly derived from rarpd. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: pf.c,v 1.4 1997/10/16 23:24:55 lukem Exp $"); +#endif + +#include "os.h" + +#include +#include + +#include "mopdef.h" +#include "pf.h" + +/* + * Variables + */ + +extern int promisc; + +/* + * Return information to device.c how to open device. + * In this case the driver can handle both Ethernet type II and + * IEEE 802.3 frames (SNAP) in a single pfOpen. + */ + +int +pfTrans(interface) + char *interface; +{ + return TRANS_ETHER+TRANS_8023+TRANS_AND; +} + +/* + * Open and initialize packet filter. + */ + +int +pfInit(interface, mode, protocol, typ) + char *interface; + u_short protocol; + int typ, mode; +{ + int fd; + int n = 0; + char device[sizeof "/dev/bpf000"]; + struct ifreq ifr; + u_int dlt; + int immediate; + + static struct bpf_insn insns[] = { + BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), + BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x4711, 4, 0), + BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20), + BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x4711, 0, 3), + BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 14), + BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xaaaa, 0, 1), + BPF_STMT(BPF_RET | BPF_K, 1520), + BPF_STMT(BPF_RET | BPF_K, 0), + }; + static struct bpf_program filter = { + sizeof insns / sizeof(insns[0]), + insns + }; + + /* Go through all the minors and find one that isn't in use. */ + do { + (void) sprintf(device, "/dev/bpf%d", n++); + fd = open(device, mode); + } while (fd < 0 && errno == EBUSY); + + if (fd < 0) { + syslog(LOG_ERR,"pfInit: open %s: %m", device); + return(-1); + } + + /* Set immediate mode so packets are processed as they arrive. */ + immediate = 1; + if (ioctl(fd, BIOCIMMEDIATE, &immediate) < 0) { + syslog(LOG_ERR,"pfInit: BIOCIMMEDIATE: %m"); + return(-1); + } + (void) strncpy(ifr.ifr_name, interface, sizeof ifr.ifr_name); + if (ioctl(fd, BIOCSETIF, (caddr_t) & ifr) < 0) { + syslog(LOG_ERR,"pfInit: BIOCSETIF: %m"); + return(-1); + } + /* Check that the data link layer is an Ethernet; this code won't work + * with anything else. */ + if (ioctl(fd, BIOCGDLT, (caddr_t) & dlt) < 0) { + syslog(LOG_ERR,"pfInit: BIOCGDLT: %m"); + return(-1); + } + if (dlt != DLT_EN10MB) { + syslog(LOG_ERR,"pfInit: %s is not ethernet", device); + return(-1); + } + if (promisc) { + /* Set promiscuous mode. */ + if (ioctl(fd, BIOCPROMISC, (caddr_t)0) < 0) { + syslog(LOG_ERR,"pfInit: BIOCPROMISC: %m"); + return(-1); + } + } + /* Set filter program. */ + insns[1].k = protocol; + insns[3].k = protocol; + + if (ioctl(fd, BIOCSETF, (caddr_t) & filter) < 0) { + syslog(LOG_ERR,"pfInit: BIOCSETF: %m"); + return(-1); + } + return(fd); +} + +/* + * Add a Multicast address to the interface + */ + +int +pfAddMulti(s, interface, addr) + int s; + char *interface, *addr; +{ + struct ifreq ifr; + int fd; + + strcpy(ifr.ifr_name, interface); + + ifr.ifr_addr.sa_family = AF_UNSPEC; + memmove(ifr.ifr_addr.sa_data, addr, 6); + + /* + * open a socket, temporarily, to use for SIOC* ioctls + * + */ + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "pfAddMulti: socket: %m"); + return(-1); + } + if (ioctl(fd, SIOCADDMULTI, (caddr_t)&ifr) < 0) { + syslog(LOG_ERR, "pfAddMulti: SIOCADDMULTI: %m"); + close(fd); + return(-1); + } + close(fd); + + return(0); +} + +/* + * Delete a Multicast address from the interface + */ + +int +pfDelMulti(s, interface, addr) + int s; + char *interface, *addr; +{ + struct ifreq ifr; + int fd; + + strcpy(ifr.ifr_name, interface); + + ifr.ifr_addr.sa_family = AF_UNSPEC; + memmove(ifr.ifr_addr.sa_data, addr, 6); + + /* + * open a socket, temporarily, to use for SIOC* ioctls + * + */ + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "pfDelMulti: socket: %m"); + return(-1); + } + if (ioctl(fd, SIOCDELMULTI, (caddr_t)&ifr) < 0) { + syslog(LOG_ERR, "pfAddMulti: SIOCDELMULTI: %m"); + close(fd); + return(-1); + } + close(fd); + + return(0); +} + +/* + * read a packet + */ + +int +pfRead(fd, buf, len) + int fd, len; + u_char *buf; +{ + return(read(fd, buf, len)); +} + +/* + * write a packet + */ + +int +pfWrite(fd, buf, len, trans) + int fd, len, trans; + u_char *buf; +{ + + struct iovec iov[2]; + + switch (trans) { + case TRANS_8023: + iov[0].iov_base = (caddr_t)buf; + iov[0].iov_len = 22; + iov[1].iov_base = (caddr_t)buf+22; + iov[1].iov_len = len-22; + break; + default: + iov[0].iov_base = (caddr_t)buf; + iov[0].iov_len = 14; + iov[1].iov_base = (caddr_t)buf+14; + iov[1].iov_len = len-14; + break; + } + + if (writev(fd, iov, 2) == len) + return(len); + + return(-1); +} + diff --git a/package/mopd/src/common/pf.h b/package/mopd/src/common/pf.h new file mode 100644 index 000000000..e37f78cc7 --- /dev/null +++ b/package/mopd/src/common/pf.h @@ -0,0 +1,48 @@ +/* $NetBSD: pf.h,v 1.2 1997/03/25 03:07:29 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: pf.h,v 1.2 1997/03/25 03:07:29 thorpej Exp $ + * + */ + +#ifndef _PF_H_ +#define _PF_H_ + +__BEGIN_DECLS +int pfTrans __P((char *)); +int pfInit __P((char *, int, u_short, int)); +int pfEthAddr __P((int, u_char *)); +int pfAddMulti __P((int, char *, char *)); +int pfDelMulti __P((int, char *, char *)); +int pfRead __P((int, u_char *, int)); +int pfWrite __P((int, u_char *, int, int)); +__END_DECLS + +#endif _PF_H_ diff --git a/package/mopd/src/common/print.c b/package/mopd/src/common/print.c new file mode 100644 index 000000000..7bb859ead --- /dev/null +++ b/package/mopd/src/common/print.c @@ -0,0 +1,707 @@ +/* $NetBSD: print.c,v 1.2 1997/03/25 03:07:30 thorpej Exp $ */ + +/* + * Copyright (c) 1993-96 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: print.c,v 1.2 1997/03/25 03:07:30 thorpej Exp $"; +#endif + +#include +#include + +#include "os.h" +#include "cmp.h" +#include "get.h" +#include "mopdef.h" +#include "nma.h" +#include "nmadef.h" +#include "print.h" + +#define SHORT_PRINT + +void +mopPrintHWA(fd, ap) + FILE *fd; + u_char *ap; +{ + (void)fprintf(fd, "%x:%x:%x:%x:%x:%x", + ap[0],ap[1],ap[2],ap[3],ap[4],ap[5]); + if (ap[0] < 10) (void)fprintf(fd, " "); + if (ap[1] < 10) (void)fprintf(fd, " "); + if (ap[2] < 10) (void)fprintf(fd, " "); + if (ap[3] < 10) (void)fprintf(fd, " "); + if (ap[4] < 10) (void)fprintf(fd, " "); + if (ap[5] < 10) (void)fprintf(fd, " "); +} + +void +mopPrintBPTY(fd, bpty) + FILE *fd; + u_char bpty; +{ + switch(bpty) { + case MOP_K_BPTY_SYS: + (void)fprintf(fd, "System Processor"); + break; + case MOP_K_BPTY_COM: + (void)fprintf(fd, "Communication Processor"); + break; + default: + (void)fprintf(fd, "Unknown"); + break; + }; +}; + +void +mopPrintPGTY(fd, pgty) + FILE *fd; + u_char pgty; +{ + switch(pgty) { + case MOP_K_PGTY_SECLDR: + (void)fprintf(fd, "Secondary Loader"); + break; + case MOP_K_PGTY_TERLDR: + (void)fprintf(fd, "Tertiary Loader"); + break; + case MOP_K_PGTY_OPRSYS: + (void)fprintf(fd, "Operating System"); + break; + case MOP_K_PGTY_MGNTFL: + (void)fprintf(fd, "Management File"); + break; + default: + (void)fprintf(fd, "Unknown"); + break; + }; +} + +void +mopPrintOneline(fd, pkt, trans) + FILE *fd; + u_char *pkt; + int trans; +{ + int index = 0; + u_char *dst, *src, code; + u_short proto; + int len; + + trans = mopGetTrans(pkt, trans); + mopGetHeader(pkt, &index, &dst, &src, &proto, &len, trans); + code = mopGetChar(pkt, &index); + + switch (proto) { + case MOP_K_PROTO_DL: + (void)fprintf(fd, "MOP DL "); + break; + case MOP_K_PROTO_RC: + (void)fprintf(fd, "MOP RC "); + break; + case MOP_K_PROTO_LP: + (void)fprintf(fd, "MOP LP "); + break; + default: + switch((proto % 256)*256 + (proto / 256)) { + case MOP_K_PROTO_DL: + (void)fprintf(fd, "MOP DL "); + proto = MOP_K_PROTO_DL; + break; + case MOP_K_PROTO_RC: + (void)fprintf(fd, "MOP RC "); + proto = MOP_K_PROTO_RC; + break; + case MOP_K_PROTO_LP: + (void)fprintf(fd, "MOP LP "); + proto = MOP_K_PROTO_LP; + break; + default: + (void)fprintf(fd, "MOP ?? "); + break; + } + } + + if (trans == TRANS_8023) { + (void)fprintf(fd, "802.3 "); + } + + mopPrintHWA(fd, src); (void)fprintf(fd," > "); + mopPrintHWA(fd, dst); + if (len < 1600) { + (void)fprintf(fd, " len %4d code %02x ",len,code); + } else { + (void)fprintf(fd, " len %4d code %02x ", + (len % 256)*256 + (len /256), code); + } + + switch (proto) { + case MOP_K_PROTO_DL: + switch (code) { + case MOP_K_CODE_MLT: + (void)fprintf(fd, "MLT "); + break; + case MOP_K_CODE_DCM: + (void)fprintf(fd, "DCM "); + break; + case MOP_K_CODE_MLD: + (void)fprintf(fd, "MLD "); + break; + case MOP_K_CODE_ASV: + (void)fprintf(fd, "ASV "); + break; + case MOP_K_CODE_RMD: + (void)fprintf(fd, "RMD "); + break; + case MOP_K_CODE_RPR: + (void)fprintf(fd, "RPR "); + break; + case MOP_K_CODE_RML: + (void)fprintf(fd, "RML "); + break; + case MOP_K_CODE_RDS: + (void)fprintf(fd, "RDS "); + break; + case MOP_K_CODE_MDD: + (void)fprintf(fd, "MDD "); + break; + case MOP_K_CODE_PLT: + (void)fprintf(fd, "PLT "); + break; + default: + (void)fprintf(fd, "??? "); + break; + } + break; + case MOP_K_PROTO_RC: + switch (code) { + case MOP_K_CODE_RID: + (void)fprintf(fd, "RID "); + break; + case MOP_K_CODE_BOT: + (void)fprintf(fd, "BOT "); + break; + case MOP_K_CODE_SID: + (void)fprintf(fd, "SID "); + break; + case MOP_K_CODE_RQC: + (void)fprintf(fd, "RQC "); + break; + case MOP_K_CODE_CNT: + (void)fprintf(fd, "CNT "); + break; + case MOP_K_CODE_RVC: + (void)fprintf(fd, "RVC "); + break; + case MOP_K_CODE_RLC: + (void)fprintf(fd, "RLC "); + break; + case MOP_K_CODE_CCP: + (void)fprintf(fd, "CCP "); + break; + case MOP_K_CODE_CRA: + (void)fprintf(fd, "CRA "); + break; + default: + (void)fprintf(fd, "??? "); + break; + } + break; + case MOP_K_PROTO_LP: + switch (code) { + case MOP_K_CODE_ALD: + (void)fprintf(fd, "ALD "); + break; + case MOP_K_CODE_PLD: + (void)fprintf(fd, "PLD "); + break; + default: + (void)fprintf(fd, "??? "); + break; + } + break; + default: + (void)fprintf(fd, "??? "); + break; + } + (void)fprintf(fd, "\n"); +} + +void +mopPrintHeader(fd, pkt, trans) + FILE *fd; + u_char *pkt; + int trans; +{ + u_char *dst, *src; + u_short proto; + int len, index = 0; + + trans = mopGetTrans(pkt, trans); + mopGetHeader(pkt, &index, &dst, &src, &proto, &len, trans); + + (void)fprintf(fd,"\nDst : "); + mopPrintHWA(fd, dst); + if (mopCmpEAddr(dl_mcst,dst) == 0) { + (void)fprintf(fd," MOP Dump/Load Multicast"); + }; + if (mopCmpEAddr(rc_mcst,dst) == 0) { + (void)fprintf(fd," MOP Remote Console Multicast"); + }; + (void)fprintf(fd,"\n"); + + (void)fprintf(fd,"Src : "); + mopPrintHWA(fd, src); + (void)fprintf(fd,"\n"); + (void)fprintf(fd,"Proto : %04x ",proto); + switch (proto) { + case MOP_K_PROTO_DL: + switch (trans) { + case TRANS_8023: + (void)fprintf(fd, "MOP Dump/Load (802.3)\n"); + break; + default: + (void)fprintf(fd, "MOP Dump/Load\n"); + } + break; + case MOP_K_PROTO_RC: + switch (trans) { + case TRANS_8023: + (void)fprintf(fd, "MOP Remote Console (802.3)\n"); + break; + default: + (void)fprintf(fd, "MOP Remote Console\n"); + } + break; + case MOP_K_PROTO_LP: + switch (trans) { + case TRANS_8023: + (void)fprintf(fd, "MOP Loopback (802.3)\n"); + break; + default: + (void)fprintf(fd, "MOP Loopback\n"); + } + break; + default: + (void)fprintf(fd, "\n"); + break; + } + + + (void)fprintf(fd,"Length : %04x (%d)\n",len,len); +} + +void +mopPrintMopHeader(fd, pkt, trans) + FILE *fd; + u_char *pkt; + int trans; +{ + u_char *dst, *src; + u_short proto; + int len, index = 0; + u_char code; + + trans = mopGetTrans(pkt, trans); + mopGetHeader(pkt, &index, &dst, &src, &proto, &len, trans); + + code = mopGetChar(pkt, &index); + + (void)fprintf(fd, "Code : %02x ",code); + + switch (proto) { + case MOP_K_PROTO_DL: + switch (code) { + case MOP_K_CODE_MLT: + (void)fprintf(fd, + "Memory Load with transfer address\n"); + break; + case MOP_K_CODE_DCM: + (void)fprintf(fd, "Dump Complete\n"); + break; + case MOP_K_CODE_MLD: + (void)fprintf(fd, "Memory Load\n"); + break; + case MOP_K_CODE_ASV: + (void)fprintf(fd, "Assistance volunteer\n"); + break; + case MOP_K_CODE_RMD: + (void)fprintf(fd, "Request memory dump\n"); + break; + case MOP_K_CODE_RPR: + (void)fprintf(fd, "Request program\n"); + break; + case MOP_K_CODE_RML: + (void)fprintf(fd, "Request memory load\n"); + break; + case MOP_K_CODE_RDS: + (void)fprintf(fd, "Request Dump Service\n"); + break; + case MOP_K_CODE_MDD: + (void)fprintf(fd, "Memory dump data\n"); + break; + case MOP_K_CODE_PLT: + (void)fprintf(fd, + "Parameter load with transfer addres\n"); + break; + default: + (void)fprintf(fd, "(unknown)\n"); + break; + } + break; + case MOP_K_PROTO_RC: + switch (code) { + case MOP_K_CODE_RID: + (void)fprintf(fd, "Request ID\n"); + break; + case MOP_K_CODE_BOT: + (void)fprintf(fd, "Boot\n"); + break; + case MOP_K_CODE_SID: + (void)fprintf(fd, "System ID\n"); + break; + case MOP_K_CODE_RQC: + (void)fprintf(fd, "Request Counters\n"); + break; + case MOP_K_CODE_CNT: + (void)fprintf(fd, "Counters\n"); + break; + case MOP_K_CODE_RVC: + (void)fprintf(fd, "Reserve Console\n"); + break; + case MOP_K_CODE_RLC: + (void)fprintf(fd, "Release Console\n"); + break; + case MOP_K_CODE_CCP: + (void)fprintf(fd, "Console Command and Poll\n"); + break; + case MOP_K_CODE_CRA: + (void)fprintf(fd, + "Console Response and Acknnowledge\n"); + break; + default: + (void)fprintf(fd, "(unknown)\n"); + break; + } + break; + case MOP_K_PROTO_LP: + switch (code) { + case MOP_K_CODE_ALD: + (void)fprintf(fd, "Active loop data\n"); + break; + case MOP_K_CODE_PLD: + (void)fprintf(fd, "Passive looped data\n"); + break; + default: + (void)fprintf(fd, "(unknown)\n"); + break; + } + break; + default: + (void)fprintf(fd, "(unknown)\n"); + break; + } +} + +void +mopPrintDevice(fd, device) + FILE *fd; + u_char device; +{ + char *sname, *name; + + sname = nmaGetShort((int) device); + name = nmaGetDevice((int) device); + + (void)fprintf(fd, "%s '%s'",sname,name); +} + +void +mopPrintTime(fd, ap) + FILE *fd; + u_char *ap; +{ + (void)fprintf(fd, + "%04d-%02d-%02d %02d:%02d:%02d.%02d %d:%02d", + ap[0]*100 + ap[1], + ap[2],ap[3],ap[4],ap[5],ap[6],ap[7],ap[8],ap[9]); +} + +void +mopPrintInfo(fd, pkt, index, moplen, mopcode, trans) + FILE *fd; + u_char *pkt, mopcode; + int *index, trans; + u_short moplen; +{ + u_short itype,tmps; + u_char ilen ,tmpc,device; + u_char uc1,uc2,uc3,*ucp; + int i; + + device = 0; + + switch(trans) { + case TRANS_ETHER: + moplen = moplen + 16; + break; + case TRANS_8023: + moplen = moplen + 14; + break; + } + + itype = mopGetShort(pkt,index); + + while (*index < (int)(moplen + 2)) { + ilen = mopGetChar(pkt,index); + switch (itype) { + case 0: + tmpc = mopGetChar(pkt,index); + *index = *index + tmpc; + break; + case MOP_K_INFO_VER: + uc1 = mopGetChar(pkt,index); + uc2 = mopGetChar(pkt,index); + uc3 = mopGetChar(pkt,index); + (void)fprintf(fd,"Maint Version: %d.%d.%d\n", + uc1,uc2,uc3); + break; + case MOP_K_INFO_MFCT: + tmps = mopGetShort(pkt,index); + (void)fprintf(fd,"Maint Funcion: %04x ( ",tmps); + if (tmps & 1) (void)fprintf(fd, "Loop "); + if (tmps & 2) (void)fprintf(fd, "Dump "); + if (tmps & 4) (void)fprintf(fd, "Pldr "); + if (tmps & 8) (void)fprintf(fd, "MLdr "); + if (tmps & 16) (void)fprintf(fd, "Boot "); + if (tmps & 32) (void)fprintf(fd, "CC "); + if (tmps & 64) (void)fprintf(fd, "DLC "); + if (tmps & 128) (void)fprintf(fd, "CCR "); + (void)fprintf(fd, ")\n"); + break; + case MOP_K_INFO_CNU: + ucp = pkt + *index; *index = *index + 6; + (void)fprintf(fd,"Console User : "); + mopPrintHWA(fd, ucp); + (void)fprintf(fd, "\n"); + break; + case MOP_K_INFO_RTM: + tmps = mopGetShort(pkt,index); + (void)fprintf(fd,"Reserv Timer : %04x (%d)\n", + tmps,tmps); + break; + case MOP_K_INFO_CSZ: + tmps = mopGetShort(pkt,index); + (void)fprintf(fd,"Cons Cmd Size: %04x (%d)\n", + tmps,tmps); + break; + case MOP_K_INFO_RSZ: + tmps = mopGetShort(pkt,index); + (void)fprintf(fd,"Cons Res Size: %04x (%d)\n", + tmps,tmps); + break; + case MOP_K_INFO_HWA: + ucp = pkt + *index; *index = *index + 6; + (void)fprintf(fd,"Hardware Addr: "); + mopPrintHWA(fd, ucp); + (void)fprintf(fd, "\n"); + break; + case MOP_K_INFO_TIME: + ucp = pkt + *index; *index = *index + 10; + (void)fprintf(fd,"System Time: "); + mopPrintTime(fd, ucp); + (void)fprintf(fd,"\n"); + break; + case MOP_K_INFO_SOFD: + device = mopGetChar(pkt,index); + (void)fprintf(fd,"Comm Device : %02x ",device); + mopPrintDevice(fd, device); + (void)fprintf(fd, "\n"); + break; + case MOP_K_INFO_SFID: + tmpc = mopGetChar(pkt,index); + (void)fprintf(fd,"Software ID : %02x ",tmpc); + if ((tmpc == 0)) { + (void)fprintf(fd,"No software id"); + } + if ((tmpc == 254)) { + (void)fprintf(fd,"Maintenance system"); + tmpc = 0; + } + if ((tmpc == 255)) { + (void)fprintf(fd,"Standard operating system"); + tmpc = 0; + } + if ((tmpc > 0)) { + (void)fprintf(fd,"'"); + for (i = 0; i < ((int) tmpc); i++) { + (void)fprintf(fd,"%c", + mopGetChar(pkt,index)); + } + (void)fprintf(fd,"'"); + } + (void)fprintf(fd,"\n"); + break; + case MOP_K_INFO_PRTY: + tmpc = mopGetChar(pkt,index); + (void)fprintf(fd,"System Proc : %02x ",tmpc); + switch (tmpc) { + case MOP_K_PRTY_11: + (void)fprintf(fd, "PDP-11\n"); + break; + case MOP_K_PRTY_CMSV: + (void)fprintf(fd, + "Communication Server\n"); + break; + case MOP_K_PRTY_PRO: + (void)fprintf(fd, "Professional\n"); + break; + case MOP_K_PRTY_SCO: + (void)fprintf(fd, "Scorpio\n"); + break; + case MOP_K_PRTY_AMB: + (void)fprintf(fd, "Amber\n"); + break; + case MOP_K_PRTY_BRI: + (void)fprintf(fd, "XLII Bridge\n"); + break; + default: + (void)fprintf(fd, "Unknown\n"); + break; + }; + break; + case MOP_K_INFO_DLTY: + tmpc = mopGetChar(pkt,index); + (void)fprintf(fd,"Data Link Typ: %02x ",tmpc); + switch (tmpc) { + case MOP_K_DLTY_NI: + (void)fprintf(fd, "Ethernet\n"); + break; + case MOP_K_DLTY_DDCMP: + (void)fprintf(fd, "DDCMP\n"); + break; + case MOP_K_DLTY_LAPB: + (void)fprintf(fd, "LAPB (X.25)\n"); + break; + default: + (void)fprintf(fd, "Unknown\n"); + break; + }; + break; + case MOP_K_INFO_DLBSZ: + tmps = mopGetShort(pkt,index); + (void)fprintf(fd,"DL Buff Size : %04x (%d)\n", + tmps,tmps); + break; + default: + if (((device = NMA_C_SOFD_LCS) || /* DECserver 100 */ + (device = NMA_C_SOFD_DS2) || /* DECserver 200 */ + (device = NMA_C_SOFD_DP2) || /* DECserver 250 */ + (device = NMA_C_SOFD_DS3)) && /* DECserver 300 */ + ((itype > 101) && (itype < 107))) + { + switch (itype) { + case 102: + ucp = pkt + *index; + *index = *index + ilen; + (void)fprintf(fd, + "ROM Sftwr Ver: %02x '", + ilen); + for (i = 0; i < ilen; i++) { + (void)fprintf(fd,"%c",ucp[i]); + } + (void)fprintf(fd, "'\n"); + break; + case 103: + ucp = pkt + *index; + *index = *index + ilen; + (void)fprintf(fd, + "Software Ver : %02x '", + ilen); + for (i = 0; i < ilen; i++) { + (void)fprintf(fd, "%c",ucp[i]); + } + (void)fprintf(fd, "'\n"); + break; + case 104: + tmps = mopGetShort(pkt,index); + (void)fprintf(fd, + "DECnet Addr : %d.%d (%d)\n", + tmps / 1024, + tmps % 1024, + tmps); + break; + case 105: + ucp = pkt + *index; + *index = *index + ilen; + (void)fprintf(fd, + "Node Name : %02x '", + ilen); + for (i = 0; i < ilen; i++) { + (void)fprintf(fd, "%c",ucp[i]); + } + (void)fprintf(fd, "'\n"); + break; + case 106: + ucp = pkt + *index; + *index = *index + ilen; + (void)fprintf(fd, + "Node Ident : %02x '", + ilen); + for (i = 0; i < ilen; i++) { + (void)fprintf(fd, "%c",ucp[i]); + } + (void)fprintf(fd, "'\n"); + break; + }; + } else { + ucp = pkt + *index; *index = *index + ilen; + (void)fprintf(fd, "Info Type : %04x (%d)\n", + itype, + itype); + (void)fprintf(fd, "Info Data : %02x ", + ilen); + for (i = 0; i < ilen; i++) { + if ((i % 16) == 0) { + if ((i / 16) == 0) { + } else { + (void)fprintf(fd, + "\n "); + }; + }; + (void)fprintf(fd, "%02x ",ucp[i]); + } + (void)fprintf(fd, "\n"); + }; + } + itype = mopGetShort(pkt,index); + } +} + diff --git a/package/mopd/src/common/print.h b/package/mopd/src/common/print.h new file mode 100644 index 000000000..3077bde65 --- /dev/null +++ b/package/mopd/src/common/print.h @@ -0,0 +1,51 @@ +/* $NetBSD: print.h,v 1.2 1997/03/25 03:07:31 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: print.h,v 1.2 1997/03/25 03:07:31 thorpej Exp $ + * + */ + +#ifndef _PRINT_H_ +#define _PRINT_H_ + +__BEGIN_DECLS +void mopPrintHWA __P((FILE *, u_char *)); +void mopPrintBPTY __P((FILE *, u_char)); +void mopPrintPGTY __P((FILE *, u_char)); +void mopPrintOneline __P((FILE *, u_char *, int)); +void mopPrintHeader __P((FILE *, u_char *, int)); +void mopPrintMopHeader __P((FILE *, u_char *, int)); +void mopPrintDevice __P((FILE *, u_char)); +void mopPrintTime __P((FILE *, u_char *)); +void mopPrintInfo __P((FILE *, u_char *, int *, u_short, + u_char, int)); +__END_DECLS + +#endif _PRINT_H_ diff --git a/package/mopd/src/common/put.c b/package/mopd/src/common/put.c new file mode 100644 index 000000000..12b6a02d8 --- /dev/null +++ b/package/mopd/src/common/put.c @@ -0,0 +1,185 @@ +/* $NetBSD: put.c,v 1.2 1997/03/25 03:07:33 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: put.c,v 1.2 1997/03/25 03:07:33 thorpej Exp $"; +#endif + +#include "os.h" +#include "mopdef.h" +#include "put.h" + +void +mopPutChar(pkt, index, value) + u_char *pkt; + int *index; + u_char value; +{ + pkt[*index] = value; + *index = *index + 1; +} + +void +mopPutShort(pkt, index, value) + u_char *pkt; + int *index; + u_short value; +{ + int i; + for (i = 0; i < 2; i++) { + pkt[*index+i] = value % 256; + value = value / 256; + } + *index = *index + 2; +} + +void +mopPutLong(pkt, index, value) + u_char *pkt; + int *index; + u_int32_t value; +{ + int i; + for (i = 0; i < 4; i++) { + pkt[*index+i] = value % 256; + value = value / 256; + } + *index = *index + 4; +} + +void +mopPutMulti(pkt, index, value, size) + u_char *pkt,*value; + int *index,size; +{ + int i; + + for (i = 0; i < size; i++) { + pkt[*index+i] = value[i]; + } + *index = *index + size; +} + +void +mopPutTime(pkt, index, value) + u_char *pkt; + int *index; + time_t value; +{ + time_t tnow; + struct tm *timenow; + + if ((value == 0)) { + tnow = time(NULL); + } else { + tnow = value; + } + + timenow = localtime(&tnow); + + mopPutChar (pkt,index,10); + mopPutChar (pkt,index,(timenow->tm_year / 100) + 19); + mopPutChar (pkt,index,(timenow->tm_year % 100)); + mopPutChar (pkt,index,(timenow->tm_mon + 1)); + mopPutChar (pkt,index,(timenow->tm_mday)); + mopPutChar (pkt,index,(timenow->tm_hour)); + mopPutChar (pkt,index,(timenow->tm_min)); + mopPutChar (pkt,index,(timenow->tm_sec)); + mopPutChar (pkt,index,0x00); + mopPutChar (pkt,index,0x00); + mopPutChar (pkt,index,0x00); +} + +void +mopPutHeader(pkt, index, dst, src, proto, trans) + u_char *pkt; + int *index; + u_char dst[], src[]; + u_short proto; + int trans; +{ + + mopPutMulti(pkt, index, dst, 6); + mopPutMulti(pkt, index, src, 6); + if (trans == TRANS_8023) { + mopPutShort(pkt, index, 0); + mopPutChar (pkt, index, MOP_K_PROTO_802_DSAP); + mopPutChar (pkt, index, MOP_K_PROTO_802_SSAP); + mopPutChar (pkt, index, MOP_K_PROTO_802_CNTL); + mopPutChar (pkt, index, 0x08); + mopPutChar (pkt, index, 0x00); + mopPutChar (pkt, index, 0x2b); + } +#if !defined(__FreeBSD__) + mopPutChar(pkt, index, (proto / 256)); + mopPutChar(pkt, index, (proto % 256)); +#else + if (trans == TRANS_8023) { + mopPutChar(pkt, index, (proto / 256)); + mopPutChar(pkt, index, (proto % 256)); + } else { + mopPutChar(pkt, index, (proto % 256)); + mopPutChar(pkt, index, (proto / 256)); + } +#endif + if (trans == TRANS_ETHER) + mopPutShort(pkt, index, 0); + +} + +void +mopPutLength(pkt, trans, len) + u_char *pkt; + int trans; + u_short len; +{ + int index = 0; + + switch(trans) { + case TRANS_ETHER: + index = 14; + mopPutChar(pkt, &index, ((len - 16) % 256)); + mopPutChar(pkt, &index, ((len - 16) / 256)); + break; + case TRANS_8023: + index = 12; +#if !defined(__FreeBSD__) + mopPutChar(pkt, &index, ((len - 14) / 256)); + mopPutChar(pkt, &index, ((len - 14) % 256)); +#else + mopPutChar(pkt, &index, ((len - 14) % 256)); + mopPutChar(pkt, &index, ((len - 14) / 256)); +#endif + break; + } + +} diff --git a/package/mopd/src/common/put.h b/package/mopd/src/common/put.h new file mode 100644 index 000000000..68ad04475 --- /dev/null +++ b/package/mopd/src/common/put.h @@ -0,0 +1,48 @@ +/* $NetBSD: put.h,v 1.2 1997/03/25 03:07:34 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: put.h,v 1.2 1997/03/25 03:07:34 thorpej Exp $ + * + */ + +#ifndef _PUT_H_ +#define _PUT_H_ + +__BEGIN_DECLS +void mopPutChar __P((u_char *, int *, u_char)); +void mopPutShort __P((u_char *, int *, u_short)); +void mopPutLong __P((u_char *, int *, u_int32_t)); +void mopPutMulti __P((u_char *, int *, u_char *, int)); +void mopPutTime __P((u_char *, int *, time_t)); +void mopPutHeader __P((u_char *, int *, u_char *, u_char *, u_short, int)); +void mopPutLength __P((u_char *, int, u_short)); +__END_DECLS + +#endif /* _PUT_H_ */ diff --git a/package/mopd/src/common/rc.c b/package/mopd/src/common/rc.c new file mode 100644 index 000000000..2c19d1b89 --- /dev/null +++ b/package/mopd/src/common/rc.c @@ -0,0 +1,322 @@ +/* $NetBSD: rc.c,v 1.2 1997/03/25 03:07:35 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: rc.c,v 1.2 1997/03/25 03:07:35 thorpej Exp $"; +#endif + +#include "os.h" +#include "get.h" +#include "mopdef.h" +#include "print.h" +#include "rc.h" + +void +mopDumpRC(fd, pkt, trans) + FILE *fd; + u_char *pkt; + int trans; +{ + int i,index = 0; + int32_t tmpl; + u_char tmpc,code,control; + u_short len,tmps,moplen; + + len = mopGetLength(pkt, trans); + + switch (trans) { + case TRANS_8023: + index = 22; + moplen = len - 8; + break; + default: + index = 16; + moplen = len; + } + code = mopGetChar(pkt,&index); + /* see above, if (len < 8) then moplen ends up around 65535 */ + if (moplen > len) moplen = len; + + switch (code) { + case MOP_K_CODE_RID: + + tmpc = mopGetChar(pkt,&index); + (void)fprintf(fd,"Reserved : %02x\n",tmpc); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Receipt Nbr : %04x\n",tmps); + + break; + case MOP_K_CODE_BOT: + + if ((moplen == 5)) { + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Verification : %04x\n",tmps); + } else { + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Verification : %08x\n",tmpl); + + tmpc = mopGetChar(pkt,&index); /* Processor */ + (void)fprintf(fd,"Processor : %02x ",tmpc); + mopPrintBPTY(fd, tmpc); (void)fprintf(fd, "\n"); + + control = mopGetChar(pkt,&index); /* Control */ + (void)fprintf(fd,"Control : %02x ",control); + if ((control & (1>>MOP_K_BOT_CNTL_SERVER))) { + (void)fprintf(fd, + "Bootserver Requesting system "); + } else { + (void)fprintf(fd, + "Bootserver System default "); + } + if ((control & (1>>MOP_K_BOT_CNTL_DEVICE))) { + (void)fprintf(fd, + "Bootdevice Specified device"); + } else { + (void)fprintf(fd, + "Bootdevice System default"); + } + (void)fprintf(fd,"\n"); + + if ((control & (1>>MOP_K_BOT_CNTL_DEVICE))) { + tmpc = mopGetChar(pkt,&index);/* Device ID */ + (void)fprintf(fd, + "Device ID : %02x '",tmpc); + for (i = 0; i < ((int) tmpc); i++) { + (void)fprintf(fd,"%c", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"'\n"); + } + + tmpc = mopGetChar(pkt,&index); /* Software ID */ + (void)fprintf(fd,"Software ID : %02x ",tmpc); + if ((tmpc == 0)) { + (void)fprintf(fd,"No software id"); + } + if ((tmpc == 254)) { + (void)fprintf(fd,"Maintenance system"); + tmpc = 0; + } + if ((tmpc == 255)) { + (void)fprintf(fd,"Standard operating system"); + tmpc = 0; + } + if ((tmpc > 0)) { + (void)fprintf(fd,"'"); + for (i = 0; i < ((int) tmpc); i++) { + (void)fprintf(fd,"%c", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"'"); + } + (void)fprintf(fd,"'\n"); + + } + break; + case MOP_K_CODE_SID: + + tmpc = mopGetChar(pkt,&index); /* Reserved */ + (void)fprintf(fd, "Reserved : %02x\n",tmpc); + + tmps = mopGetShort(pkt,&index); /* Receipt # */ + (void)fprintf(fd, "Receipt Nbr : %04x\n",tmpc); + + mopPrintInfo(fd, pkt, &index, moplen, code, trans); + + break; + case MOP_K_CODE_RQC: + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Receipt Nbr : %04x\n",tmps); + + break; + case MOP_K_CODE_CNT: + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Receipt Nbr : %04x %d\n",tmps,tmps); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Last Zeroed : %04x %d\n",tmps,tmps); + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Bytes rec : %08x %d\n",tmpl,tmpl); + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Bytes snd : %08x %d\n",tmpl,tmpl); + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Frames rec : %08x %d\n",tmpl,tmpl); + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Frames snd : %08x %d\n",tmpl,tmpl); + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Mcst Bytes re: %08x %d\n",tmpl,tmpl); + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Mcst Frame re: %08x %d\n",tmpl,tmpl); + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Frame snd,def: %08x %d\n",tmpl,tmpl); + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Frame snd,col: %08x %d\n",tmpl,tmpl); + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Frame snd,mcl: %08x %d\n",tmpl,tmpl); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Snd failure : %04x %d\n",tmps,tmps); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Snd fail reas: %04x ",tmps); + if ((tmps & 1)) (void)fprintf(fd,"Excess col "); + if ((tmps & 2)) (void)fprintf(fd,"Carrier chk fail "); + if ((tmps & 4)) (void)fprintf(fd,"Short circ "); + if ((tmps & 8)) (void)fprintf(fd,"Open circ "); + if ((tmps & 16)) (void)fprintf(fd,"Frm to long "); + if ((tmps & 32)) (void)fprintf(fd,"Rem fail to defer "); + (void)fprintf(fd,"\n"); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Rec failure : %04x %d\n",tmps,tmps); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Rec fail reas: %04x ",tmps); + if ((tmps & 1)) (void)fprintf(fd,"Block chk err "); + if ((tmps & 2)) (void)fprintf(fd,"Framing err "); + if ((tmps & 4)) (void)fprintf(fd,"Frm to long "); + (void)fprintf(fd,"\n"); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Unrec frm dst: %04x %d\n",tmps,tmps); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Data overrun : %04x %d\n",tmps,tmps); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Sys Buf Unava: %04x %d\n",tmps,tmps); + + tmps = mopGetShort(pkt,&index); + (void)fprintf(fd,"Usr Buf Unava: %04x %d\n",tmps,tmps); + + break; + case MOP_K_CODE_RVC: + + tmpl = mopGetLong(pkt,&index); + (void)fprintf(fd,"Verification : %08x\n",tmpl); + + break; + case MOP_K_CODE_RLC: + + /* Empty message */ + + break; + case MOP_K_CODE_CCP: + + tmpc = mopGetChar(pkt,&index); + (void)fprintf(fd, + "Control Flags: %02x Message %d ",tmpc,tmpc & 1); + if ((tmpc & 2)) + (void)fprintf(fd,"Break"); + (void)fprintf(fd,"\n"); + + if (moplen > 2) { +#ifndef SHORT_PRINT + for (i = 0; i < (moplen - 2); i++) { + if ((i % 16) == 0) { + if ((i / 16) == 0) { + (void)fprintf(fd, + "Image Data : %04x ", + moplen-2); + } else { + (void)fprintf(fd, + " "); + } + } + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + if ((i % 16) == 15) + (void)fprintf(fd,"\n"); + } + if ((i % 16) != 15) + (void)fprintf(fd,"\n"); +#else + index = index + moplen - 2; +#endif + } + + break; + case MOP_K_CODE_CRA: + + tmpc = mopGetChar(pkt,&index); + (void)fprintf(fd, + "Control Flags: %02x Message %d ",tmpc,tmpc & 1); + if ((tmpc & 2)) + (void)fprintf(fd,"Cmd Data Lost "); + if ((tmpc & 4)) + (void)fprintf(fd,"Resp Data Lost "); + (void)fprintf(fd,"\n"); + + if (moplen > 2) { +#ifndef SHORT_PRINT + for (i = 0; i < (moplen - 2); i++) { + if ((i % 16) == 0) { + if ((i / 16) == 0) { + (void)fprintf(fd, + "Image Data : %04x ", + moplen-2); + } else { + (void)fprintf(fd, + " "); + } + } + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + if ((i % 16) == 15) + (void)fprintf(fd,"\n"); + } + if ((i % 16) != 15) + (void)fprintf(fd,"\n"); +#else + index = index + moplen - 2; +#endif + } + + break; + default: + break; + } +} + diff --git a/package/mopd/src/common/rc.h b/package/mopd/src/common/rc.h new file mode 100644 index 000000000..a79a61e37 --- /dev/null +++ b/package/mopd/src/common/rc.h @@ -0,0 +1,42 @@ +/* $NetBSD: rc.h,v 1.2 1997/03/25 03:07:36 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: rc.h,v 1.2 1997/03/25 03:07:36 thorpej Exp $ + * + */ + +#ifndef _RC_H_ +#define _RC_H_ + +__BEGIN_DECLS +void mopDumpRC __P((FILE *, u_char *, int)); +__END_DECLS + +#endif _RC_H_ diff --git a/package/mopd/src/mopa.out/Makefile b/package/mopd/src/mopa.out/Makefile new file mode 100644 index 000000000..9366f85f1 --- /dev/null +++ b/package/mopd/src/mopa.out/Makefile @@ -0,0 +1,5 @@ +# $NetBSD: Makefile,v 1.4 1997/04/17 21:09:02 christos Exp $ + +PROG= mopa.out + +.include diff --git a/package/mopd/src/mopa.out/mopa.out.1 b/package/mopd/src/mopa.out/mopa.out.1 new file mode 100644 index 000000000..ba8d47b0d --- /dev/null +++ b/package/mopd/src/mopa.out/mopa.out.1 @@ -0,0 +1,58 @@ +.\" $NetBSD: mopa.out.1,v 1.2 1997/03/25 03:07:39 thorpej Exp $ +.\" +.\" Copyright (c) 1996 Mats O Jansson. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Mats O Jansson. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd August 11, 1996 +.Dt MOPA.OUT 1 +.Sh NAME +.Nm mopa.out +.Nd Create MOP image from a a.out file +.Sh SYNOPSIS +.Nm +.Ar infile +.Ar outfile +.Sh DESCRIPTION +.Nm +is used to convert an a.out file to a MOP-image. +.Pp +This program will check if +.Xr a.out 5 +machine-id is recognized. If not it will try to swap the +.Xr a.out 5 +header, and try again. +.Sh BUGS +This program only supports the VAX machine-id for now. +.Sh SEE ALSO +.Xr a.out 5 , +.Xr mopchk 1 , +.Xr mopd 8 , +.Xr mopprobe 1 , +.Xr moptrace 1 +.Sh AUTHORS +Lloyd Parkes. + diff --git a/package/mopd/src/mopa.out/mopa.out.c b/package/mopd/src/mopa.out/mopa.out.c new file mode 100644 index 000000000..177e8116a --- /dev/null +++ b/package/mopd/src/mopa.out/mopa.out.c @@ -0,0 +1,147 @@ +/* $NetBSD: mopa.out.c,v 1.5 1997/10/16 23:25:09 lukem Exp $ */ + +/* mopa.out - Convert a Unix format kernel into something that + * can be transfered via MOP. + * + * This code was written while refering to the NetBSD/vax boot + * loader. Therefore anything that can be booted by the Vax + * should be convertable with this program. + * + * If necessary, the a.out header is stripped, and the program + * segments are padded out. The BSS segment is zero filled. + * A header is prepended that looks like an IHD header. In + * particular the Unix mahine ID is placed where mopd expects + * the image type to be (offset is IHD_W_ALIAS). If the machine + * ID could be mistaken for a DEC image type, then the conversion + * is aborted. The original a.out header is copied into the front + * of the header so that once we have detected the Unix machine + * ID we can haul the load address and the xfer address out. + */ + +/* + * Copyright (c) 1996 Lloyd Parkes. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Lloyd Parkes. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: mopa.out.c,v 1.5 1997/10/16 23:25:09 lukem Exp $"); +#endif + +#include "os.h" +#include "common/common.h" +#include "common/mopdef.h" +#include "common/file.h" +#if defined(__NetBSD__) || defined(__OpenBSD__) +#include +#endif +#if defined(__FreeBSD__) +#include +#endif +#if defined(__bsdi__) || defined(__Linux__) +#include +#define NOAOUT +#endif +#if !defined(MID_VAX) +#define MID_VAX 140 +#endif + +u_char header[512]; /* The VAX header we generate is 1 block. */ +struct exec ex, ex_swap; + +int +main (int argc, char **argv) +{ + FILE *out; /* A FILE because that is easier. */ + int i; + struct dllist dl; + + extern char *__progname; /* from crt0.o */ + +#ifdef NOAOUT + errx(1, "has no function in NetBSD"); +#endif + + if (argc != 3) { + fprintf (stderr, "usage: %s kernel-in sys-out\n", __progname); + return (1); + } + + dl.ldfd = open (argv[1], O_RDONLY); + if (dl.ldfd == -1) + err(2, "open `%s'", argv[1]); + + GetFileInfo(dl.ldfd, + &dl.loadaddr, + &dl.xferaddr, + &dl.aout, + &dl.a_text,&dl.a_text_fill, + &dl.a_data,&dl.a_data_fill, + &dl.a_bss ,&dl.a_bss_fill ); + + if (dl.aout == -1) + errx(3, "`%s' is not an a.out file", argv[1]); + + if (dl.aout != MID_VAX) + printf("WARNING: `%s' is not a VAX image (mid=%d)\n", + argv[1], dl.aout); + + i = dl.a_text + dl.a_text_fill + dl.a_data + dl.a_data_fill + + dl.a_bss + dl.a_bss_fill; + i = (i+1) / 512; + + dl.nloadaddr = dl.loadaddr; + dl.lseek = lseek(dl.ldfd,0L,SEEK_CUR); + dl.a_lseek = 0; + dl.count = 0; + dl.dl_bsz = 512; + + mopFilePutLX(header,IHD_W_SIZE,0xd4,2); /* Offset to ISD section. */ + mopFilePutLX(header,IHD_W_ACTIVOFF,0x30,2);/* Offset to 1st section.*/ + mopFilePutLX(header,IHD_W_ALIAS,IHD_C_NATIVE,2);/* It's a VAX image.*/ + mopFilePutLX(header,IHD_B_HDRBLKCNT,1,1); /* Only one header block. */ + mopFilePutLX(header,0x30+IHA_L_TFRADR1,dl.xferaddr,4); /* Xfer Addr */ + mopFilePutLX(header,0xd4+ISD_W_PAGCNT,i,2);/* Imagesize in blks.*/ + + out = fopen (argv[2], "w"); + if (!out) + err(2, "writing `%s'", argv[2]); + + /* Now we do the actual work. Write VAX MOP-image header */ + + fwrite (header, sizeof (header), 1, out); + + fprintf(stderr, "copying %u+%u+%u->%u\n", dl.a_text, + dl.a_data, dl.a_bss, dl.xferaddr); + + while ((i = mopFileRead(&dl,header)) > 0) { + (void)fwrite(header, i, 1, out); + } + + fclose (out); + return (0); +} diff --git a/package/mopd/src/mopchk/Makefile b/package/mopd/src/mopchk/Makefile new file mode 100644 index 000000000..3aef3c10c --- /dev/null +++ b/package/mopd/src/mopchk/Makefile @@ -0,0 +1,23 @@ +OBJS=mopchk.o +INCL=-I../ -I../common +LIBS=../common/libcommon.a + +all: mopchk + +mopchk: ${OBJS} version.o $(LIBS) + $(CC) -o mopchk version.o ${OBJS} ${LIBS} + +.c.o: .c + $(CC) -c $(CFLAGS) ${INCL} $< + +clean: + rm -f *.o *~ mopchk VERSION version.* + +version.o: version.c +version.c version.h: + ln -sf ../common/VERSION VERSION + rm -f version.c ; sed 's/.*/char version[] = "&";/' VERSION > version.c + set `sed 's/\([0-9]*\)\.\([0-9]*\).*/\1 \2/' VERSION` ; \ + { echo '#define VERSION_MAJOR' $$1 ; \ + echo '#define VERSION_MINOR' $$2 ; } > version.h + diff --git a/package/mopd/src/mopchk/mopchk.1 b/package/mopd/src/mopchk/mopchk.1 new file mode 100644 index 000000000..ed6ba06a8 --- /dev/null +++ b/package/mopd/src/mopchk/mopchk.1 @@ -0,0 +1,64 @@ +.\" $NetBSD: mopchk.1,v 1.4 1998/09/30 15:05:01 briggs Exp $ +.\" +.\" Copyright (c) 1996 Mats O Jansson. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Mats O Jansson. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd October 2, 1995 +.Dt MOPCHK 1 +.Sh NAME +.Nm mopchk +.Nd MOP Check Utility +.Sh SYNOPSIS +.Nm +.Op Fl a +.Op Fl v +.Op Ar filename +.Sh DESCRIPTION +.Nm +shows information about which devices are known, version of mopd suite or +information about a MOP-image. +.Pp +If +.Ar filename +is given, information about the MOP-image is read from the header of the +file. +.Sh OPTIONS +.Bl -tag -width indent +.It Fl a +Show all the Ethernets attached to the system. +.It Fl v +Show version of the mopd suite. +.El +.Sh BUGS +In some implementations the same interface can occur more than once. +.Sh SEE ALSO +.Xr mopa.out 1 , +.Xr mopprobe 1 , +.Xr moptrace 1 , +.Xr mopd 8 +.Sh AUTHORS +Mats O Jansson (moj@stacken.kth.se). diff --git a/package/mopd/src/mopchk/mopchk.c b/package/mopd/src/mopchk/mopchk.c new file mode 100644 index 000000000..3905b79bc --- /dev/null +++ b/package/mopd/src/mopchk/mopchk.c @@ -0,0 +1,167 @@ +/* $NetBSD: mopchk.c,v 1.5 1997/10/16 07:36:50 lukem Exp $ */ + +/* + * Copyright (c) 1995-96 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +/*__RCSID("$NetBSD: mopchk.c,v 1.5 1997/10/16 07:36:50 lukem Exp $");*/ +#endif + +/* + * mopchk - MOP Check Utility + * + * Usage: mopchk [-a] [-v] [filename...] + */ + +#include "os.h" +#include "common/common.h" +#include "common/device.h" +#include "common/file.h" +#include "common/mopdef.h" +#include "common/pf.h" + +/* + * The list of all interfaces that are being listened to. rarp_loop() + * "selects" on the descriptors in this list. + */ +struct if_info *iflist; + +void Usage __P((void)); +int main __P((int, char **)); +void mopProcess __P((struct if_info *, u_char *)); + +int AllFlag = 0; /* listen on "all" interfaces */ +int VersionFlag = 0; /* Show version */ +int promisc = 0; /* promisc mode not needed */ + +extern char *__progname; /* from crt0.o */ +extern char version[]; + +int +main(argc, argv) + int argc; + char **argv; +{ + int op, i, fd; + char *filename; + struct if_info *ii; + int err, aout; + + /* All error reporting is done through syslogs. */ + openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON); + + opterr = 0; + while ((op = getopt(argc, argv, "av")) != -1) { + switch (op) { + case 'a': + AllFlag++; + break; + case 'v': + VersionFlag++; + break; + default: + Usage(); + /* NOTREACHED */ + } + } + + if (VersionFlag) + printf("%s: Version %s\n", __progname, version); + + if (AllFlag) { + if (VersionFlag) + printf("\n"); + iflist = NULL; + deviceInitAll(); + if (iflist == NULL) + printf("No interface\n"); + else { + printf("Interface Address\n"); + for (ii = iflist; ii; ii = ii->next) + printf("%-9s %x:%x:%x:%x:%x:%x\n", + ii->if_name, ii->eaddr[0], ii->eaddr[1], + ii->eaddr[2], ii->eaddr[3], ii->eaddr[4], + ii->eaddr[5]); + } + } + + if (VersionFlag || AllFlag) + i = 1; + else + i = 0; + + while (argc > optind) { + if (i) printf("\n"); + i++; + filename = argv[optind++]; + printf("Checking: %s\n", filename); + fd = open(filename, O_RDONLY, 0); + if (fd == -1) + printf("Unknown file.\n"); + else { + err = CheckAOutFile(fd); + if (err == 0) { + if (GetAOutFileInfo(fd, 0, 0, 0, 0, + 0, 0, 0, 0, &aout) < 0) { + printf( + "Some failure in GetAOutFileInfo\n"); + aout = -1; + } + } else + aout = -1; + if (aout == -1) + err = CheckMopFile(fd); + if (aout == -1 && err == 0) + if (GetMopFileInfo(fd, 0, 0) < 0) + printf( + "Some failure in GetMopFileInfo\n"); + } + } + return (0); +} + +void +Usage() +{ + (void) fprintf(stderr, "usage: %s [-a] [-v] [filename...]\n", + __progname); + exit(1); +} + +/* + * Process incomming packages. + * Doesn't actually do anything for mopchk(1) + */ +void +mopProcess(ii, pkt) + struct if_info *ii; + u_char *pkt; +{ +} diff --git a/package/mopd/src/mopd/Makefile b/package/mopd/src/mopd/Makefile new file mode 100644 index 000000000..1f88c946e --- /dev/null +++ b/package/mopd/src/mopd/Makefile @@ -0,0 +1,24 @@ +CC?= +OBJS=mopd.o process.o +INCL=-I../ -I../common +LIBS=../common/libcommon.a + +all: mopd + +mopd: ${OBJS} version.o $(LIBS) + $(CC) -o mopd version.o ${OBJS} ${LIBS} + +.c.o: .c + $(CC) -c $(CFLAGS) ${INCL} $< + +clean: + rm -f *.o *~ mopd VERSION version.* + +version.o: version.c +version.c version.h: + ln -sf ../common/VERSION VERSION + rm -f version.c ; sed 's/.*/char version[] = "&";/' VERSION > version.c + set `sed 's/\([0-9]*\)\.\([0-9]*\).*/\1 \2/' VERSION` ; \ + { echo '#define VERSION_MAJOR' $$1 ; \ + echo '#define VERSION_MINOR' $$2 ; } > version.h + diff --git a/package/mopd/src/mopd/TODO b/package/mopd/src/mopd/TODO new file mode 100644 index 000000000..720b58d75 --- /dev/null +++ b/package/mopd/src/mopd/TODO @@ -0,0 +1 @@ +Change code to send hostname instead of 'ipc'. diff --git a/package/mopd/src/mopd/mopd.8 b/package/mopd/src/mopd/mopd.8 new file mode 100644 index 000000000..41163ed60 --- /dev/null +++ b/package/mopd/src/mopd/mopd.8 @@ -0,0 +1,109 @@ +.\" $NetBSD: mopd.8,v 1.2 1997/03/25 03:07:48 thorpej Exp $ +.\" +.\" Copyright (c) 1993-96 Mats O Jansson. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Mats O Jansson. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd September 24, 1995 +.Dt MOPD 8 +.Sh NAME +.Nm mopd +.Nd MOP Loader Daemon +.Sh SYNOPSIS +.Nm +.Op Fl adf +.Op Ar interface +.Sh DESCRIPTION +.Nm +services MOP Load requests on the Ethernet connected to +.Ar interface +or all interfaces if +.Sq Fl a +is given. +In a load request received by +.Nm +a filename can be given. This is the normal case for e.g. terminal servers. +If a filename isn't given +.Nm +must know what image to load. +.Pp +Upon receiving a request, +.Nm +checks if the requested file exists in +.Pa /tftpboot/mop , +the filename is normaly uppercase and with an extension of +.Pa .SYS . +If the filename isn't given, the ethernet address of the target is used as +filename, e.g. +.Pa 08002b09f4de.SYS +and it might be a soft link to another file. +.Pp +.Nm +supports two kinds of files. The first type that is check is if the file is +in +.Xr a.out 5 +format. If not, a couple of Digital's formats are checked. +.Pp +In normal operation, +.Nm +forks a copy of itself and runs in +the background. Anomalies and errors are reported via +.Xr syslog 3 . +.Sh OPTIONS +.Bl -tag -width indent +.It Fl a +Listen on all the Ethernets attached to the system. +If +.Sq Fl a +is omitted, an interface must be specified. +.It Fl d +Run in debug mode, with all the output to stdout. The process will run in +the foreground. +.It Fl f +Run in the foreground. +.El +.Sh FILES +.Bl -tag -width Pa -compact +.It Pa /tftpboot/mop +.El +.Sh SEE ALSO +.Xr bpf 4 , +.Xr mopa.out 1 , +.Xr mopchk 1 , +.Xr mopprobe 1 , +.Xr moptrace 1 +.Rs +DECnet Digital Network Architecture Phase IV, +.%R Maintenance Operations Functional Specification V3.0.0 +.%N AA-X436A-TK +.Re +.Rs +DECnet Digital Network Architecture, +.%R Maintenance Operations Protocol Functional Specification V4.0.0 +.%N EK-DNA11-FS-001 +.Re +.Sh AUTHORS +Mats O Jansson (moj@stacken.kth.se). diff --git a/package/mopd/src/mopd/mopd.c b/package/mopd/src/mopd/mopd.c new file mode 100644 index 000000000..2de83d0f0 --- /dev/null +++ b/package/mopd/src/mopd/mopd.c @@ -0,0 +1,216 @@ +/* $NetBSD: mopd.c,v 1.5 1997/10/16 23:25:17 lukem Exp $ */ + +/* + * Copyright (c) 1993-96 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +/*__RCSID("$NetBSD: mopd.c,v 1.5 1997/10/16 23:25:17 lukem Exp $");*/ +#endif + +/* + * mopd - MOP Dump/Load Daemon + * + * Usage: mopd -a [ -d -f -v ] [ -3 | -4 ] + * mopd [ -d -f -v ] [ -3 | -4 ] interface + */ + +#include "common/os.h" +#include "common/cmp.h" +#include "common/common.h" +#include "common/device.h" +#include "common/dl.h" +#include "common/get.h" +#include "common/mopdef.h" +#include "common/pf.h" +#include "common/print.h" +#include "process.h" +#include "common/rc.h" + +#ifndef __linux__ +#include +#else +#define pidfile(x) x; +#endif + +/* + * The list of all interfaces that are being listened to. + * "selects" on the descriptors in this list. + */ +struct if_info *iflist; + +void Usage __P((void)); +int main __P((int, char **)); +void mopProcess __P((struct if_info *, u_char *)); + +int AllFlag = 0; /* listen on "all" interfaces */ +int DebugFlag = 0; /* print debugging messages */ +int ForegroundFlag = 0; /* run in foreground */ +int VersionFlag = 0; /* print version */ +int Not3Flag = 0; /* Not MOP V3 messages. */ +int Not4Flag = 0; /* Not MOP V4 messages. */ +int promisc = 1; /* Need promisc mode */ + +extern char *__progname; /* from crt0.o */ + +int +main(argc, argv) + int argc; + char **argv; +{ + int c, pid; + char *interface; + + extern char version[]; + + while ((c = getopt(argc, argv, "34adfv")) != -1) + switch (c) { + case '3': + Not3Flag++; + break; + case '4': + Not4Flag++; + break; + case 'a': + AllFlag++; + break; + case 'd': + DebugFlag++; + break; + case 'f': + ForegroundFlag++; + break; + case 'v': + VersionFlag++; + break; + default: + Usage(); + /* NOTREACHED */ + } + + if (VersionFlag) { + fprintf(stdout,"%s: version %s\n", __progname, version); + exit(0); + } + + interface = argv[optind++]; + + if ((AllFlag && interface) || + (!AllFlag && interface == 0) || + (argc > optind) || + (Not3Flag && Not4Flag)) + Usage(); + + /* All error reporting is done through syslogs. */ + openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON); + + if ((!ForegroundFlag) && DebugFlag) + fprintf(stdout, + "%s: not running as daemon, -d given.\n", __progname); + + if ((!ForegroundFlag) && (!DebugFlag)) { + pid = fork(); + if (pid > 0) + /* Parent exits, leaving child in background. */ + exit(0); + else + if (pid == -1) { + syslog(LOG_ERR, "cannot fork"); + exit(0); + } + + /* Fade into the background */ + daemon(0, 0); + pidfile(NULL); + } + + syslog(LOG_INFO, "%s %s started.", __progname, version); + + if (AllFlag) + deviceInitAll(); + else + deviceInitOne(interface); + + Loop(); + /* NOTREACHED */ + return (0); +} + +void +Usage() +{ + (void) fprintf(stderr, "usage: %s -a [ -d -f -v ] [ -3 | -4 ]\n", + __progname); + (void) fprintf(stderr, " %s [ -d -f -v ] [ -3 | -4 ] interface\n", + __progname); + exit(1); +} + +/* + * Process incomming packages. + */ +void +mopProcess(ii, pkt) + struct if_info *ii; + u_char *pkt; +{ + u_char *dst, *src; + u_short ptype; + int index, trans, len; + + /* We don't known with transport, Guess! */ + + trans = mopGetTrans(pkt, 0); + + /* Ok, return if we don't wan't this message */ + + if ((trans == TRANS_ETHER) && Not3Flag) return; + if ((trans == TRANS_8023) && Not4Flag) return; + + index = 0; + mopGetHeader(pkt, &index, &dst, &src, &ptype, &len, trans); + + /* + * Ignore our own transmissions + * + */ + if (mopCmpEAddr(ii->eaddr,src) == 0) + return; + + switch(ptype) { + case MOP_K_PROTO_DL: + mopProcessDL(stdout, ii, pkt, &index, dst, src, trans, len); + break; + case MOP_K_PROTO_RC: + mopProcessRC(stdout, ii, pkt, &index, dst, src, trans, len); + break; + default: + break; + } +} diff --git a/package/mopd/src/mopd/process.c b/package/mopd/src/mopd/process.c new file mode 100644 index 000000000..4656e027a --- /dev/null +++ b/package/mopd/src/mopd/process.c @@ -0,0 +1,684 @@ +/* $NetBSD: process.c,v 1.7 2000/06/27 18:57:41 ragge Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: process.c,v 1.7 2000/06/27 18:57:41 ragge Exp $"; +#endif + +#include "os.h" +#include "cmp.h" +#include "common.h" +#include "dl.h" +#include "file.h" +#include "get.h" +#include "mopdef.h" +#include "nmadef.h" +#include "pf.h" +#include "print.h" +#include "put.h" +#include "rc.h" + +#ifdef SEND_REAL_HOSTNAME +#include /* for getting the hostname */ +#endif +#include /* for getting MAXHOSTNAMELEN */ + +extern u_char buf[]; +extern int DebugFlag; + +struct dllist dllist[MAXDL]; /* dump/load list */ +extern char dl_mcst[]; /* Dump/Load Multicast */ +extern char rc_mcst[]; /* Remote Console Multicast */ + +void mopNextLoad __P((u_char *, u_char *, u_char, int)); +void mopProcessDL __P((FILE *, struct if_info *, u_char *, int *, + u_char *, u_char *, int, u_short)); +void mopProcessRC __P((FILE *, struct if_info *, u_char *, int *, + u_char *, u_char *, int, u_short)); +void mopProcessInfo __P((u_char *, int *, u_short, struct dllist *, int)); +void mopSendASV __P((u_char *, u_char *, struct if_info *, int)); +void mopStartLoad __P((u_char *, u_char *, struct dllist *, int)); + +void +mopProcessInfo(pkt, index, moplen, dl_rpr, trans) + u_char *pkt; + int *index; + u_short moplen; + struct dllist *dl_rpr; + int trans; +{ + u_short itype,tmps; + u_char ilen ,tmpc,device; + u_char uc1,uc2,uc3,*ucp; + + device = 0; + + switch(trans) { + case TRANS_ETHER: + moplen = moplen + 16; + break; + case TRANS_8023: + moplen = moplen + 14; + break; + } + + itype = mopGetShort(pkt,index); + + while (*index < (int)(moplen)) { + ilen = mopGetChar(pkt,index); + switch (itype) { + case 0: + tmpc = mopGetChar(pkt,index); + *index = *index + tmpc; + break; + case MOP_K_INFO_VER: + uc1 = mopGetChar(pkt,index); + uc2 = mopGetChar(pkt,index); + uc3 = mopGetChar(pkt,index); + break; + case MOP_K_INFO_MFCT: + tmps = mopGetShort(pkt,index); + break; + case MOP_K_INFO_CNU: + ucp = pkt + *index; *index = *index + 6; + break; + case MOP_K_INFO_RTM: + tmps = mopGetShort(pkt,index); + break; + case MOP_K_INFO_CSZ: + tmps = mopGetShort(pkt,index); + break; + case MOP_K_INFO_RSZ: + tmps = mopGetShort(pkt,index); + break; + case MOP_K_INFO_HWA: + ucp = pkt + *index; *index = *index + 6; + break; + case MOP_K_INFO_TIME: + ucp = pkt + *index; *index = *index + 10; + break; + case MOP_K_INFO_SOFD: + device = mopGetChar(pkt,index); + break; + case MOP_K_INFO_SFID: + tmpc = mopGetChar(pkt,index); + ucp = pkt + *index; *index = *index + tmpc; + break; + case MOP_K_INFO_PRTY: + tmpc = mopGetChar(pkt,index); + break; + case MOP_K_INFO_DLTY: + tmpc = mopGetChar(pkt,index); + break; + case MOP_K_INFO_DLBSZ: + tmps = mopGetShort(pkt,index); + dl_rpr->dl_bsz = tmps; + break; + default: + if (((device = NMA_C_SOFD_LCS) || /* DECserver 100 */ + (device = NMA_C_SOFD_DS2) || /* DECserver 200 */ + (device = NMA_C_SOFD_DP2) || /* DECserver 250 */ + (device = NMA_C_SOFD_DS3)) && /* DECserver 300 */ + ((itype > 101) && (itype < 107))) + { + switch (itype) { + case 102: + ucp = pkt + *index; + *index = *index + ilen; + break; + case 103: + ucp = pkt + *index; + *index = *index + ilen; + break; + case 104: + tmps = mopGetShort(pkt,index); + break; + case 105: + ucp = pkt + *index; + *index = *index + ilen; + break; + case 106: + ucp = pkt + *index; + *index = *index + ilen; + break; + }; + } else { + ucp = pkt + *index; *index = *index + ilen; + }; + } + itype = mopGetShort(pkt,index); + } +} + +void +mopSendASV(dst, src, ii, trans) + u_char *dst,*src; + struct if_info *ii; + int trans; +{ + u_char pkt[200], *p; + int index; + u_char mopcode = MOP_K_CODE_ASV; + u_short newlen = 0,ptype = MOP_K_PROTO_DL; + + index = 0; + mopPutHeader(pkt, &index, dst, src, ptype, trans); + + p = &pkt[index]; + mopPutChar(pkt,&index,mopcode); + + mopPutLength(pkt, trans, index); + newlen = mopGetLength(pkt, trans); + + if ((DebugFlag == DEBUG_ONELINE)) { + mopPrintOneline(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_HEADER)) { + mopPrintHeader(stdout, pkt, trans); + mopPrintMopHeader(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_INFO)) { + mopDumpDL(stdout, pkt, trans); + } + + if (pfWrite(ii->fd, pkt, index, trans) != index) { + if (DebugFlag) { + (void)fprintf(stderr, "error pfWrite()\n"); + } + } +} + +#define MAX_ETH_PAYLOAD 1492 + +void +mopStartLoad(dst, src, dl_rpr, trans) + u_char *dst,*src; + struct dllist *dl_rpr; + int trans; +{ + int len; + int i, slot; + u_char pkt[BUFSIZE], *p; + int index; + u_char mopcode = MOP_K_CODE_MLD; + u_short newlen,ptype = MOP_K_PROTO_DL; + + slot = -1; + + /* Look if we have a non terminated load, if so, use it's slot */ + + for (i = 0; i < MAXDL; i++) { + if (dllist[i].status != DL_STATUS_FREE) { + if (mopCmpEAddr(dllist[i].eaddr,dst) == 0) { + slot = i; + } + } + } + + /* If no slot yet, then find first free */ + + if (slot == -1) { + for (i = 0; i < MAXDL; i++) { + if (dllist[i].status == DL_STATUS_FREE) { + if (slot == -1) { + slot = i; + memmove((char *)dllist[i].eaddr, + (char *)dst, 6); + } + } + } + } + + /* If no slot yet, then return. No slot is free */ + + if (slot == -1) + return; + + /* Ok, save info from RPR */ + + dllist[slot] = *dl_rpr; + dllist[slot].status = DL_STATUS_READ_IMGHDR; + + /* Get Load and Transfer Address. */ + + GetFileInfo(dllist[slot].ldfd, + &dllist[slot].loadaddr, + &dllist[slot].xferaddr, + &dllist[slot].aout, + &dllist[slot].a_text, &dllist[slot].a_text_fill, + &dllist[slot].a_data, &dllist[slot].a_data_fill, + &dllist[slot].a_bss, &dllist[slot].a_bss_fill); + + dllist[slot].nloadaddr = dllist[slot].loadaddr; + dllist[slot].lseek = lseek(dllist[slot].ldfd,0L,SEEK_CUR); + dllist[slot].a_lseek = 0; + + dllist[slot].count = 0; + if (dllist[slot].dl_bsz >= MAX_ETH_PAYLOAD || dllist[slot].dl_bsz == 0) + dllist[slot].dl_bsz = MAX_ETH_PAYLOAD; + if (dllist[slot].dl_bsz == 1030) /* VS/uVAX 2000 needs this */ + dllist[slot].dl_bsz = 1000; + if (dllist[slot].dl_bsz == 0) /* Needed by "big" VAXen */ + dllist[slot].dl_bsz = MAX_ETH_PAYLOAD; + if (trans == TRANS_8023) + dllist[slot].dl_bsz = dllist[slot].dl_bsz - 8; + + index = 0; + mopPutHeader(pkt, &index, dst, src, ptype, trans); + p = &pkt[index]; + mopPutChar (pkt,&index,mopcode); + + mopPutChar (pkt,&index,dllist[slot].count); + mopPutLong (pkt,&index,dllist[slot].loadaddr); + + len = mopFileRead(&dllist[slot],&pkt[index]); + + dllist[slot].nloadaddr = dllist[slot].loadaddr + len; + index = index + len; + + mopPutLength(pkt, trans, index); + newlen = mopGetLength(pkt, trans); + + if ((DebugFlag == DEBUG_ONELINE)) { + mopPrintOneline(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_HEADER)) { + mopPrintHeader(stdout, pkt, trans); + mopPrintMopHeader(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_INFO)) { + mopDumpDL(stdout, pkt, trans); + } + + if (pfWrite(dllist[slot].ii->fd, pkt, index, trans) != index) { + if (DebugFlag) { + (void)fprintf(stderr, "error pfWrite()\n"); + } + } + + dllist[slot].status = DL_STATUS_SENT_MLD; +} + +void +mopNextLoad(dst, src, new_count, trans) + u_char *dst,*src,new_count; + int trans; +{ + int len; + int i, slot; + u_char pkt[BUFSIZE], *p; + int index, pindex; + char line[100]; + u_short newlen = 0,ptype = MOP_K_PROTO_DL; + u_char mopcode; + +#ifdef SEND_REAL_HOSTNAME + struct utsname uts_name; +#endif + char hostname[MAXHOSTNAMELEN]; + + slot = -1; + + for (i = 0; i < MAXDL; i++) { + if (dllist[i].status != DL_STATUS_FREE) { + if (mopCmpEAddr(dst,dllist[i].eaddr) == 0) + slot = i; + } + } + + /* If no slot yet, then return. No slot is free */ + + if (slot == -1) + return; + + if ((new_count == ((dllist[slot].count+1) % 256))) { + dllist[slot].loadaddr = dllist[slot].nloadaddr; + dllist[slot].count = new_count; + } else { + return; + } + + if (dllist[slot].status == DL_STATUS_SENT_PLT) { + close(dllist[slot].ldfd); + dllist[slot].ldfd = 0; + dllist[slot].status = DL_STATUS_FREE; + sprintf(line, + "%x:%x:%x:%x:%x:%x Load completed", + dst[0],dst[1],dst[2],dst[3],dst[4],dst[5]); + syslog(LOG_INFO, "%s", line); + return; + } + + dllist[slot].lseek = lseek(dllist[slot].ldfd,0L,SEEK_CUR); + + if (dllist[slot].dl_bsz >= MAX_ETH_PAYLOAD) + dllist[slot].dl_bsz = MAX_ETH_PAYLOAD; + + index = 0; + mopPutHeader(pkt, &index, dst, src, ptype, trans); + p = &pkt[index]; + mopcode = MOP_K_CODE_MLD; + pindex = index; + mopPutChar (pkt,&index,mopcode); + mopPutChar (pkt,&index,dllist[slot].count); + mopPutLong (pkt,&index,dllist[slot].loadaddr); + + len = mopFileRead(&dllist[slot],&pkt[index]); + + if (len > 0 ) { + + dllist[slot].nloadaddr = dllist[slot].loadaddr + len; + index = index + len; + + mopPutLength(pkt, trans, index); + newlen = mopGetLength(pkt, trans); + + } else { + if (len == 0) { + +#ifdef SEND_REAL_HOSTNAME + /* get the proper hostname. use 'DEFAULT_HOSTNAME' on failure */ + if(uname(&uts_name) < 0){ + syslog(LOG_ERR,"uname() failed with errno: %d. using '%s' as hostname\n",errno,DEFAULT_HOSTNAME); + sprintf(hostname, "%s", DEFAULT_HOSTNAME); + } + else{ + sprintf(hostname, "%s", uts_name.nodename); + } +#else + sprintf(hostname,"%s",DEFAULT_HOSTNAME); +#endif + syslog(LOG_INFO,"hostname: [%s] len: %d\n",hostname,strlen(hostname)); + index = pindex; + mopcode = MOP_K_CODE_PLT; + mopPutChar (pkt,&index,mopcode); + mopPutChar (pkt,&index,dllist[slot].count); + mopPutChar (pkt,&index,MOP_K_PLTP_HSN); + mopPutChar (pkt,&index,strlen(hostname)); + mopPutMulti(pkt,&index,hostname,strlen(hostname)); + mopPutChar (pkt,&index,MOP_K_PLTP_HSA); + mopPutChar (pkt,&index,6); + mopPutMulti(pkt,&index,src,6); + mopPutChar (pkt,&index,MOP_K_PLTP_HST); + mopPutTime (pkt,&index, 0); + mopPutChar (pkt,&index,0); + mopPutLong (pkt,&index,dllist[slot].xferaddr); + + mopPutLength(pkt, trans, index); + newlen = mopGetLength(pkt, trans); + + dllist[slot].status = DL_STATUS_SENT_PLT; + } else { + dllist[slot].status = DL_STATUS_FREE; + return; + } + } + + if ((DebugFlag == DEBUG_ONELINE)) { + mopPrintOneline(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_HEADER)) { + mopPrintHeader(stdout, pkt, trans); + mopPrintMopHeader(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_INFO)) { + mopDumpDL(stdout, pkt, trans); + } + + if (pfWrite(dllist[slot].ii->fd, pkt, index, trans) != index) { + if (DebugFlag) { + (void)fprintf(stderr, "error pfWrite()\n"); + } + } +} + +void +mopProcessDL(fd, ii, pkt, index, dst, src, trans, len) + FILE *fd; + struct if_info *ii; + u_char *pkt; + int *index; + u_char *dst, *src; + int trans; + u_short len; +{ + u_char tmpc; + u_short moplen; + u_char pfile[129], mopcode; + char filename[FILENAME_MAX]; + char line[100]; + int i,nfd,iindex; + struct dllist dl,*dl_rpr; + u_char rpr_pgty,load; + + if ((DebugFlag == DEBUG_ONELINE)) { + mopPrintOneline(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_HEADER)) { + mopPrintHeader(stdout, pkt, trans); + mopPrintMopHeader(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_INFO)) { + mopDumpDL(stdout, pkt, trans); + } + + moplen = mopGetLength(pkt, trans); + mopcode = mopGetChar(pkt,index); + + switch (mopcode) { + case MOP_K_CODE_MLT: + break; + case MOP_K_CODE_DCM: + break; + case MOP_K_CODE_MLD: + break; + case MOP_K_CODE_ASV: + break; + case MOP_K_CODE_RMD: + break; + case MOP_K_CODE_RPR: + + tmpc = mopGetChar(pkt,index); /* Device Type */ + + tmpc = mopGetChar(pkt,index); /* Format Version */ + if ((tmpc != MOP_K_RPR_FORMAT) && + (tmpc != MOP_K_RPR_FORMAT_V3)) { + (void)fprintf(stderr,"mopd: Unknown RPR Format (%d) from ",tmpc); + mopPrintHWA(stderr,src); + (void)fprintf(stderr,"\n"); + } + + rpr_pgty = mopGetChar(pkt,index); /* Program Type */ + + tmpc = mopGetChar(pkt,index); /* Software ID Len */ + if (tmpc > sizeof(pfile) - 1) + return; + for (i = 0; i < tmpc; i++) { + pfile[i] = mopGetChar(pkt,index); + pfile[i+1] = '\0'; + } + + if (tmpc == 0) { + /* In a normal implementation of a MOP Loader this */ + /* would cause a question to NML (DECnet) if this */ + /* node is known and if so what image to load. But */ + /* we don't have DECnet so we don't have anybody */ + /* to ask. My solution is to use the ethernet addr */ + /* as filename. Implementing a database would be */ + /* overkill. */ + sprintf(pfile,"%02x%02x%02x%02x%02x%02x%c", + src[0],src[1],src[2],src[3],src[4],src[5],0); + } + + tmpc = mopGetChar(pkt,index); /* Processor */ + + iindex = *index; + dl_rpr = &dl; + memset(dl_rpr, 0, sizeof(*dl_rpr)); + dl_rpr->ii = ii; + memmove((char *)(dl_rpr->eaddr), (char *)src, 6); + mopProcessInfo(pkt,index,moplen,dl_rpr,trans); + + sprintf(filename,"%s/%s.SYS", MOP_FILE_PATH, pfile); + if ((mopCmpEAddr(dst,dl_mcst) == 0)) { + if ((nfd = open(filename, O_RDONLY, 0)) != -1) { + close(nfd); + mopSendASV(src, ii->eaddr, ii, trans); + sprintf(line, + "%x:%x:%x:%x:%x:%x (%d) Do you have %s? (Yes)", + src[0],src[1],src[2], + src[3],src[4],src[5],trans,pfile); + } else { + sprintf(line, + "%x:%x:%x:%x:%x:%x (%d) Do you have %s? (No)", + src[0],src[1],src[2], + src[3],src[4],src[5],trans,pfile); + } + syslog(LOG_INFO, "%s", line); + } else { + if ((mopCmpEAddr(dst,ii->eaddr) == 0)) { + dl_rpr->ldfd = open(filename, O_RDONLY, 0); + mopStartLoad(src, ii->eaddr, dl_rpr, trans); + sprintf(line, + "%x:%x:%x:%x:%x:%x Send me %s", + src[0],src[1],src[2], + src[3],src[4],src[5],pfile); + syslog(LOG_INFO, "%s", line); + } + } + + break; + case MOP_K_CODE_RML: + + load = mopGetChar(pkt,index); /* Load Number */ + + tmpc = mopGetChar(pkt,index); /* Error */ + + if ((mopCmpEAddr(dst,ii->eaddr) == 0)) { + mopNextLoad(src, ii->eaddr, load, trans); + } + + break; + case MOP_K_CODE_RDS: + break; + case MOP_K_CODE_MDD: + break; + case MOP_K_CODE_CCP: + break; + case MOP_K_CODE_PLT: + break; + default: + break; + } +} + +void +mopProcessRC(fd, ii, pkt, index, dst, src, trans, len) + FILE *fd; + struct if_info *ii; + u_char *pkt; + int *index; + u_char *dst, *src; + int trans; + u_short len; +{ + u_char tmpc; + u_short tmps, moplen = 0; + u_char mopcode; + struct dllist dl,*dl_rpr; + + if ((DebugFlag == DEBUG_ONELINE)) { + mopPrintOneline(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_HEADER)) { + mopPrintHeader(stdout, pkt, trans); + mopPrintMopHeader(stdout, pkt, trans); + } + + if ((DebugFlag >= DEBUG_INFO)) { + mopDumpRC(stdout, pkt, trans); + } + + moplen = mopGetLength(pkt, trans); + mopcode = mopGetChar(pkt,index); + + switch (mopcode) { + case MOP_K_CODE_RID: + break; + case MOP_K_CODE_BOT: + break; + case MOP_K_CODE_SID: + + tmpc = mopGetChar(pkt,index); /* Reserved */ + + if ((DebugFlag >= DEBUG_INFO)) { + (void)fprintf(stderr, "Reserved : %02x\n",tmpc); + } + + tmps = mopGetShort(pkt,index); /* Receipt # */ + if ((DebugFlag >= DEBUG_INFO)) { + (void)fprintf(stderr, "Receipt Nbr : %04x\n",tmpc); + } + + dl_rpr = &dl; + memset(dl_rpr, 0, sizeof(*dl_rpr)); + dl_rpr->ii = ii; + memmove((char *)(dl_rpr->eaddr), (char *)src, 6); + mopProcessInfo(pkt,index,moplen,dl_rpr,trans); + + break; + case MOP_K_CODE_RQC: + break; + case MOP_K_CODE_CNT: + break; + case MOP_K_CODE_RVC: + break; + case MOP_K_CODE_RLC: + break; + case MOP_K_CODE_CCP: + break; + case MOP_K_CODE_CRA: + break; + default: + break; + } +} + diff --git a/package/mopd/src/mopd/process.h b/package/mopd/src/mopd/process.h new file mode 100644 index 000000000..12bb94419 --- /dev/null +++ b/package/mopd/src/mopd/process.h @@ -0,0 +1,45 @@ +/* $NetBSD: process.h,v 1.2 1997/03/25 03:07:52 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: process.h,v 1.2 1997/03/25 03:07:52 thorpej Exp $ + * + */ + +#ifndef _PROCESS_H_ +#define _PROCESS_H_ + +__BEGIN_DECLS +void mopProcessDL __P((FILE *, struct if_info *, u_char *, int *, + u_char *, u_char *, int, u_short)); +void mopProcessRC __P((FILE *, struct if_info *, u_char *, int *, + u_char *, u_char *, int, u_short)); +__END_DECLS + +#endif _PROCESS_H_ diff --git a/package/mopd/src/mopprobe/Makefile b/package/mopd/src/mopprobe/Makefile new file mode 100644 index 000000000..3b64d5f71 --- /dev/null +++ b/package/mopd/src/mopprobe/Makefile @@ -0,0 +1,23 @@ +OBJS=mopprobe.o +INCL=-I../ -I../common +LIBS=../common/libcommon.a + +all: mopprobe + +mopprobe: ${OBJS} version.o $(LIBS) + $(CC) -o mopprobe version.o ${OBJS} ${LIBS} + +.c.o: .c + $(CC) -c $(CFLAGS) ${INCL} $< + +clean: + rm -f *.o *~ mopprobe VERSION version.* + +version.o: version.c +version.c version.h: + ln -sf ../common/VERSION VERSION + rm -f version.c ; sed 's/.*/char version[] = "&";/' VERSION > version.c + set `sed 's/\([0-9]*\)\.\([0-9]*\).*/\1 \2/' VERSION` ; \ + { echo '#define VERSION_MAJOR' $$1 ; \ + echo '#define VERSION_MINOR' $$2 ; } > version.h + diff --git a/package/mopd/src/mopprobe/mopprobe.1 b/package/mopd/src/mopprobe/mopprobe.1 new file mode 100644 index 000000000..d120a0330 --- /dev/null +++ b/package/mopd/src/mopprobe/mopprobe.1 @@ -0,0 +1,68 @@ +.\" $NetBSD: mopprobe.1,v 1.2 1997/03/25 03:07:56 thorpej Exp $ +.\" +.\" Copyright (c) 1996 Mats O Jansson. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Mats O Jansson. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd October 2, 1995 +.Dt MOPPROBE 1 +.Sh NAME +.Nm mopprobe +.Nd MOP Probe Utility +.Sh SYNOPSIS +.Nm +.Fl a +.Op Fl 3 | 4 +.Nm "" +.Op Fl 3 | 4 +.Ar interface +.Sh DESCRIPTION +.Nm +prints the ethernet address and nodename of MOP SID message on the Ethernet +connected to +.Ar interface +or all known interfaces if +.Sq Fl a +is given. +.Sh OPTIONS +.Bl -tag -width indent +.It Fl a +Listen on all the Ethernets attached to the system. +If +.Sq Fl a +is omitted, an interface must be specified. +.It Fl 3 +Ignore MOP V3 messages (Ethernet II). +.It Fl 4 +Ignore MOP V4 messages (Ethernet 802.3). +.El +.Sh SEE ALSO +.Xr mopa.out 1 , +.Xr mopchk 1 , +.Xr mopd 8 , +.Xr moptrace 8 +.Sh AUTHORS +Mats O Jansson (moj@stacken.kth.se). diff --git a/package/mopd/src/mopprobe/mopprobe.c b/package/mopd/src/mopprobe/mopprobe.c new file mode 100644 index 000000000..fbd398b08 --- /dev/null +++ b/package/mopd/src/mopprobe/mopprobe.c @@ -0,0 +1,283 @@ +/* $NetBSD: mopprobe.c,v 1.4 1997/04/17 21:09:27 christos Exp $ */ + +/* + * Copyright (c) 1993-96 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +/*__RCSID("$NetBSD: mopprobe.c,v 1.4 1997/04/17 21:09:27 christos Exp $");*/ +#endif + +/* + * mopprobe - MOP Probe Utility + * + * Usage: mopprobe -a [ -3 | -4 ] + * mopprobe [ -3 | -4 ] interface + */ + +#include "os.h" +#include "common/cmp.h" +#include "common/common.h" +#include "common/device.h" +#include "common/get.h" +#include "common/mopdef.h" +#include "common/nmadef.h" +#include "common/pf.h" +#include "common/print.h" + +/* + * The list of all interfaces that are being listened to. rarp_loop() + * "selects" on the descriptors in this list. + */ +struct if_info *iflist; + +void Usage __P((void)); +int main __P((int, char **)); +void mopProcess __P((struct if_info *, u_char *)); + +int AllFlag = 0; /* listen on "all" interfaces */ +int DebugFlag = 0; /* print debugging messages */ +int Not3Flag = 0; /* Not MOP V3 messages */ +int Not4Flag = 0; /* Not MOP V4 messages */ +int oflag = 0; /* print only once */ +int promisc = 1; /* Need promisc mode */ + +extern char *__progname; /* from crt0.o */ + +int +main(argc, argv) + int argc; + char **argv; +{ + int op; + char *interface; + + /* All error reporting is done through syslogs. */ + openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON); + + opterr = 0; + while ((op = getopt(argc, argv, "ado")) != -1) { + switch (op) { + case '3': + Not3Flag++; + break; + case '4': + Not4Flag++; + break; + case 'a': + AllFlag++; + break; + case 'd': + DebugFlag++; + break; + case 'o': + oflag++; + break; + + default: + Usage(); + /* NOTREACHED */ + } + } + interface = argv[optind++]; + + if ((AllFlag && interface) || + (!AllFlag && interface == 0) || + (Not3Flag && Not4Flag)) + Usage(); + + if (AllFlag) + deviceInitAll(); + else + deviceInitOne(interface); + + Loop(); + /* NOTREACHED */ + return (0); +} + +void +Usage() +{ + (void) fprintf(stderr, "usage: %s -a [ -3 | -4 ]\n", __progname); + (void) fprintf(stderr, " %s [ -3 | -4 ] interface\n", __progname); + exit(1); +} + +/* + * Process incomming packages. + */ +void +mopProcess(ii, pkt) + struct if_info *ii; + u_char *pkt; +{ + u_char *dst, *src, *p, mopcode, tmpc, ilen; + u_short *ptype, moplen, tmps, itype, len; + int index, i, device, trans; + + dst = pkt; + src = pkt+6; + ptype = (u_short *)(pkt+12); + index = 0; + + if (*ptype < 1600) { + len = *ptype; + trans = TRANS_8023; + ptype = (u_short *)(pkt+20); + p = pkt+22; + if (Not4Flag) return; + } else { + len = 0; + trans = TRANS_ETHER; + p = pkt+14; + if (Not3Flag) return; + } + + /* Ignore our own messages */ + + if (mopCmpEAddr(ii->eaddr,src) == 0) { + return; + } + + /* Just check multicast */ + + if (mopCmpEAddr(rc_mcst,dst) != 0) { + return; + } + + switch (trans) { + case TRANS_8023: + moplen = len; + break; + default: + moplen = mopGetShort(pkt,&index); + } + mopcode = mopGetChar(p,&index); + + /* Just process System Information */ + + if (mopcode != MOP_K_CODE_SID) { + return; + } + + tmpc = mopGetChar(pkt,&index); /* Reserved */ + tmps = mopGetShort(pkt,&index); /* Receipt # */ + + device = 0; /* Unknown Device */ + + itype = mopGetShort(pkt,&index); + + while (index < (int)(moplen + 2)) { + ilen = mopGetChar(pkt,&index); + switch (itype) { + case 0: + tmpc = mopGetChar(pkt,&index); + index = index + tmpc; + break; + case MOP_K_INFO_VER: + index = index + 3; + break; + case MOP_K_INFO_MFCT: + index = index + 2; + break; + case MOP_K_INFO_CNU: + index = index + 6; + break; + case MOP_K_INFO_RTM: + index = index + 2; + break; + case MOP_K_INFO_CSZ: + index = index + 2; + break; + case MOP_K_INFO_RSZ: + index = index + 2; + break; + case MOP_K_INFO_HWA: + index = index + 6; + break; + case MOP_K_INFO_TIME: + index = index + 10; + break; + case MOP_K_INFO_SOFD: + device = mopGetChar(pkt,&index); + break; + case MOP_K_INFO_SFID: + tmpc = mopGetChar(pkt,&index); + if ((index > 0) && (index < 17)) + index = index + tmpc; + break; + case MOP_K_INFO_PRTY: + index = index + 1; + break; + case MOP_K_INFO_DLTY: + index = index + 1; + break; + case MOP_K_INFO_DLBSZ: + index = index + 2; + break; + default: + if (((device = NMA_C_SOFD_LCS) || /* DECserver 100 */ + (device = NMA_C_SOFD_DS2) || /* DECserver 200 */ + (device = NMA_C_SOFD_DP2) || /* DECserver 250 */ + (device = NMA_C_SOFD_DS3)) && /* DECserver 300 */ + ((itype > 101) && (itype < 107))) + { + switch (itype) { + case 102: + index = index + ilen; + break; + case 103: + index = index + ilen; + break; + case 104: + index = index + 2; + break; + case 105: + (void)fprintf(stdout,"%x:%x:%x:%x:%x:%x\t", + src[0],src[1],src[2],src[3],src[4],src[5]); + for (i = 0; i < ilen; i++) { + (void)fprintf(stdout, "%c",pkt[index+i]); + } + index = index + ilen; + (void)fprintf(stdout, "\n"); + break; + case 106: + index = index + ilen; + break; + }; + } else { + index = index + ilen; + }; + } + itype = mopGetShort(pkt,&index); + } + +} + diff --git a/package/mopd/src/moptrace/Makefile b/package/mopd/src/moptrace/Makefile new file mode 100644 index 000000000..e237d8d16 --- /dev/null +++ b/package/mopd/src/moptrace/Makefile @@ -0,0 +1,23 @@ +OBJS=moptrace.o +INCL=-I../ -I../common +LIBS=../common/libcommon.a + +all: moptrace + +moptrace: ${OBJS} version.o $(LIBS) + $(CC) -o moptrace version.o ${OBJS} ${LIBS} + +.c.o: .c + $(CC) -c $(CFLAGS) ${INCL} $< + +clean: + rm -f *.o *~ moptrace VERSION version.* + +version.o: version.c +version.c version.h: + ln -sf ../common/VERSION VERSION + rm -f version.c ; sed 's/.*/char version[] = "&";/' VERSION > version.c + set `sed 's/\([0-9]*\)\.\([0-9]*\).*/\1 \2/' VERSION` ; \ + { echo '#define VERSION_MAJOR' $$1 ; \ + echo '#define VERSION_MINOR' $$2 ; } > version.h + diff --git a/package/mopd/src/moptrace/moptrace.1 b/package/mopd/src/moptrace/moptrace.1 new file mode 100644 index 000000000..5626c78eb --- /dev/null +++ b/package/mopd/src/moptrace/moptrace.1 @@ -0,0 +1,83 @@ +.\" $NetBSD: moptrace.1,v 1.4 1997/10/18 04:37:37 lukem Exp $ +.\" +.\" Copyright (c) 1993-95 Mats O Jansson. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Mats O Jansson. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.\" @(#) $NetBSD: moptrace.1,v 1.4 1997/10/18 04:37:37 lukem Exp $ +.\" +.Dd October 2, 1995 +.Dt MOPTRACE 1 +.Sh NAME +.Nm moptrace +.Nd MOP Trace Utility +.Sh SYNOPSIS +.Nm +.Op Fl a +.Op Fl d +.Op Fl 3 | 4 +.Nm "" +.Op Fl d +.Op Fl 3 | 4 +.Op Ar interface +.Sh DESCRIPTION +.Nm +prints the contents of MOP packages on the Ethernet connected to +.Ar interface +or all known interfaces if +.Sq Fl a +is given. +.Sh OPTIONS +.Bl -tag -width indent +.It Fl a +Listen on all the Ethernets attached to the system. +If +.Sq Fl a +is omitted, an interface must be specified. +.It Fl d +Run in debug mode, with all the output to stderr. +.It Fl 3 +Ignore MOP V3 messages (Ethernet II). +.It Fl 4 +Ignore MOP V4 messages (Ethernet 802.3). +.El +.Sh SEE ALSO +.Xr mopa.out 1 , +.Xr mopchk 1 , +.Xr mopd 8 , +.Xr mopprobe 1 +.Rs +DECnet Digital Network Architecture Phase IV, +.%R Maintenance Operations Functional Specification V3.0.0 +.%N AA-X436A-TK +.Re +.Rs +DECnet Digital Network Architecture, +.%R Maintenance Operations Protocol Functional Specification V4.0.0 +.%N EK-DNA11-FS-001 +.Re +.Sh AUTHORS +Mats O Jansson (moj@stacken.kth.se). diff --git a/package/mopd/src/moptrace/moptrace.c b/package/mopd/src/moptrace/moptrace.c new file mode 100644 index 000000000..8f7124192 --- /dev/null +++ b/package/mopd/src/moptrace/moptrace.c @@ -0,0 +1,157 @@ +/* $NetBSD: moptrace.c,v 1.4 1997/04/17 21:09:33 christos Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +/*__RCSID("$NetBSD: moptrace.c,v 1.4 1997/04/17 21:09:33 christos Exp $");*/ +#endif + +/* + * moptrace - MOP Trace Utility + * + * Usage: moptrace -a [ -d ] [ -3 | -4 ] + * moptrace [ -d ] [ -3 | -4 ] interface + */ + +#include "os.h" +#include "common/common.h" +#include "common/device.h" +#include "common/dl.h" +#include "common/get.h" +#include "common/mopdef.h" +#include "common/pf.h" +#include "common/print.h" +#include "common/rc.h" + +/* + * The list of all interfaces that are being listened to. + * "selects" on the descriptors in this list. + */ +struct if_info *iflist; + +void Usage __P((void)); +int main __P((int, char **)); +void mopProcess __P((struct if_info *, u_char *)); + +int AllFlag = 0; /* listen on "all" interfaces */ +int DebugFlag = 0; /* print debugging messages */ +int Not3Flag = 0; /* Ignore MOP V3 messages */ +int Not4Flag = 0; /* Ignore MOP V4 messages */ +int promisc = 1; /* Need promisc mode */ + +extern char *__progname; /* from crt0.o */ + +int +main(argc, argv) + int argc; + char **argv; +{ + int op; + char *interface; + + /* All error reporting is done through syslogs. */ + openlog(__progname, LOG_PID | LOG_CONS, LOG_DAEMON); + + opterr = 0; + while ((op = getopt(argc, argv, "34ad")) != -1) { + switch (op) { + case '3': + Not3Flag++; + break; + case '4': + Not4Flag++; + break; + case 'a': + AllFlag++; + break; + case 'd': + DebugFlag++; + break; + default: + Usage(); + /* NOTREACHED */ + } + } + + interface = argv[optind++]; + + if ((AllFlag && interface) || + (!AllFlag && interface == 0) || + (Not3Flag && Not4Flag)) + Usage(); + + if (AllFlag) + deviceInitAll(); + else + deviceInitOne(interface); + + Loop(); + /* NOTREACHED */ + return (0); +} + +void +Usage() +{ + (void) fprintf(stderr, "usage: %s -a [ -d ] [ -3 | -4 ]\n", __progname); + (void) fprintf(stderr, " %s [ -d ] [ -3 | -4 ] interface\n", + __progname); + exit(1); +} + +/* + * Process incoming packages. + */ +void +mopProcess(ii, pkt) + struct if_info *ii; + u_char *pkt; +{ + int trans; + + /* We don't known which transport, Guess! */ + + trans = mopGetTrans(pkt, 0); + + /* Ok, return if we don't want this message */ + + if ((trans == TRANS_ETHER) && Not3Flag) return; + if ((trans == TRANS_8023) && Not4Flag) return; + + mopPrintHeader(stdout, pkt, trans); + mopPrintMopHeader(stdout, pkt, trans); + + mopDumpDL(stdout, pkt, trans); + mopDumpRC(stdout, pkt, trans); + + fprintf(stdout, "\n"); + fflush(stdout); +} -- cgit v1.2.3