summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/mopd/Makefile5
-rw-r--r--usr.sbin/mopd/Makefile.inc4
-rw-r--r--usr.sbin/mopd/common/VERSION1
-rw-r--r--usr.sbin/mopd/common/cmp.c41
-rw-r--r--usr.sbin/mopd/common/cmp.h44
-rw-r--r--usr.sbin/mopd/common/common.h92
-rw-r--r--usr.sbin/mopd/common/device.c331
-rw-r--r--usr.sbin/mopd/common/device.h52
-rw-r--r--usr.sbin/mopd/common/dl.c315
-rw-r--r--usr.sbin/mopd/common/dl.h44
-rw-r--r--usr.sbin/mopd/common/file.c843
-rw-r--r--usr.sbin/mopd/common/file.h67
-rw-r--r--usr.sbin/mopd/common/get.c148
-rw-r--r--usr.sbin/mopd/common/get.h58
-rw-r--r--usr.sbin/mopd/common/loop-bsd.c179
-rw-r--r--usr.sbin/mopd/common/mopdef.c49
-rw-r--r--usr.sbin/mopd/common/mopdef.h196
-rw-r--r--usr.sbin/mopd/common/nma.c224
-rw-r--r--usr.sbin/mopd/common/nma.h46
-rw-r--r--usr.sbin/mopd/common/nmadef.h181
-rw-r--r--usr.sbin/mopd/common/os.h57
-rw-r--r--usr.sbin/mopd/common/pf.c279
-rw-r--r--usr.sbin/mopd/common/pf.h56
-rw-r--r--usr.sbin/mopd/common/print.c703
-rw-r--r--usr.sbin/mopd/common/print.h62
-rw-r--r--usr.sbin/mopd/common/put.c186
-rw-r--r--usr.sbin/mopd/common/put.h56
-rw-r--r--usr.sbin/mopd/common/rc.c316
-rw-r--r--usr.sbin/mopd/common/rc.h44
-rw-r--r--usr.sbin/mopd/mopa.out/Makefile10
-rw-r--r--usr.sbin/mopd/mopa.out/mopa.out.159
-rw-r--r--usr.sbin/mopd/mopa.out/mopa.out.c154
-rw-r--r--usr.sbin/mopd/mopchk/Makefile18
-rw-r--r--usr.sbin/mopd/mopchk/mopchk.165
-rw-r--r--usr.sbin/mopd/mopchk/mopchk.c177
-rw-r--r--usr.sbin/mopd/mopd/Makefile20
-rw-r--r--usr.sbin/mopd/mopd/TODO1
-rw-r--r--usr.sbin/mopd/mopd/mopd.8113
-rw-r--r--usr.sbin/mopd/mopd/mopd.c241
-rw-r--r--usr.sbin/mopd/mopd/process.c637
-rw-r--r--usr.sbin/mopd/mopd/process.h50
-rw-r--r--usr.sbin/mopd/mopprobe/Makefile17
-rw-r--r--usr.sbin/mopd/mopprobe/mopprobe.170
-rw-r--r--usr.sbin/mopd/mopprobe/mopprobe.c292
-rw-r--r--usr.sbin/mopd/moptrace/Makefile20
-rw-r--r--usr.sbin/mopd/moptrace/moptrace.183
-rw-r--r--usr.sbin/mopd/moptrace/moptrace.c169
-rw-r--r--usr.sbin/mopd/otherOS/Makefile172
-rw-r--r--usr.sbin/mopd/otherOS/loop.c178
-rw-r--r--usr.sbin/mopd/otherOS/mdtype51
-rw-r--r--usr.sbin/mopd/otherOS/os-sunos4.h51
-rw-r--r--usr.sbin/mopd/otherOS/ostype33
-rw-r--r--usr.sbin/mopd/otherOS/pf-snit.c340
53 files changed, 7700 insertions, 0 deletions
diff --git a/usr.sbin/mopd/Makefile b/usr.sbin/mopd/Makefile
new file mode 100644
index 00000000000..8c20a6efe18
--- /dev/null
+++ b/usr.sbin/mopd/Makefile
@@ -0,0 +1,5 @@
+# $Id: Makefile,v 1.1 1996/09/21 13:49:15 maja Exp $
+
+SUBDIR= mopd mopprobe moptrace mopchk mopa.out
+
+.include <bsd.subdir.mk>
diff --git a/usr.sbin/mopd/Makefile.inc b/usr.sbin/mopd/Makefile.inc
new file mode 100644
index 00000000000..d76b2ca5d44
--- /dev/null
+++ b/usr.sbin/mopd/Makefile.inc
@@ -0,0 +1,4 @@
+# from: @(#)Makefile.inc 5.1 (Berkeley) 5/11/90
+# $Id: Makefile.inc,v 1.1 1996/09/21 13:49:16 maja Exp $
+
+BINDIR?= /usr/sbin
diff --git a/usr.sbin/mopd/common/VERSION b/usr.sbin/mopd/common/VERSION
new file mode 100644
index 00000000000..aedc15bb0c6
--- /dev/null
+++ b/usr.sbin/mopd/common/VERSION
@@ -0,0 +1 @@
+2.5.3
diff --git a/usr.sbin/mopd/common/cmp.c b/usr.sbin/mopd/common/cmp.c
new file mode 100644
index 00000000000..09b6e4abd31
--- /dev/null
+++ b/usr.sbin/mopd/common/cmp.c
@@ -0,0 +1,41 @@
+/*
+ * 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: cmp.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include "os.h"
+
+int
+mopCmpEAddr(addr1, addr2)
+ register u_char *addr1, *addr2;
+{
+ return(bcmp((char *)addr1, (char *)addr2, 6));
+}
diff --git a/usr.sbin/mopd/common/cmp.h b/usr.sbin/mopd/common/cmp.h
new file mode 100644
index 00000000000..78d4e496037
--- /dev/null
+++ b/usr.sbin/mopd/common/cmp.h
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ *
+ * $Id: cmp.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _CMP_H_
+#define _CMP_H_
+
+#ifdef NO__P
+int mopCmpEAddr (/* u_char *,u_char * */);
+#else
+__BEGIN_DECLS
+int mopCmpEAddr __P((u_char *,u_char *));
+__END_DECLS
+#endif
+
+#endif _CMP_H_
diff --git a/usr.sbin/mopd/common/common.h b/usr.sbin/mopd/common/common.h
new file mode 100644
index 00000000000..c9fcddc14cc
--- /dev/null
+++ b/usr.sbin/mopd/common/common.h
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ *
+ * $Id: common.h,v 1.1 1996/09/21 13:49:16 maja 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 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)(); /* Interface Open Routine */
+ int (*write)(); /* Interface Write Routine */
+ void (*read)(); /* 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_long loadaddr; /* Load Address */
+ u_long xferaddr; /* Transfer Address */
+ u_long nloadaddr; /* Next Load Address */
+ long lseek; /* Seek before last read */
+ int aout; /* Is it an a.out file */
+ u_long a_text; /* Size of text segment */
+ u_long a_text_fill; /* Size of text segment fill */
+ u_long a_data; /* Size of data segment */
+ u_long a_data_fill; /* Size of data segment fill */
+ u_long a_bss; /* Size of bss segment */
+ u_long a_bss_fill; /* Size of bss segment fill */
+ long a_lseek; /* Keep track of pos in newfile */
+};
+
+#endif _COMMON_H_
diff --git a/usr.sbin/mopd/common/device.c b/usr.sbin/mopd/common/device.c
new file mode 100644
index 00000000000..b81e0b2d829
--- /dev/null
+++ b/usr.sbin/mopd/common/device.c
@@ -0,0 +1,331 @@
+/*
+ * 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: device.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include "os.h"
+#include "common/common.h"
+#include "common/mopdef.h"
+
+struct if_info *iflist; /* Interface List */
+
+void mopReadDL();
+void mopReadRC();
+#ifdef NO__P
+int mopOpenDL(/* struct if_info *, int */);
+int mopOpenRC(/* struct if_info *, int */);
+#else
+int mopOpenDL(struct if_info *, int);
+int mopOpenRC(struct if_info *, int);
+#endif
+int pfTrans();
+int pfInit();
+int pfWrite();
+
+#ifdef DEV_NEW_CONF
+/*
+ * 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;
+
+ /* 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");
+ 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))) {
+ bcopy((caddr_t)LLADDR(sdl), (caddr_t)eaddr, 6);
+ return;
+ }
+ }
+
+ syslog(LOG_ERR, "deviceEthAddr: Never saw interface `%s'!", ifname);
+ exit(1);
+}
+#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;
+ bzero((char *)p->eaddr,sizeof(p->eaddr));
+ p->fd = tmp.fd;
+
+#ifdef DEV_NEW_CONF
+ deviceEthAddr(p->if_name,&p->eaddr[0]);
+#else
+ p->eaddr[0]= tmp.eaddr[0];
+ p->eaddr[1]= tmp.eaddr[1];
+ p->eaddr[2]= tmp.eaddr[2];
+ p->eaddr[3]= tmp.eaddr[3];
+ p->eaddr[4]= tmp.eaddr[4];
+ p->eaddr[5]= tmp.eaddr[5];
+#endif /* DEV_NEW_CONF */
+
+ }
+}
+
+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/usr.sbin/mopd/common/device.h b/usr.sbin/mopd/common/device.h
new file mode 100644
index 00000000000..40e47d372a1
--- /dev/null
+++ b/usr.sbin/mopd/common/device.h
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ *
+ * $Id: device.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _DEVICE_H_
+#define _DEVICE_H_
+
+#ifdef NO__P
+#ifdef DEV_NEW_CONF
+void deviceEthAddr (/* char *,u_char * */);
+#endif
+void deviceInitOne (/* char * */);
+void deviceInitAll (/* void */);
+#else
+__BEGIN_DECLS
+#ifdef DEV_NEW_CONF
+void deviceEthAddr __P((char *,u_char *));
+#endif
+void deviceInitOne __P((char *));
+void deviceInitAll __P((void));
+__END_DECLS
+#endif
+
+#endif _DEVICE_H_
diff --git a/usr.sbin/mopd/common/dl.c b/usr.sbin/mopd/common/dl.c
new file mode 100644
index 00000000000..2900bd34961
--- /dev/null
+++ b/usr.sbin/mopd/common/dl.c
@@ -0,0 +1,315 @@
+/*
+ * 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: dl.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include "os.h"
+#include "common/get.h"
+#include "common/print.h"
+#include "common/mopdef.h"
+
+void
+mopDumpDL(fd, pkt, trans)
+ FILE *fd;
+ u_char *pkt;
+ int trans;
+{
+ int i,index = 0;
+ long tmpl;
+ u_char tmpc,c,program[17],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);
+
+ 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/usr.sbin/mopd/common/dl.h b/usr.sbin/mopd/common/dl.h
new file mode 100644
index 00000000000..b4edac3be20
--- /dev/null
+++ b/usr.sbin/mopd/common/dl.h
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ *
+ * $Id: dl.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _DL_H_
+#define _DL_H_
+
+#ifdef NO__P
+void mopDumpDL (/* FILE *, u_char *, int */);
+#else
+__BEGIN_DECLS
+void mopDumpDL __P((FILE *, u_char *, int));
+__END_DECLS
+#endif
+
+#endif _DL_H_
diff --git a/usr.sbin/mopd/common/file.c b/usr.sbin/mopd/common/file.c
new file mode 100644
index 00000000000..e65eb4d3227
--- /dev/null
+++ b/usr.sbin/mopd/common/file.c
@@ -0,0 +1,843 @@
+/*
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: file.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include "os.h"
+#include "common/common.h"
+#include "common/mopdef.h"
+
+#ifndef NOAOUT
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/exec_aout.h>
+#endif
+#if defined(__bsdi__)
+#define NOAOUT
+#endif
+#if defined(__FreeBSD__)
+#include <sys/imgact_aout.h>
+#endif
+#if !defined(MID_VAX)
+#define MID_VAX 140
+#endif
+#endif
+
+void
+mopFilePutLX(buf, index, value, cnt)
+ u_char *buf;
+ int index, cnt;
+ u_long 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_long value;
+{
+ int i;
+ for (i = 0; i < cnt; i++) {
+ buf[index+cnt-1-i] = value % 256;
+ value = value / 256;
+ }
+}
+
+u_long
+mopFileGetLX(buf, index, cnt)
+ u_char *buf;
+ int index, cnt;
+{
+ u_long ret = 0;
+ int i;
+
+ for (i = 0; i < cnt; i++) {
+ ret = ret*256 + buf[index+cnt-1-i];
+ }
+
+ return(ret);
+}
+
+u_long
+mopFileGetBX(buf, index, cnt)
+ u_char *buf;
+ int index, cnt;
+{
+ u_long 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_long *load, *xfr;
+{
+ u_char header[512];
+ short image_type;
+ u_long 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;
+#ifdef INFO
+ 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);
+#endif
+ 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];
+#ifdef INFO
+ 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);
+#endif
+ break;
+ case IHD_C_BPA: /* BASIC plus analog */
+#ifdef INFO
+ printf("BASIC-Plus Image, not supported\n");
+#endif
+ return(-1);
+ break;
+ case IHD_C_ALIAS: /* Alias */
+#ifdef INFO
+ printf("Alias, not supported\n");
+#endif
+ return(-1);
+ break;
+ case IHD_C_CLI: /* Image is CLI */
+#ifdef INFO
+ printf("CLI, not supported\n");
+#endif
+ 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]);
+#ifdef INFO
+ 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);
+#endif
+ 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;
+#ifdef INFO
+ 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);
+#endif
+ break;
+ default:
+#ifdef INFO
+ printf("Unknown Image (%d)\n",image_type);
+#endif
+ 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
+/*###323 [cc] for each function it appears in.)%%%*/
+/*###323 [cc] (Each undeclared identifier is reported only once%%%*/
+/*###323 [cc] `MID_SPARC' undeclared (first use this function)%%%*/
+ 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:
+/*###352 [cc] syntax error before `}'%%%*/
+ }
+
+ return(mid);
+}
+
+int
+getCLBYTES(mid)
+ int mid;
+{
+ int clbytes;
+
+ switch (mid) {
+#ifdef MID_VAX
+ case MID_VAX:
+ clbytes = 1024;
+ break;
+#endif
+ case MID_I386:
+#ifdef MID_M68K4K
+ case MID_M68K4K:
+#endif
+#ifdef MID_NS32532
+ case MID_NS32532:
+#endif
+ case MID_SPARC: /* It might be 8192 */
+#ifdef MID_PMAX
+ case MID_PMAX:
+#endif
+#ifdef MID_MIPS
+ case MID_MIPS:
+#endif
+#ifdef MID_ARM6
+ case MID_ARM6:
+#endif
+ clbytes = 4096;
+ break;
+#ifdef MID_M68K
+ case MID_M68K:
+#endif
+#ifdef MID_ALPHA
+ case MID_ALPHA:
+#endif
+#if defined(MID_M68K) || defined(MID_ALPHA)
+ clbytes = 8192;
+ break;
+#endif
+ default:
+ clbytes = 0;
+ }
+
+ return(clbytes);
+}
+#endif
+
+/*###406 [cc] syntax error before `int'%%%*/
+int
+CheckAOutFile(fd)
+ int fd;
+{
+#ifdef NOAOUT
+ return(-1);
+#else
+ struct exec ex, ex_swap;
+ int mid = -1;
+
+/*###416 [cc] `fd' undeclared (first use this function)%%%*/
+ 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
+}
+
+/*###440 [cc] syntax error before `int'%%%*/
+int
+GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
+ a_data, a_data_fill, a_bss, a_bss_fill, aout)
+ int fd, *aout;
+ u_long *load, *xfr, *a_text, *a_text_fill;
+ u_long *a_data, *a_data_fill, *a_bss, *a_bss_fill;
+{
+#ifdef NOAOUT
+ return(-1);
+#else
+ struct exec ex, ex_swap;
+ int mid = -1;
+ u_long 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:
+/*###525 [cc] syntax error before `}'%%%*/
+ }
+
+#ifdef INFO
+ 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:
+ }
+ 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 %d",N_GETMAGIC (ex));
+ }
+ printf("\n");
+ printf("Size of text: %08x\n",ex.a_text);
+ printf("Size of data: %08x\n",ex.a_data);
+ printf("Size of bss: %08x\n",ex.a_bss);
+ printf("Size of symbol tab: %08x\n",ex.a_syms);
+ printf("Transfer Address: %08x\n",ex.a_entry);
+ printf("Size of reloc text: %08x\n",ex.a_trsize);
+ printf("Size of reloc data: %08x\n",ex.a_drsize);
+#endif
+ magic = N_GETMAGIC (ex);
+ clbytes = getCLBYTES(mid);
+ clofset = clbytes - 1;
+
+/*###608 [cc] `load' undeclared (first use this function)%%%*/
+ if (load != NULL) {
+ *load = 0;
+ }
+
+/*###612 [cc] `xfr' undeclared (first use this function)%%%*/
+ if (xfr != NULL) {
+ *xfr = ex.a_entry;
+ }
+
+/*###616 [cc] `a_text' undeclared (first use this function)%%%*/
+ if (a_text != NULL) {
+ *a_text = ex.a_text;
+ }
+
+/*###620 [cc] `a_text_fill' undeclared (first use this function)%%%*/
+ 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;
+ }
+ }
+
+/*###631 [cc] `a_data' undeclared (first use this function)%%%*/
+ if (a_data != NULL) {
+ *a_data = ex.a_data;
+ }
+
+/*###635 [cc] `a_data_fill' undeclared (first use this function)%%%*/
+ 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;
+ }
+ }
+
+/*###646 [cc] `a_bss' undeclared (first use this function)%%%*/
+ if (a_bss != NULL) {
+ *a_bss = ex.a_bss;
+ }
+
+/*###650 [cc] `a_bss_fill' undeclared (first use this function)%%%*/
+ 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;
+ }
+ }
+ }
+
+/*###665 [cc] `aout' undeclared (first use this function)%%%*/
+ if (aout != NULL) {
+ *aout = mid;
+ }
+
+ return(0);
+#endif NOAOUT
+}
+
+/*###673 [cc] syntax error before `int'%%%*/
+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_long *load, *xfr, *a_text, *a_text_fill;
+ u_long *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
+/*###711 [cc] syntax error before `mopFileRead'%%%*/
+mopFileRead(dlslot, buf)
+ struct dllist *dlslot;
+ u_char *buf;
+{
+ ssize_t len, outlen;
+ int bsz;
+ long pos, notdone, total;
+
+/*###719 [cc] `dlslot' undeclared (first use this function)%%%*/
+ if (dlslot->aout == -1) {
+/*###720 [cc] `buf' undeclared (first use this function)%%%*/
+ 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) {
+/*###731 [cc] subscripted value is neither array nor pointer%%%*/
+ outlen = read(dlslot->ldfd,&buf[len],notdone);
+ } else {
+/*###733 [cc] subscripted value is neither array nor pointer%%%*/
+ 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;
+ }
+/*###749 [cc] subscripted value is neither array nor pointer%%%*/
+ bzero(&buf[len],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) {
+/*###760 [cc] subscripted value is neither array nor pointer%%%*/
+ outlen = read(dlslot->ldfd,&buf[len],notdone);
+ } else {
+/*###762 [cc] subscripted value is neither array nor pointer%%%*/
+ 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;
+ }
+/*###778 [cc] subscripted value is neither array nor pointer%%%*/
+ bzero(&buf[len],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;
+ }
+/*###793 [cc] subscripted value is neither array nor pointer%%%*/
+ bzero(&buf[len],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;
+ }
+/*###808 [cc] subscripted value is neither array nor pointer%%%*/
+ bzero(&buf[len],outlen);
+ len = len + outlen;
+ pos = pos + outlen;
+ bsz = bsz - outlen;
+ }
+
+ dlslot->a_lseek = pos;
+
+ }
+
+ return(len);
+}
+/*###820 [cc] syntax error at end of input%%%*/
diff --git a/usr.sbin/mopd/common/file.h b/usr.sbin/mopd/common/file.h
new file mode 100644
index 00000000000..4839de29ad0
--- /dev/null
+++ b/usr.sbin/mopd/common/file.h
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ *
+ * $Id: file.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _FILE_H_
+#define _FILE_H_
+
+#ifdef NO__P
+void mopFilePutLX (/* u_char *, int, u_long, int */);
+void mopFilePutBX (/* u_char *, int, u_long, int */);
+u_long mopFileGetLX (/* u_char *, int, int */);
+u_long mopFileGetBX (/* u_char *, int, int */);
+void mopFileSwapX (/* u_char *, int, int */);
+int CheckMopFile (/* int */);
+int GetMopFileInfo (/* int, u_long *, u_long * */);
+int CheckAOutFile (/* int */);
+int GetAOutFileInfo(/* int, u_long *, u_long *, u_long *, u_long *,
+ u_long *, u_long *, u_long *, u_long * */);
+int GetFileInfo (/* int, u_long *, u_long *, int *, u_long *, u_long *,
+ u_long *, u_long *, u_long *, u_long * */);
+#else
+__BEGIN_DECLS
+void mopFilePutLX __P((u_char *, int, u_long, int));
+void mopFilePutBX __P((u_char *, int, u_long, int));
+u_long mopFileGetLX __P((u_char *, int, int));
+u_long mopFileGetBX __P((u_char *, int, int));
+void mopFileSwapX __P((u_char *, int, int));
+int CheckMopFile __P((int));
+int GetMopFileInfo __P((int, u_long *, u_long *));
+int CheckAOutFile __P((int));
+int GetAOutFileInfo __P((int, u_long *, u_long *, u_long *, u_long *,
+ u_long *, u_long *, u_long *, u_long *, int *));
+int GetFileInfo __P((int, u_long *, u_long *, int *,
+ u_long *, u_long *, u_long *, u_long *,
+ u_long *, u_long *));
+__END_DECLS
+#endif
+
+#endif _FILE_H_
diff --git a/usr.sbin/mopd/common/get.c b/usr.sbin/mopd/common/get.c
new file mode 100644
index 00000000000..34bab5a6284
--- /dev/null
+++ b/usr.sbin/mopd/common/get.c
@@ -0,0 +1,148 @@
+/*
+ * 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: get.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include <sys/types.h>
+#include "common/mopdef.h"
+
+u_char
+mopGetChar(pkt, index)
+ register u_char *pkt;
+ register int *index;
+{
+ u_char ret;
+
+ ret = pkt[*index];
+ *index = *index + 1;
+ return(ret);
+}
+
+u_short
+mopGetShort(pkt, index)
+ register u_char *pkt;
+ register int *index;
+{
+ u_short ret;
+
+ ret = pkt[*index] + pkt[*index+1]*256;
+ *index = *index + 2;
+ return(ret);
+}
+
+u_long
+mopGetLong(pkt, index)
+ register u_char *pkt;
+ register int *index;
+{
+ u_long 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)
+ register u_char *pkt,*dest;
+ register 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/usr.sbin/mopd/common/get.h b/usr.sbin/mopd/common/get.h
new file mode 100644
index 00000000000..9102aaeb32a
--- /dev/null
+++ b/usr.sbin/mopd/common/get.h
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ *
+ * $Id: get.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _GET_H_
+#define _GET_H_
+
+#ifdef NO__P
+u_char mopGetChar (/* u_char *, int * */);
+u_short mopGetShort (/* u_char *, int * */);
+u_long mopGetLong (/* u_char *, int * */);
+void mopGetMulti (/* u_char *, int *,u_char *,int */);
+int mopGetTrans (/* u_char *, int */);
+void mopGetHeader (/* u_char *, int *, u_char **, u_char **, u_short *,
+ int *, int */);
+u_short mopGetLength (/* u_char *, int */);
+#else
+__BEGIN_DECLS
+u_char mopGetChar __P((u_char *,int *));
+u_short mopGetShort __P((u_char *,int *));
+u_long 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
+
+#endif _GET_H_
diff --git a/usr.sbin/mopd/common/loop-bsd.c b/usr.sbin/mopd/common/loop-bsd.c
new file mode 100644
index 00000000000..cb3cb09114a
--- /dev/null
+++ b/usr.sbin/mopd/common/loop-bsd.c
@@ -0,0 +1,179 @@
+/*
+ * 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-bsd.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include <stdlib.h>
+#include <strings.h>
+#include <unistd.h>
+#if defined(__bsdi__) || defined(__FreeBSD__)
+#include <sys/time.h>
+#endif
+#include <net/bpf.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+
+#include "os.h"
+#include "common/common.h"
+#include "common/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) {
+ register int caplen, hdrlen;
+
+ caplen = bhp->bh_caplen;
+ hdrlen = bhp->bh_hdrlen;
+ mopProcess(ii, bp + hdrlen);
+ bp += BPF_WORDALIGN(hdrlen + caplen);
+ }
+ }
+ }
+}
diff --git a/usr.sbin/mopd/common/mopdef.c b/usr.sbin/mopd/common/mopdef.c
new file mode 100644
index 00000000000..a3d019dd0cd
--- /dev/null
+++ b/usr.sbin/mopd/common/mopdef.c
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: mopdef.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#define MOPDEF_SURPESS_EXTERN
+#include "common/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 */
+
+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]);
+}
diff --git a/usr.sbin/mopd/common/mopdef.h b/usr.sbin/mopd/common/mopdef.h
new file mode 100644
index 00000000000..f6c7966e612
--- /dev/null
+++ b/usr.sbin/mopd/common/mopdef.h
@@ -0,0 +1,196 @@
+/*
+ * 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.
+ *
+ * $Id: mopdef.h,v 1.1 1996/09/21 13:49:16 maja 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/usr.sbin/mopd/common/nma.c b/usr.sbin/mopd/common/nma.c
new file mode 100644
index 00000000000..a29eb47c462
--- /dev/null
+++ b/usr.sbin/mopd/common/nma.c
@@ -0,0 +1,224 @@
+/*
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: nma.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include <stddef.h>
+#include "common/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/usr.sbin/mopd/common/nma.h b/usr.sbin/mopd/common/nma.h
new file mode 100644
index 00000000000..cf65ddb9b84
--- /dev/null
+++ b/usr.sbin/mopd/common/nma.h
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ *
+ * $Id: nma.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _NMA_H_
+#define _NMA_H_
+
+#ifdef NO__P
+char *nmaGetShort (/* int */);
+char *nmaGetDevice (/* int */);
+#else
+__BEGIN_DECLS
+char *nmaGetShort __P((int));
+char *nmaGetDevice __P((int));
+__END_DECLS
+#endif
+
+#endif _NMA_H_
diff --git a/usr.sbin/mopd/common/nmadef.h b/usr.sbin/mopd/common/nmadef.h
new file mode 100644
index 00000000000..7cbaf9e0539
--- /dev/null
+++ b/usr.sbin/mopd/common/nmadef.h
@@ -0,0 +1,181 @@
+/*
+ * 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.
+ *
+ * $Id: nmadef.h,v 1.1 1996/09/21 13:49:16 maja 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/usr.sbin/mopd/common/os.h b/usr.sbin/mopd/common/os.h
new file mode 100644
index 00000000000..08a7cfe648b
--- /dev/null
+++ b/usr.sbin/mopd/common/os.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1994-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.
+ *
+ * $Id: os.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _OS_H_
+#define _OS_H_
+
+#include <stdio.h>
+
+#include <syslog.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <sys/ioctl.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <time.h>
+#include <fcntl.h>
+#include <strings.h>
+#include <unistd.h>
+
+#define DEV_NEW_CONF
+
+#endif _OS_H_
diff --git a/usr.sbin/mopd/common/pf.c b/usr.sbin/mopd/common/pf.c
new file mode 100644
index 00000000000..88fbd655dda
--- /dev/null
+++ b/usr.sbin/mopd/common/pf.c
@@ -0,0 +1,279 @@
+/*
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: pf.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <net/if.h>
+
+#include <net/bpf.h>
+#include <sys/errno.h>
+
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+
+#include <netdb.h>
+#include <ctype.h>
+#include <strings.h>
+
+#include <syslog.h>
+#include <varargs.h>
+
+#include "common/mopdef.h"
+
+/*
+ * Variables
+ */
+
+extern int errno;
+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 bpf %m");
+ 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;
+ bcopy(addr, ifr.ifr_addr.sa_data, 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;
+ bcopy(addr, ifr.ifr_addr.sa_data, 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/usr.sbin/mopd/common/pf.h b/usr.sbin/mopd/common/pf.h
new file mode 100644
index 00000000000..e3759b50b31
--- /dev/null
+++ b/usr.sbin/mopd/common/pf.h
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ *
+ * $Id: pf.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _PF_H_
+#define _PF_H_
+
+#ifdef NO__P
+int pfTrans (/* char * */);
+int pfInit (/* char *, int, u_short, int */);
+int pfEthAddr (/* int, u_char * */);
+int pfAddMulti (/* int, char *, char * */);
+int pfDelMulti (/* int, char *, char * */);
+int pfRead (/* int, u_char *, int */);
+int pfWrite (/* int, u_char *, int, int */);
+#else
+__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
+
+#endif _PF_H_
diff --git a/usr.sbin/mopd/common/print.c b/usr.sbin/mopd/common/print.c
new file mode 100644
index 00000000000..bfa20ffd035
--- /dev/null
+++ b/usr.sbin/mopd/common/print.c
@@ -0,0 +1,703 @@
+/*
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: print.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include <sys/types.h>
+#include <stdio.h>
+
+#include "os.h"
+#include "common/mopdef.h"
+#include "common/nmadef.h"
+#include "common/nma.h"
+#include "common/cmp.h"
+#include "common/get.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/usr.sbin/mopd/common/print.h b/usr.sbin/mopd/common/print.h
new file mode 100644
index 00000000000..f2be66cdb45
--- /dev/null
+++ b/usr.sbin/mopd/common/print.h
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ *
+ * $Id: print.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _PRINT_H_
+#define _PRINT_H_
+
+#ifdef NO__P
+void mopPrintHWA (/* FILE *, u_char * */);
+void mopPrintBPTY (/* FILE *, u_char */);
+void mopPrintPGTY (/* FILE *, u_char */);
+void mopPrintOneline (/* FILE *, u_char *, int */);
+void mopPrintHeader (/* FILE *, u_char *, int */);
+void mopPrintMopHeader (/* FILE *, u_char *, int */);
+void mopPrintDevice (/* FILE *, u_char */);
+void mopPrintTime (/* FILE *, u_char * */);
+void mopPrintInfo (/* FILE *, u_char *, int *, u_short,
+ u_char, int */);
+#else
+__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
+
+#endif _PRINT_H_
diff --git a/usr.sbin/mopd/common/put.c b/usr.sbin/mopd/common/put.c
new file mode 100644
index 00000000000..c960b85713f
--- /dev/null
+++ b/usr.sbin/mopd/common/put.c
@@ -0,0 +1,186 @@
+/*
+ * 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: put.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include <stddef.h>
+#include <sys/types.h>
+#include <time.h>
+#include "common/mopdef.h"
+
+void
+mopPutChar(pkt, index, value)
+ register u_char *pkt;
+ register int *index;
+ u_char value;
+{
+ pkt[*index] = value;
+ *index = *index + 1;
+}
+
+void
+mopPutShort(pkt, index, value)
+ register u_char *pkt;
+ register 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)
+ register u_char *pkt;
+ register int *index;
+ u_long 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)
+ register u_char *pkt,*value;
+ register int *index,size;
+{
+ int i;
+
+ for (i = 0; i < size; i++) {
+ pkt[*index+i] = value[i];
+ }
+ *index = *index + size;
+}
+
+void
+mopPutTime(pkt, index, value)
+ register u_char *pkt;
+ register 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)
+ register u_char *pkt;
+ register int *index;
+ 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)
+ register 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/usr.sbin/mopd/common/put.h b/usr.sbin/mopd/common/put.h
new file mode 100644
index 00000000000..c856c6d8fc0
--- /dev/null
+++ b/usr.sbin/mopd/common/put.h
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ *
+ * $Id: put.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _PUT_H_
+#define _PUT_H_
+
+#ifdef NO__P
+void mopPutChar (/* u_char *, int *, u_char */);
+void mopPutShort (/* u_char *, int *, u_short */);
+void mopPutLong (/* u_char *, int *, u_long */);
+void mopPutMulti (/* u_char *, int *, u_char *, int */);
+void mopPutTime (/* u_char *, int *, time_t */);
+void mopPutHeader (/* u_char *, int *, u_char *, u_char *, u_short, int */);
+void mopPutLength (/* u_char *, int, u_short */);
+#else
+__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_long));
+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
+
+#endif _PUT_H_
diff --git a/usr.sbin/mopd/common/rc.c b/usr.sbin/mopd/common/rc.c
new file mode 100644
index 00000000000..3a06c95073a
--- /dev/null
+++ b/usr.sbin/mopd/common/rc.c
@@ -0,0 +1,316 @@
+/*
+ * 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: rc.c,v 1.1 1996/09/21 13:49:16 maja Exp $";
+#endif
+
+#include "os.h"
+#include "common/get.h"
+#include "common/print.h"
+#include "common/mopdef.h"
+
+void
+mopDumpRC(fd, pkt, trans)
+ FILE *fd;
+ u_char *pkt;
+ int trans;
+{
+ int i,index = 0;
+ long 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);
+
+ 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/usr.sbin/mopd/common/rc.h b/usr.sbin/mopd/common/rc.h
new file mode 100644
index 00000000000..96c9a988810
--- /dev/null
+++ b/usr.sbin/mopd/common/rc.h
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ *
+ * $Id: rc.h,v 1.1 1996/09/21 13:49:16 maja Exp $
+ *
+ */
+
+#ifndef _RC_H_
+#define _RC_H_
+
+#ifdef NO__P
+void mopDumpRC (/* FILE *, u_char *, int */);
+#else
+__BEGIN_DECLS
+void mopDumpRC __P((FILE *, u_char *, int));
+__END_DECLS
+#endif
+
+#endif _RC_H_
diff --git a/usr.sbin/mopd/mopa.out/Makefile b/usr.sbin/mopd/mopa.out/Makefile
new file mode 100644
index 00000000000..dff003edbf2
--- /dev/null
+++ b/usr.sbin/mopd/mopa.out/Makefile
@@ -0,0 +1,10 @@
+
+# $Id: Makefile,v 1.1 1996/09/21 13:49:17 maja Exp $
+
+PROG= mopa.out
+SRCS= mopa.out.c file.c
+
+CFLAGS+= -I${.CURDIR} -I${.CURDIR}/.. -I${.CURDIR}/../common
+.PATH: ${.CURDIR}/../common
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/mopd/mopa.out/mopa.out.1 b/usr.sbin/mopd/mopa.out/mopa.out.1
new file mode 100644
index 00000000000..4b170243e48
--- /dev/null
+++ b/usr.sbin/mopd/mopa.out/mopa.out.1
@@ -0,0 +1,59 @@
+.\"
+.\" 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.
+.\"
+.\" @(#) $Id: mopa.out.1,v 1.1 1996/09/21 13:49:17 maja Exp $
+.\"
+.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 mopa.out
+.Ar infile
+.Ar outfile
+.Sh DESCRIPTION
+.Nm mopa.out
+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 just 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/usr.sbin/mopd/mopa.out/mopa.out.c b/usr.sbin/mopd/mopa.out/mopa.out.c
new file mode 100644
index 00000000000..b05f7733585
--- /dev/null
+++ b/usr.sbin/mopd/mopa.out/mopa.out.c
@@ -0,0 +1,154 @@
+
+/* 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: mopa.out.c,v 1.1 1996/09/21 13:49:17 maja Exp $";
+#endif
+
+#include "os.h"
+#include "common/common.h"
+#include "common/mopdef.h"
+#include "common/file.h"
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/exec_aout.h>
+#endif
+#if defined(__FreeBSD__)
+#include <sys/imgact_aout.h>
+#endif
+#if defined(__bsdi__)
+#include <a.out.h>
+#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;
+
+#ifdef NOAOUT
+ fprintf(stderr, "%s: has no function in OS/BSD\n", argv[0]);
+ return(1);
+#endif
+
+ if (argc != 3) {
+ fprintf (stderr, "usage: %s kernel-in sys-out\n", argv[0]);
+ return (1);
+ }
+
+ dl.ldfd = open (argv[1], O_RDONLY);
+ if (dl.ldfd == -1) {
+ perror (argv[1]);
+ return (2);
+ }
+
+ 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) {
+ fprintf(stderr,"s%: not an a.out file\n",argv[1]);
+ return (3);
+ }
+
+ if (dl.aout != MID_VAX) {
+ fprintf(stderr,"%s: file is not a VAX image (mid=%d)\n",
+ argv[1],dl.aout);
+ return (4);
+ }
+
+ 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) {
+ perror (argv[2]);
+ return (2);
+ }
+
+ /* Now we do the actual work. Write VAX MOP-image header */
+
+ fwrite (header, sizeof (header), 1, out);
+
+ fprintf (stderr, "copying %lu", dl.a_text);
+ fprintf (stderr, "+%lu", dl.a_data);
+ fprintf (stderr, "+%lu", dl.a_bss);
+ fprintf (stderr, "->%lu", dl.xferaddr);
+ fprintf (stderr, "\n");
+
+ while ((i = mopFileRead(&dl,header)) > 0) {
+ (void)fwrite(header, i, 1, out);
+ }
+
+ fclose (out);
+}
diff --git a/usr.sbin/mopd/mopchk/Makefile b/usr.sbin/mopd/mopchk/Makefile
new file mode 100644
index 00000000000..812345103cf
--- /dev/null
+++ b/usr.sbin/mopd/mopchk/Makefile
@@ -0,0 +1,18 @@
+# $Id: Makefile,v 1.1 1996/09/21 13:49:17 maja Exp $
+
+PROG= mopchk
+SRCS= mopchk.c device.c version.c pf.c loop-bsd.c file.c
+CFLAGS+= -I${.CURDIR} -I${.CURDIR}/.. -I${.CURDIR}/../common -DINFO
+CLEANFILES= version.c version.h
+LDADD= -lkvm
+.PATH: ${.CURDIR}/.. ${.CURDIR}/../common
+
+version.c version.h: ${.CURDIR}/../common/VERSION
+ rm -f version.c; \
+ sed 's/.*/char version[] = "&";/' ${.ALLSRC} > version.c
+ set `sed 's/\([0-9]*\)\.\([0-9]*\).*/\1 \2/' ${.ALLSRC}` ; \
+ { echo '#define VERSION_MAJOR' $$1 ; \
+ echo '#define VERSION_MINOR' $$2 ; } > version.h
+
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/mopd/mopchk/mopchk.1 b/usr.sbin/mopd/mopchk/mopchk.1
new file mode 100644
index 00000000000..7254c02b0bc
--- /dev/null
+++ b/usr.sbin/mopd/mopchk/mopchk.1
@@ -0,0 +1,65 @@
+.\"
+.\" 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.
+.\"
+.\" @(#) $Id: mopchk.1,v 1.1 1996/09/21 13:49:17 maja Exp $
+.\"
+.Dd October 2, 1995
+.Dt MOPCHK 1
+.Sh NAME
+.Nm mopchk
+.Nd MOP Check Utility
+.Sh SYNOPSIS
+.Nm mopchk
+.Op Fl a
+.Op Fl v
+.Op Ar filename
+.Sh DESCRIPTION
+.Nm Mopchk
+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 mopprobe.
+.El
+.Sh BUGS
+In some implementation the same interface can occure 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/usr.sbin/mopd/mopchk/mopchk.c b/usr.sbin/mopd/mopchk/mopchk.c
new file mode 100644
index 00000000000..7e57b931584
--- /dev/null
+++ b/usr.sbin/mopd/mopchk/mopchk.c
@@ -0,0 +1,177 @@
+/*
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: mopchk.c,v 1.1 1996/09/21 13:49:17 maja Exp $";
+#endif
+
+/*
+ * mopchk - MOP Check Utility
+ *
+ * Usage: mopchk [-a] [-v] [filename...]
+ */
+
+#include "os.h"
+#include "common/common.h"
+#include "common/mopdef.h"
+#include "common/device.h"
+#include "common/pf.h"
+#include "common/file.h"
+
+/*
+ * The list of all interfaces that are being listened to. rarp_loop()
+ * "selects" on the descriptors in this list.
+ */
+struct if_info *iflist;
+
+#ifdef NO__P
+void Usage (/* void */);
+void mopProcess (/* struct if_info *, u_char * */);
+#else
+void Usage __P((void));
+void mopProcess __P((struct if_info *, u_char *));
+#endif
+
+int AllFlag = 0; /* listen on "all" interfaces */
+int VersionFlag = 0; /* Show version */
+int promisc = 0; /* promisc mode not needed */
+char *Program;
+char version[];
+
+void
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int op, i, fd;
+ char *filename;
+ struct if_info *ii;
+ int err, aout;
+
+ extern int optind, opterr;
+
+ if ((Program = strrchr(argv[0], '/')))
+ Program++;
+ else
+ Program = argv[0];
+ if (*Program == '-')
+ Program++;
+
+ /* All error reporting is done through syslogs. */
+ openlog(Program, LOG_PID | LOG_CONS, LOG_DAEMON);
+
+ opterr = 0;
+ while ((op = getopt(argc, argv, "av")) != EOF) {
+ switch (op) {
+ case 'a':
+ AllFlag++;
+ break;
+ case 'v':
+ VersionFlag++;
+ break;
+ default:
+ Usage();
+ /* NOTREACHED */
+ }
+ }
+
+ if (VersionFlag)
+ printf("%s: Version %s\n",Program,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");
+ }
+ };
+ }
+ }
+
+}
+
+void
+Usage()
+{
+ (void) fprintf(stderr, "usage: %d [-a] [-v] [filename...]\n",Program);
+ exit(1);
+}
+
+/*
+ * Process incomming packages, NOT.
+ */
+void
+mopProcess(ii, pkt)
+ struct if_info *ii;
+ u_char *pkt;
+{
+}
+
diff --git a/usr.sbin/mopd/mopd/Makefile b/usr.sbin/mopd/mopd/Makefile
new file mode 100644
index 00000000000..bab3fc29bb9
--- /dev/null
+++ b/usr.sbin/mopd/mopd/Makefile
@@ -0,0 +1,20 @@
+# $Id: Makefile,v 1.1 1996/09/21 13:49:17 maja Exp $
+
+PROG= mopd
+SRCS= mopd.c process.c print.c cmp.c get.c put.c mopdef.c nma.c device.c \
+ version.c pf.c loop-bsd.c dl.c rc.c file.c
+MAN= mopd.8
+CFLAGS+= -I${.CURDIR} -I${.CURDIR}/.. -I${.CURDIR}/../common
+CLEANFILES= version.c version.h
+LDADD= -lkvm
+.PATH: ${.CURDIR}/../common
+
+version.c version.h: ${.CURDIR}/../common/VERSION
+ rm -f version.c; \
+ sed 's/.*/char version[] = "&";/' ${.ALLSRC} > version.c
+ set `sed 's/\([0-9]*\)\.\([0-9]*\).*/\1 \2/' ${.ALLSRC}` ; \
+ { echo '#define VERSION_MAJOR' $$1 ; \
+ echo '#define VERSION_MINOR' $$2 ; } > version.h
+
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/mopd/mopd/TODO b/usr.sbin/mopd/mopd/TODO
new file mode 100644
index 00000000000..720b58d7566
--- /dev/null
+++ b/usr.sbin/mopd/mopd/TODO
@@ -0,0 +1 @@
+Change code to send hostname instead of 'ipc'.
diff --git a/usr.sbin/mopd/mopd/mopd.8 b/usr.sbin/mopd/mopd/mopd.8
new file mode 100644
index 00000000000..08a68ba2b0f
--- /dev/null
+++ b/usr.sbin/mopd/mopd/mopd.8
@@ -0,0 +1,113 @@
+.\"
+.\" 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.
+.\"
+.\" @(#) $Id: mopd.8,v 1.1 1996/09/21 13:49:17 maja Exp $
+.\"
+.Dd September 24, 1995
+.Dt MOPD 8
+.Sh NAME
+.Nm mopd
+.Nd MOP Loader Daemon
+.Sh SYNOPSIS
+.Nm mopd
+.Op Fl adf
+.Op Ar interface
+.Sh DESCRIPTION
+.Nm Mopd
+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 mopd
+a filename can be given. This is the normal case for e.g. terminal servers.
+If a filename isn't given
+.Nm mopd
+must know what image to load.
+.Pp
+Upon receiving a request,
+.Nm mopd
+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 Mopd
+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 mopd
+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 BUGS
+.Xr a.out 5
+isn't supported yet non bsd implementations (otherOS).
+.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/usr.sbin/mopd/mopd/mopd.c b/usr.sbin/mopd/mopd/mopd.c
new file mode 100644
index 00000000000..7aa880335f6
--- /dev/null
+++ b/usr.sbin/mopd/mopd/mopd.c
@@ -0,0 +1,241 @@
+/*
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: mopd.c,v 1.1 1996/09/21 13:49:17 maja Exp $";
+#endif
+
+/*
+ * mopd - MOP Dump/Load Daemon
+ *
+ * Usage: mopd -a [ -d -f -v ] [ -3 | -4 ]
+ * mopd [ -d -f -v ] [ -3 | -4 ] interface
+ */
+
+#include "os.h"
+#include "common/common.h"
+#include "common/mopdef.h"
+#include "common/device.h"
+#include "common/print.h"
+#include "common/pf.h"
+#include "common/cmp.h"
+#include "common/get.h"
+#include "common/dl.h"
+#include "common/rc.h"
+#include "process.h"
+
+/*
+ * The list of all interfaces that are being listened to.
+ * "selects" on the descriptors in this list.
+ */
+struct if_info *iflist;
+
+#ifdef NO__P
+void Loop (/* void */);
+void Usage (/* void */);
+void mopProcess (/* struct if_info *, u_char * */);
+#else
+void Loop __P((void));
+void Usage __P((void));
+void mopProcess __P((struct if_info *, u_char *));
+#endif
+
+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 */
+char *Program;
+
+void
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int c, pid, devnull, f;
+ char *interface;
+
+ extern int optind;
+ extern char version[];
+
+ if ((Program = strrchr(argv[0], '/')))
+ Program++;
+ else
+ Program = argv[0];
+
+ if (*Program == '-')
+ Program++;
+
+ while ((c = getopt(argc, argv, "34adfv")) != EOF)
+ 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", Program, 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(Program, LOG_PID | LOG_CONS, LOG_DAEMON);
+
+ if ((!ForegroundFlag) && DebugFlag) {
+ fprintf(stdout,
+ "%s: not running as daemon, -d given.\n",
+ Program);
+ }
+
+ 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 */
+ f = open("/dev/tty", O_RDWR);
+ if (f >= 0) {
+ if (ioctl(f, TIOCNOTTY, 0) < 0) {
+ syslog(LOG_ERR, "TIOCNOTTY: %m");
+ exit(0);
+ }
+ (void) close(f);
+ }
+
+ (void) chdir("/");
+#ifdef SETPGRP_NOPARAM
+ (void) setpgrp();
+#else
+ (void) setpgrp(0, getpid());
+#endif
+ devnull = open("/dev/null", O_RDWR);
+ if (devnull >= 0) {
+ (void) dup2(devnull, 0);
+ (void) dup2(devnull, 1);
+ (void) dup2(devnull, 2);
+ if (devnull > 2)
+ (void) close(devnull);
+ }
+ }
+
+ syslog(LOG_INFO, "%s %s started.", Program, version);
+
+ if (AllFlag)
+ deviceInitAll();
+ else
+ deviceInitOne(interface);
+
+ Loop();
+}
+
+void
+Usage()
+{
+ (void) fprintf(stderr, "usage: %s -a [ -d -f -v ] [ -3 | -4 ]\n",Program);
+ (void) fprintf(stderr, " %s [ -d -f -v ] [ -3 | -4 ] interface\n",Program);
+ 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/usr.sbin/mopd/mopd/process.c b/usr.sbin/mopd/mopd/process.c
new file mode 100644
index 00000000000..ae2a8e6c4f7
--- /dev/null
+++ b/usr.sbin/mopd/mopd/process.c
@@ -0,0 +1,637 @@
+/*
+ * 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: process.c,v 1.1 1996/09/21 13:49:17 maja Exp $";
+#endif
+
+#include "os.h"
+#include "common/common.h"
+#include "common/mopdef.h"
+#include "common/nmadef.h"
+#include "common/get.h"
+#include "common/put.h"
+#include "common/print.h"
+#include "common/pf.h"
+#include "common/cmp.h"
+#include "common/dl.h"
+#include "common/rc.h"
+#include "common/file.h"
+
+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
+mopProcessInfo(pkt,index,moplen,dl_rpr,trans)
+ u_char *pkt;
+ int *index, trans;
+ u_short moplen;
+ struct dllist *dl_rpr;
+{
+ 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");
+ }
+ }
+}
+
+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;
+ bcopy((char *)dst,
+ (char *)dllist[i].eaddr, 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 >= 1492)
+ dllist[slot].dl_bsz = 1492;
+ if (dllist[slot].dl_bsz == 1030) /* VS/uVAX 2000 needs this */
+ dllist[slot].dl_bsz = 1000;
+ 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;
+
+ 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, line);
+ return;
+ }
+
+ dllist[slot].lseek = lseek(dllist[slot].ldfd,0L,SEEK_CUR);
+
+ if (dllist[slot].dl_bsz >= 1492)
+ dllist[slot].dl_bsz = 1492;
+
+ 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) {
+ 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,3);
+ mopPutMulti(pkt,&index,"ipc",3);
+ 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, *dst, *src;
+ int *index, trans;
+ u_short len;
+{
+ u_char tmpc;
+ u_short moplen;
+ u_char pfile[17], 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 */
+ 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;
+ bzero(dl_rpr,sizeof(*dl_rpr));
+ dl_rpr->ii = ii;
+ bcopy((char *)src, (char *)(dl_rpr->eaddr), 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, 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, 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, *dst, *src;
+ int *index, 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;
+ bzero(dl_rpr,sizeof(*dl_rpr));
+ dl_rpr->ii = ii;
+ bcopy((char *)src, (char *)(dl_rpr->eaddr), 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/usr.sbin/mopd/mopd/process.h b/usr.sbin/mopd/mopd/process.h
new file mode 100644
index 00000000000..eda920a3285
--- /dev/null
+++ b/usr.sbin/mopd/mopd/process.h
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ *
+ * $Id: process.h,v 1.1 1996/09/21 13:49:17 maja Exp $
+ *
+ */
+
+#ifndef _PROCESS_H_
+#define _PROCESS_H_
+
+#ifdef NO__P
+void mopProcessDL (/* FILE *, struct if_info *, u_char *, int *,
+ u_char *, u_char *, int, u_short */);
+void mopProcessRC (/* FILE *, struct if_info *, u_char *, int *,
+ u_char *, u_char *, int, u_short */);
+#else
+__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
+
+#endif _PROCESS_H_
diff --git a/usr.sbin/mopd/mopprobe/Makefile b/usr.sbin/mopd/mopprobe/Makefile
new file mode 100644
index 00000000000..8658b4423ce
--- /dev/null
+++ b/usr.sbin/mopd/mopprobe/Makefile
@@ -0,0 +1,17 @@
+# $Id: Makefile,v 1.1 1996/09/21 13:49:17 maja Exp $
+
+PROG= mopprobe
+SRCS= mopprobe.c device.c get.c cmp.c mopdef.c version.c pf.c loop-bsd.c
+CFLAGS+= -I${.CURDIR} -I${.CURDIR}/.. -I${.CURDIR}/../common -DNODL
+CLEANFILES= version.c version.h
+LDADD= -lkvm
+.PATH: ${.CURDIR}/../common
+
+version.c version.h: ${.CURDIR}/../common/VERSION
+ rm -f version.c; \
+ sed 's/.*/char version[] = "&";/' ${.ALLSRC} > version.c
+ set `sed 's/\([0-9]*\)\.\([0-9]*\).*/\1 \2/' ${.ALLSRC}` ; \
+ { echo '#define VERSION_MAJOR' $$1 ; \
+ echo '#define VERSION_MINOR' $$2 ; } > version.h
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/mopd/mopprobe/mopprobe.1 b/usr.sbin/mopd/mopprobe/mopprobe.1
new file mode 100644
index 00000000000..cdb3fa8566b
--- /dev/null
+++ b/usr.sbin/mopd/mopprobe/mopprobe.1
@@ -0,0 +1,70 @@
+.\"
+.\" 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.
+.\"
+.\" @(#) $Id: mopprobe.1,v 1.1 1996/09/21 13:49:17 maja Exp $
+.\"
+.Dd October 2, 1995
+.Dt MOPPROBE 1
+.Sh NAME
+.Nm mopprobe
+.Nd MOP Probe Utility
+.Sh SYNOPSIS
+.Nm mopprobe
+.Fl a
+.Op Fl 3 | 4
+.Pp
+.Nm mopprobe
+.Op Fl 3 | 4
+.Ar interface
+.Sh DESCRIPTION
+.Nm Mopprobe
+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/usr.sbin/mopd/mopprobe/mopprobe.c b/usr.sbin/mopd/mopprobe/mopprobe.c
new file mode 100644
index 00000000000..819f95eccf4
--- /dev/null
+++ b/usr.sbin/mopd/mopprobe/mopprobe.c
@@ -0,0 +1,292 @@
+/*
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: mopprobe.c,v 1.1 1996/09/21 13:49:17 maja Exp $";
+#endif
+
+/*
+ * mopprobe - MOP Probe Utility
+ *
+ * Usage: mopprobe -a [ -3 | -4 ]
+ * mopprobe [ -3 | -4 ] interface
+ */
+
+#include "os.h"
+#include "common/common.h"
+#include "common/mopdef.h"
+#include "common/device.h"
+#include "common/print.h"
+#include "common/get.h"
+#include "common/cmp.h"
+#include "common/pf.h"
+#include "common/nmadef.h"
+
+/*
+ * The list of all interfaces that are being listened to. rarp_loop()
+ * "selects" on the descriptors in this list.
+ */
+struct if_info *iflist;
+
+#ifdef NO__P
+void Loop (/* void */);
+void Usage (/* void */);
+void mopProcess (/* struct if_info *, u_char * */);
+#else
+void Loop __P((void));
+void Usage __P((void));
+void mopProcess __P((struct if_info *, u_char *));
+#endif
+
+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 */
+char *Program;
+
+void
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int op;
+ char *interface;
+
+ extern int optind, opterr;
+
+ if ((Program = strrchr(argv[0], '/')))
+ Program++;
+ else
+ Program = argv[0];
+ if (*Program == '-')
+ Program++;
+
+ /* All error reporting is done through syslogs. */
+ openlog(Program, LOG_PID | LOG_CONS, LOG_DAEMON);
+
+ opterr = 0;
+ while ((op = getopt(argc, argv, "ado")) != EOF) {
+ 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();
+}
+
+void
+Usage()
+{
+ (void) fprintf(stderr, "usage: %s -a [ -3 | -4 ]\n",Program);
+ (void) fprintf(stderr, " %s [ -3 | -4 ] interface\n",Program);
+ 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/usr.sbin/mopd/moptrace/Makefile b/usr.sbin/mopd/moptrace/Makefile
new file mode 100644
index 00000000000..952f7e6673d
--- /dev/null
+++ b/usr.sbin/mopd/moptrace/Makefile
@@ -0,0 +1,20 @@
+# $Id: Makefile,v 1.1 1996/09/21 13:49:17 maja Exp $
+
+PROG= moptrace
+SRCS= moptrace.c print.c cmp.c get.c mopdef.c nma.c device.c version.c pf.c \
+ loop-bsd.c dl.c rc.c
+MAN= moptrace.1
+CFLAGS+= -I${.CURDIR} -I${.CURDIR}/.. -I${.CURDIR}/../common
+CLEANFILES= version.c version.h
+LDADD= -lkvm
+.PATH: ${.CURDIR}/../common
+
+version.c version.h: ${.CURDIR}/../common/VERSION
+ rm -f version.c; \
+ sed 's/.*/char version[] = "&";/' ${.ALLSRC} > version.c
+ set `sed 's/\([0-9]*\)\.\([0-9]*\).*/\1 \2/' ${.ALLSRC}` ; \
+ { echo '#define VERSION_MAJOR' $$1 ; \
+ echo '#define VERSION_MINOR' $$2 ; } > version.h
+
+
+.include <bsd.prog.mk>
diff --git a/usr.sbin/mopd/moptrace/moptrace.1 b/usr.sbin/mopd/moptrace/moptrace.1
new file mode 100644
index 00000000000..2553467500a
--- /dev/null
+++ b/usr.sbin/mopd/moptrace/moptrace.1
@@ -0,0 +1,83 @@
+.\"
+.\" 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.
+.\"
+.\" @(#) $Id: moptrace.1,v 1.1 1996/09/21 13:49:17 maja Exp $
+.\"
+.Dd October 2, 1995
+.Dt MOPTRACE 1
+.Sh NAME
+.Nm moptrace
+.Nd MOP Trace Utility
+.Sh SYNOPSIS
+.Nm moptrace
+.Op Fl a
+.Op Fl d
+.Op Fl 3 | 4
+.Pp
+.Nm moptrace
+.Op Fl d
+.Op Fl 3 | 4
+.Op Ar interface
+.Sh DESCRIPTION
+.Nm Moptrace
+prints the contence 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/usr.sbin/mopd/moptrace/moptrace.c b/usr.sbin/mopd/moptrace/moptrace.c
new file mode 100644
index 00000000000..3d55a30d38f
--- /dev/null
+++ b/usr.sbin/mopd/moptrace/moptrace.c
@@ -0,0 +1,169 @@
+/*
+ * 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: moptrace.c,v 1.1 1996/09/21 13:49:17 maja 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/mopdef.h"
+#include "common/device.h"
+#include "common/print.h"
+#include "common/pf.h"
+#include "common/dl.h"
+#include "common/rc.h"
+#include "common/get.h"
+
+/*
+ * The list of all interfaces that are being listened to.
+ * "selects" on the descriptors in this list.
+ */
+struct if_info *iflist;
+
+#ifdef NO__P
+void Loop (/* void */);
+void Usage (/* void */);
+void mopProcess (/* struct if_info *, u_char * */);
+#else
+void Loop __P((void));
+void Usage __P((void));
+void mopProcess __P((struct if_info *, u_char *));
+#endif
+
+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 */
+char *Program;
+
+void
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ int op;
+ char *interface;
+
+ extern int optind, opterr;
+
+ if ((Program = strrchr(argv[0], '/')))
+ Program++;
+ else
+ Program = argv[0];
+
+ if (*Program == '-')
+ Program++;
+
+ /* All error reporting is done through syslogs. */
+ openlog(Program, LOG_PID | LOG_CONS, LOG_DAEMON);
+
+ opterr = 0;
+ while ((op = getopt(argc, argv, "34ad")) != EOF) {
+ 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();
+}
+
+void
+Usage()
+{
+ (void) fprintf(stderr, "usage: %s -a [ -d ] [ -3 | -4 ]\n",Program);
+ (void) fprintf(stderr, " %s [ -d ] [ -3 | -4 ] interface\n",
+ Program);
+ 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);
+}
+
+
diff --git a/usr.sbin/mopd/otherOS/Makefile b/usr.sbin/mopd/otherOS/Makefile
new file mode 100644
index 00000000000..4d7a8288890
--- /dev/null
+++ b/usr.sbin/mopd/otherOS/Makefile
@@ -0,0 +1,172 @@
+# Copyright (c) 1993-1994 Mats O Jansson, Stockholm, Sweden
+# All rights reserved.
+#
+# @(#) $Id: Makefile,v 1.1 1996/09/21 13:49:17 maja Exp $
+
+# Script (or program) that returns the machine and os types,
+# or jsut edit in the name yourself.
+MD=`./mdtype`
+OS=`./ostype`
+
+CCOPT = -O
+INCLUDES = -I..
+#rs6000-aix3#DEFINES = -D_AIX -D_BSD -DNO__P
+
+#mopchk#SPEC_FLAGS= -DINFO -DNODL -DNOAOUT
+#mopd#SPEC_FLAGS= -DNOAOUT
+#mopprobe#SPEC_FLAGS= -DNODL
+#moptrace#SPEC_FLAGS=
+
+# Standard CFLAGS
+STANDARD_CFLAGS = $(CCOPT) $(SPEC_FLAGS) $(DEFINES) $(INCLUDES)
+
+# CFLAGS definitions per machine vs. os
+#sun3-sunos4#CFLAGS = $(STANDARD_CFLAGS) -DNO__P
+#sun4-sunos4#CFLAGS = $(STANDARD_CFLAGS) -DNO__P
+#sun4-sunos5#CFLAGS = $(STANDARD_CFLAGS) -DNO__P -DDLPIPF
+#rs6000-aix3#CFLAGS = $(STANDARD_CFLAGS)
+
+#sun4-sunos5#LIB = -lsocket
+
+# Change these to cc/lex/yacc if you don't have gcc, flex and/or bison.
+CC = cc
+LEX = lex
+YACC = yacc -y
+MAKE = make
+
+# Explicitly define compiliation rule since SunOS 4's make doesn't like gcc.
+# Also, gcc does not remove the .o before forking 'as', which can be a
+# problem if you don't own the file but can write to the directory.
+.c.o:
+ rm -f $@; $(CC) $(CFLAGS) -c $*.c
+
+DIRS= mopchk mopd mopprobe moptrace
+
+CHFIL= mopchk.c
+CHOBJ= mopchk.o
+CHHDR=
+LDFIL= mopd.c process.c
+LDOBJ= mopd.o process.o
+LDHDR= process.h
+PBFIL= mopprobe.c
+PBOBJ= mopprobe.o
+PBHDR=
+TRFIL= moptrace.c
+TROBJ= moptrace.o
+TRHDR=
+
+#sun3-sunos4#OSHDR= os-sunos4.h
+#sun3-sunos4#PFFIL= pf-snit.c
+#sun3-sunos4#LOOP= loop.c
+
+#sun4-sunos4#OSHDR= os-sunos4.h
+#sun4-sunos4#PFFIL= pf-snit.c
+#sun4-sunos4#LOOP= loop.c
+
+#rs6000-aix3#OSHDR= os-aix3.h
+#rs6000-aix3#PFFIL= pf-aix3.c
+#rs6000-aix3#LOOP= loop.c
+
+#mopchk#COFIL= device.c file.c mopdef.c
+#mopchk#COOBJ= device.o file.o mopdef.o
+#mopchk#OTOBJ= pf.o loop.o
+
+#mopd#COFIL= cmp.c device.c dl.c file.c get.c mopdef.c nma.c print.c put.c rc.c
+#mopd#COOBJ= cmp.o device.o dl.o file.o get.o mopdef.o nma.o print.o put.o rc.o
+#mopd#OTOBJ= pf.o loop.o
+
+#mopprobe#COFIL= cmp.c device.c get.c mopdef.c
+#mopprobe#COOBJ= cmp.o device.o get.o mopdef.o
+#mopprobe#OTOBJ= pf.o loop.o
+
+#moptrace#COFIL= cmp.c device.c dl.c get.c mopdef.c nma.c print.c rc.c
+#moptrace#COOBJ= cmp.o device.o dl.o get.o mopdef.o nma.o print.o rc.o
+#moptrace#OTOBJ= pf.o loop.o
+
+toplvl: osmake
+
+oslvl: submake
+
+#mopchk#image: mopchk
+
+#mopd#image: mopd
+
+#mopprobe#image: mopprobe
+
+#moptrace#image: moptrace
+
+MFLAGS=
+
+osmake: force
+ @dir=$(MD)-$(OS); \
+ if [ ! -d $$dir ]; then ${MAKE} ${MFLAGS} config; fi; \
+ cd $$dir; ${MAKE} ${MFLAGS}
+
+submake: force
+ -@for i in $(DIRS); do if [ ! -d $$i ]; then mkdir $$i; chmod ug+w $$i; \
+ sed -e "/^oslvl:/d" -e "s/^#$$i#//" Makefile >$$i/Makefile; \
+ chmod ug+w $$i/Makefile; cd $$i; \
+ ${MAKE} ${MFLAGS} files; cd ..; fi; done; \
+ for i in $(DIRS); do cd $$i; ${MAKE} ${MFLAGS}; cd ..; done
+
+config:
+ @md=$(MD); os=$(OS); dir=$$md-$$os; \
+ mkdir $$dir; chmod ug+w $$dir; \
+ sed -e "/^toplvl:/d" -e "s/^#$$dir#//" Makefile >$$dir/Makefile; \
+ chmod ug+w $$dir/Makefile
+
+#mopchk#files: force
+#mopchk# echo "Adding files in mopchk"; \
+#mopchk# ln -s ../../../common common; \
+#mopchk# for i in $(CHFIL) $(CHHDR); do ln -s ../../../mopchk/$$i $$i; done; \
+#mopchk# for i in $(COFIL); do ln -s ../../../common/$$i $$i; done; \
+#mopchk# ln -s ../../$(OSHDR) os.h; ln -s ../../$(PFFIL) pf.c; \
+#mopchk# ln -s ../../$(LOOP) loop.c
+
+#mopd#files: force
+#mopd# echo "Adding files in mopd"; \
+#mopd# ln -s ../../../common common; \
+#mopd# for i in $(LDFIL) $(LDHDR); do ln -s ../../../mopd/$$i $$i; done; \
+#mopd# for i in $(COFIL); do ln -s ../../../common/$$i $$i; done; \
+#mopd# ln -s ../../$(OSHDR) os.h; ln -s ../../$(PFFIL) pf.c; \
+#mopd# ln -s ../../$(LOOP) loop.c
+
+#mopprobe#files: force
+#mopprobe# echo "Adding files in mopprobe"; \
+#mopprobe# ln -s ../../../common common; \
+#mopprobe# for i in $(PBFIL) $(PBHDR); do ln -s ../../../mopprobe/$$i $$i; done; \
+#mopprobe# for i in $(COFIL); do ln -s ../../../common/$$i $$i; done; \
+#mopprobe# ln -s ../../$(OSHDR) os.h; ln -s ../../$(PFFIL) pf.c; \
+#mopprobe# ln -s ../../$(LOOP) loop.c
+
+#moptrace#files: force
+#moptrace# echo "Adding files in moptrace"; \
+#moptrace# ln -s ../../../common common; \
+#moptrace# for i in $(TRFIL) $(TRHDR); do ln -s ../../../moptrace/$$i $$i; done; \
+#moptrace# for i in $(COFIL); do ln -s ../../../common/$$i $$i; done; \
+#moptrace# ln -s ../../$(OSHDR) os.h; ln -s ../../$(PFFIL) pf.c; \
+#moptrace# ln -s ../../$(LOOP) loop.c
+
+mopchk: $(CHOBJ) $(COOBJ) $(OTOBJ) version.o
+ $(CC) $(CFLAGS) -o $@ $(CHOBJ) $(COOBJ) $(OTOBJ) version.o $(LIB)
+
+mopd: $(LDOBJ) $(COOBJ) $(OTOBJ) version.o
+ $(CC) $(CFLAGS) -o $@ $(LDOBJ) $(COOBJ) $(OTOBJ) version.o $(LIB)
+
+mopprobe: $(PBOBJ) $(COOBJ) $(OTOBJ) version.o
+ $(CC) $(CFLAGS) -o $@ $(PBOBJ) $(COOBJ) $(OTOBJ) version.o $(LIB)
+
+moptrace: $(TROBJ) $(COOBJ) $(OTOBJ) version.o
+ $(CC) $(CFLAGS) -o $@ $(TROBJ) $(COOBJ) $(OTOBJ) version.o $(LIB)
+
+VERSION:
+ @ln -s ../../../common/VERSION VERSION
+
+version.o: version.c
+version.c version.h: 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
+
+force: /tmp
diff --git a/usr.sbin/mopd/otherOS/loop.c b/usr.sbin/mopd/otherOS/loop.c
new file mode 100644
index 00000000000..656f6681065
--- /dev/null
+++ b/usr.sbin/mopd/otherOS/loop.c
@@ -0,0 +1,178 @@
+/*
+ * 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.c,v 1.1 1996/09/21 13:49:17 maja Exp $";
+#endif
+
+#include "os.h"
+#include "common/common.h"
+#include "common/mopdef.h"
+
+/*
+ * The list of all interfaces that are being listened to. loop()
+ * "selects" on the descriptors in this list.
+ */
+struct if_info *iflist;
+u_char buf[BUFSIZE];
+
+void mopProcess (/* struct if_info *, u_char * */);
+
+int
+mopOpenRC(p, trans)
+ struct if_info *p;
+ int trans;
+{
+#ifndef NORC
+ int fd;
+
+ fd = (*(p->iopen))(p->if_name,
+ O_RDWR,
+ MOP_K_PROTO_RC,
+ trans);
+ if (fd >= 0) {
+ pfAddMulti(fd, p->if_name, rc_mcst);
+ pfEthAddr(fd, p->eaddr);
+ }
+
+ return fd;
+#else
+ return -1;
+#endif
+}
+
+int
+mopOpenDL(p, trans)
+ struct if_info *p;
+ int trans;
+{
+#ifndef NODL
+ int fd;
+
+ fd = (*(p->iopen))(p->if_name,
+ O_RDWR,
+ MOP_K_PROTO_DL,
+ trans);
+ if (fd >= 0) {
+ pfAddMulti(fd, p->if_name, dl_mcst);
+ pfEthAddr(fd, p->eaddr);
+ }
+
+ return fd;
+#else
+ return -1;
+#endif
+}
+
+void
+mopReadRC(p, fd)
+ struct if_info *p;
+ int fd;
+{
+ int cc;
+
+ if ((cc = pfRead(fd, buf+HDRSIZ, BUFSIZE-HDRSIZ)) < 0) {
+ return;
+ }
+
+ if (cc == 0)
+ return;
+
+ mopProcess(p, buf+HDRSIZ);
+
+ return;
+}
+
+void
+mopReadDL(p, fd)
+ struct if_info *p;
+ int fd;
+{
+ int cc;
+
+ if ((cc = pfRead(fd, buf+HDRSIZ, BUFSIZE-HDRSIZ)) < 0) {
+ return;
+ }
+
+ if (cc == 0)
+ return;
+
+ mopProcess(p, buf+HDRSIZ);
+
+ return;
+}
+
+/*
+ * Loop indefinitely listening for MOP requests on the
+ * interfaces in 'iflist'.
+ */
+void
+Loop()
+{
+ fd_set fds, listeners;
+ int maxfd = 0;
+ struct if_info *ii;
+
+ if (iflist == 0) {
+ fprintf(stderr,"no interfaces");
+ 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) {
+ fprintf(stderr, "select: %s");
+ exit(0);
+ }
+ for (ii = iflist; ii; ii = ii->next) {
+ if (ii->fd != -1) {
+ if (FD_ISSET(ii->fd, &listeners))
+ (*(ii->read))(ii,ii->fd);
+ }
+ }
+ }
+}
+
+
+
+
+
diff --git a/usr.sbin/mopd/otherOS/mdtype b/usr.sbin/mopd/otherOS/mdtype
new file mode 100644
index 00000000000..802f6f5dbcf
--- /dev/null
+++ b/usr.sbin/mopd/otherOS/mdtype
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+# @(#) $Id: mdtype,v 1.1 1996/09/21 13:49:17 maja Exp $
+#
+# Determine machine type.
+#
+machine="UNKNOWN"
+
+if [ -f /usr/bin/uname ]; then
+
+ os=`/usr/bin/uname`
+
+ if [ $os = "AIX" ]; then
+ if [ "`/usr/bin/uname -v`" = "3" ]; then
+ machine="rs6000"
+ fi
+ if [ "`/usr/bin/uname -v`" = "4" ]; then
+ hw="`/usr/sbin/lsattr -l proc0 -E -a type | /usr/bin/cut -d\ -f2`"
+ if [ $hw = "PowerPC_601" ]; then
+ machine="rs6000"
+ fi
+ if [ $hw = "POWER" ]; then
+ machine="rs6000"
+ fi
+ if [ $hw = "POWER2" ]; then
+ machine="rs6000"
+ fi
+ fi
+ fi
+
+ if [ $os = "SunOS" ]; then
+ machine="`/usr/bin/uname -m |/usr/bin/cut -c1-4 `"
+ fi
+
+ if [ $os = "NetBSD" ]; then
+ machine="`/usr/bin/uname -m`"
+ fi
+
+ if [ $machine = "sparc" ]; then
+ machine="sun4"
+ fi
+
+fi
+
+echo $machine
+
+if [ $machine = "UNKNOWN" ]; then
+ exit 1
+else
+ exit 0
+fi
diff --git a/usr.sbin/mopd/otherOS/os-sunos4.h b/usr.sbin/mopd/otherOS/os-sunos4.h
new file mode 100644
index 00000000000..00ba44985a1
--- /dev/null
+++ b/usr.sbin/mopd/otherOS/os-sunos4.h
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ *
+ * @(#) $Id: os-sunos4.h,v 1.1 1996/09/21 13:49:17 maja Exp $
+ */
+
+#include <stdio.h>
+
+#define FILENAME_MAX 255 /* SunOS 4 is missing it */
+
+#include <syslog.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <time.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+typedef int ssize_t;
diff --git a/usr.sbin/mopd/otherOS/ostype b/usr.sbin/mopd/otherOS/ostype
new file mode 100644
index 00000000000..fe5704adcd5
--- /dev/null
+++ b/usr.sbin/mopd/otherOS/ostype
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# @(#) $Id: ostype,v 1.1 1996/09/21 13:49:17 maja Exp $
+#
+# Determine os type.
+#
+os="UNKNOWN"
+
+if [ -f /usr/bin/uname ]; then
+
+ osname=`/usr/bin/uname`
+
+ if [ $osname = "AIX" ]; then
+ os="aix`/usr/bin/uname -v`"
+ fi
+
+ if [ $osname = "SunOS" ]; then
+ os="sunos`/usr/bin/uname -r | /usr/bin/cut -c1`"
+ fi
+
+ if [ $osname = "NetBSD" ]; then
+ os="netbsd"
+ fi
+
+fi
+
+echo $os
+
+if [ $os = "UNKNOWN" ]; then
+ exit 1
+else
+ exit 0
+fi
diff --git a/usr.sbin/mopd/otherOS/pf-snit.c b/usr.sbin/mopd/otherOS/pf-snit.c
new file mode 100644
index 00000000000..8926a7b23d3
--- /dev/null
+++ b/usr.sbin/mopd/otherOS/pf-snit.c
@@ -0,0 +1,340 @@
+/*
+ * 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.
+ */
+
+#ifndef LINT
+static char rcsid[] = "$Id: pf-snit.c,v 1.1 1996/09/21 13:49:17 maja Exp $";
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <net/if.h>
+
+#define DEV_NIT "/dev/nit"
+#include <net/nit.h>
+#include <net/nit_if.h>
+#include <net/nit_pf.h>
+#include <net/nit_buf.h>
+#include <net/packetfilt.h>
+#include <stropts.h>
+
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+
+#include <netdb.h>
+#include <ctype.h>
+#include <syslog.h>
+
+#include "common/mopdef.h"
+
+/*
+ * Variables
+ */
+
+/* struct ifreq ifr; */
+extern int errno;
+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, trans)
+ char *interface;
+ u_short protocol;
+ int trans, mode;
+{
+ int fd;
+ int ioarg;
+ char device[64];
+ unsigned long if_flags;
+
+ struct ifreq ifr;
+ struct strioctl si;
+
+ /* get clone */
+ if ((fd = open(DEV_NIT, mode)) < 0) {
+ syslog(LOG_ERR,"pfInit: open nit %m");
+ return(-1);
+ }
+
+ /*
+ * set filter for protocol
+ */
+
+ if (setup_pf(fd, protocol, trans) < 0)
+ return(-1);
+
+ /*
+ * set options, bind to underlying interface
+ */
+
+ strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
+
+ /* bind */
+ si.ic_cmd = NIOCBIND; /* bind to underlying interface */
+ si.ic_timout = 10;
+ si.ic_len = sizeof(ifr);
+ si.ic_dp = (caddr_t)&ifr;
+ if (ioctl(fd, I_STR, (caddr_t)&si) < 0) {
+ syslog(LOG_ERR,"pfinit: I_STR %m");
+ return(-1);
+ }
+
+ if (promisc) {
+ if_flags = NI_PROMISC;
+ si.ic_cmd = NIOCSFLAGS;
+ si.ic_timout = 10;
+ si.ic_len = sizeof(if_flags);
+ si.ic_dp = (caddr_t)&if_flags;
+ if (ioctl(fd, I_STR, (caddr_t)&si) < 0) {
+ syslog(LOG_ERR,"pfInit: I_STR (promisc) %m");
+ return(-1);
+ }
+ }
+
+ /* set up messages */
+ if (ioctl(fd, I_SRDOPT, (char *)RMSGD) < 0) { /* want messages */
+ syslog(LOG_ERR,"pfInit: I_SRDOPT %m");
+ return(-1);
+ }
+
+ /* flush read queue */
+ if (ioctl(fd, I_FLUSH, (char *)FLUSHR) < 0) {
+ syslog(LOG_ERR,"pfInit: I_FLUSH %m");
+ return(-1);
+ }
+
+ return(fd);
+}
+
+/*
+ * establish protocol filter
+ */
+
+int
+setup_pf(s, prot, trans)
+ int s, trans;
+ u_short prot;
+{
+ int ioarg;
+ u_short offset;
+
+ struct packetfilt pf;
+ register u_short *fwp = pf.Pf_Filter;
+ struct strioctl si;
+
+#define s_offset(structp, element) (&(((structp)0)->element))
+
+ bzero(&pf, sizeof(pf));
+ pf.Pf_Priority = 128;
+
+ offset = ((int)s_offset(struct ether_header *, ether_type))/sizeof(u_short);
+ *fwp++ = ENF_PUSHWORD + offset; /* Check Ethernet type II */
+ *fwp++ = ENF_PUSHLIT | ENF_EQ; /* protocol prot */
+ *fwp++ = htons(prot);
+ *fwp++ = ENF_PUSHWORD + offset + 4; /* Check 802.3 protocol prot */
+ *fwp++ = ENF_PUSHLIT | ENF_EQ;
+ *fwp++ = htons(prot);
+ *fwp++ = ENF_PUSHWORD + offset + 1; /* Check for SSAP and DSAP */
+ *fwp++ = ENF_PUSHLIT | ENF_EQ;
+ *fwp++ = htons(0xaaaa);
+ *fwp++ = ENF_AND;
+ *fwp++ = ENF_OR;
+ pf.Pf_FilterLen = 11;
+
+ si.ic_cmd = NIOCSETF;
+ si.ic_timout = 10;
+ si.ic_len = sizeof(pf);
+ si.ic_dp = (char *)&pf;
+ if (ioctl(s, I_PUSH, "pf") < 0) {
+ syslog(LOG_ERR,"setup_pf: I_PUSH %m");
+ return(-1);
+ }
+ if (ioctl(s, I_STR, (char *)&si) < 0) {
+ syslog(LOG_ERR,"setup_pf: I_STR %m");
+ return(-1);
+ }
+
+ return(0);
+}
+
+/*
+ * Get the interface ethernet address
+ */
+
+int
+pfEthAddr(fd, addr)
+int fd;
+u_char *addr;
+{
+ struct ifreq ifr;
+ struct sockaddr *sa;
+
+ if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) {
+ syslog(LOG_ERR,"pfEthAddr: SIOCGIFADDR %m");
+ return(-1);
+ }
+ sa = (struct sockaddr *)ifr.ifr_data;
+ bcopy((char *)sa->sa_data, (char *)addr, 6);
+
+ return(0);
+}
+
+/*
+ * 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;
+ bcopy(addr, ifr.ifr_addr.sa_data, 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;
+ bcopy(addr, ifr.ifr_addr.sa_data, 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,"pfDelMulti: 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 sockaddr sa;
+ struct strbuf pbuf, dbuf;
+
+ sa.sa_family = AF_UNSPEC;
+ bcopy(buf, sa.sa_data, sizeof(sa.sa_data));
+
+ switch (trans) {
+ default:
+ pbuf.len = sizeof(struct sockaddr);
+ pbuf.buf = (char *) &sa;
+ dbuf.len = len-14;
+ dbuf.buf = (char *)buf+14;
+ break;
+ }
+
+ if (putmsg(fd, &pbuf, &dbuf, 0) == 0)
+ return(len);
+
+ return(-1);
+}