diff options
author | Mats O Jansson <maja@cvs.openbsd.org> | 1996-09-21 13:49:18 +0000 |
---|---|---|
committer | Mats O Jansson <maja@cvs.openbsd.org> | 1996-09-21 13:49:18 +0000 |
commit | d94dff674a83ccc51db1a01ffeb6e5d45b58ea9d (patch) | |
tree | e1fdf2dca3d2654c695f000ec56cebc29dabbbf4 /usr.sbin/mopd/common | |
parent | 36f1b197c477854a9d173adfd44fd5b0e57f6f54 (diff) |
Initial import of mopd-2.5.3. -moj
Diffstat (limited to 'usr.sbin/mopd/common')
27 files changed, 4670 insertions, 0 deletions
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_ |