From 591fd60492abf36e4c07d349b836ff40228df09e Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Fri, 28 Apr 2017 19:47:09 +0200 Subject: mopd: add new package for alpha netboot --- package/mopd/src/Makefile | 34 ++ package/mopd/src/README | 20 + package/mopd/src/common/Makefile | 14 + package/mopd/src/common/VERSION | 1 + package/mopd/src/common/cmp.c | 45 ++ package/mopd/src/common/cmp.h | 42 ++ package/mopd/src/common/common.h | 100 +++++ package/mopd/src/common/device.c | 350 +++++++++++++++ package/mopd/src/common/device.h | 53 +++ package/mopd/src/common/dl.c | 322 +++++++++++++ package/mopd/src/common/dl.h | 42 ++ package/mopd/src/common/file.c | 820 ++++++++++++++++++++++++++++++++++ package/mopd/src/common/file.h | 56 +++ package/mopd/src/common/get.c | 152 +++++++ package/mopd/src/common/get.h | 49 ++ package/mopd/src/common/loop-bsd.c | 183 ++++++++ package/mopd/src/common/loop-linux2.c | 162 +++++++ package/mopd/src/common/mopdef.c | 54 +++ package/mopd/src/common/mopdef.h | 198 ++++++++ package/mopd/src/common/nma.c | 227 ++++++++++ package/mopd/src/common/nma.h | 43 ++ package/mopd/src/common/nmadef.h | 183 ++++++++ package/mopd/src/common/os.h | 53 +++ package/mopd/src/common/pf-linux2.c | 321 +++++++++++++ package/mopd/src/common/pf.c | 264 +++++++++++ package/mopd/src/common/pf.h | 48 ++ package/mopd/src/common/print.c | 707 +++++++++++++++++++++++++++++ package/mopd/src/common/print.h | 51 +++ package/mopd/src/common/put.c | 185 ++++++++ package/mopd/src/common/put.h | 48 ++ package/mopd/src/common/rc.c | 322 +++++++++++++ package/mopd/src/common/rc.h | 42 ++ package/mopd/src/mopa.out/Makefile | 5 + package/mopd/src/mopa.out/mopa.out.1 | 58 +++ package/mopd/src/mopa.out/mopa.out.c | 147 ++++++ package/mopd/src/mopchk/Makefile | 23 + package/mopd/src/mopchk/mopchk.1 | 64 +++ package/mopd/src/mopchk/mopchk.c | 167 +++++++ package/mopd/src/mopd/Makefile | 24 + package/mopd/src/mopd/TODO | 1 + package/mopd/src/mopd/mopd.8 | 109 +++++ package/mopd/src/mopd/mopd.c | 216 +++++++++ package/mopd/src/mopd/process.c | 684 ++++++++++++++++++++++++++++ package/mopd/src/mopd/process.h | 45 ++ package/mopd/src/mopprobe/Makefile | 23 + package/mopd/src/mopprobe/mopprobe.1 | 68 +++ package/mopd/src/mopprobe/mopprobe.c | 283 ++++++++++++ package/mopd/src/moptrace/Makefile | 23 + package/mopd/src/moptrace/moptrace.1 | 83 ++++ package/mopd/src/moptrace/moptrace.c | 157 +++++++ 50 files changed, 7371 insertions(+) create mode 100644 package/mopd/src/Makefile create mode 100644 package/mopd/src/README create mode 100644 package/mopd/src/common/Makefile create mode 100644 package/mopd/src/common/VERSION create mode 100644 package/mopd/src/common/cmp.c create mode 100644 package/mopd/src/common/cmp.h create mode 100644 package/mopd/src/common/common.h create mode 100644 package/mopd/src/common/device.c create mode 100644 package/mopd/src/common/device.h create mode 100644 package/mopd/src/common/dl.c create mode 100644 package/mopd/src/common/dl.h create mode 100644 package/mopd/src/common/file.c create mode 100644 package/mopd/src/common/file.h create mode 100644 package/mopd/src/common/get.c create mode 100644 package/mopd/src/common/get.h create mode 100644 package/mopd/src/common/loop-bsd.c create mode 100644 package/mopd/src/common/loop-linux2.c create mode 100644 package/mopd/src/common/mopdef.c create mode 100644 package/mopd/src/common/mopdef.h create mode 100644 package/mopd/src/common/nma.c create mode 100644 package/mopd/src/common/nma.h create mode 100644 package/mopd/src/common/nmadef.h create mode 100644 package/mopd/src/common/os.h create mode 100644 package/mopd/src/common/pf-linux2.c create mode 100644 package/mopd/src/common/pf.c create mode 100644 package/mopd/src/common/pf.h create mode 100644 package/mopd/src/common/print.c create mode 100644 package/mopd/src/common/print.h create mode 100644 package/mopd/src/common/put.c create mode 100644 package/mopd/src/common/put.h create mode 100644 package/mopd/src/common/rc.c create mode 100644 package/mopd/src/common/rc.h create mode 100644 package/mopd/src/mopa.out/Makefile create mode 100644 package/mopd/src/mopa.out/mopa.out.1 create mode 100644 package/mopd/src/mopa.out/mopa.out.c create mode 100644 package/mopd/src/mopchk/Makefile create mode 100644 package/mopd/src/mopchk/mopchk.1 create mode 100644 package/mopd/src/mopchk/mopchk.c create mode 100644 package/mopd/src/mopd/Makefile create mode 100644 package/mopd/src/mopd/TODO create mode 100644 package/mopd/src/mopd/mopd.8 create mode 100644 package/mopd/src/mopd/mopd.c create mode 100644 package/mopd/src/mopd/process.c create mode 100644 package/mopd/src/mopd/process.h create mode 100644 package/mopd/src/mopprobe/Makefile create mode 100644 package/mopd/src/mopprobe/mopprobe.1 create mode 100644 package/mopd/src/mopprobe/mopprobe.c create mode 100644 package/mopd/src/moptrace/Makefile create mode 100644 package/mopd/src/moptrace/moptrace.1 create mode 100644 package/mopd/src/moptrace/moptrace.c (limited to 'package/mopd/src') diff --git a/package/mopd/src/Makefile b/package/mopd/src/Makefile new file mode 100644 index 000000000..980579251 --- /dev/null +++ b/package/mopd/src/Makefile @@ -0,0 +1,34 @@ + +# uncomment this to send the correct hostname to the client +# otherwise 'DEFAULT_HOSTNAME' will be sent +# REAL_HOSTNAME = "-DSEND_REAL_HOSTNAME" +REAL_HOSTNAME ="" +DEFAULT_HOSTNAME="-DDEFAULT_HOSTNAME=\\\"ipc\\\"" + +# this is the path mopd will look for files in +MOP_PATH="-DMOP_FILE_PATH=\\\"/tftpboot/mop\\\"" + +# compiling on Alpha Linux 2.2.17 i needed the following: +# AOUT_SUPPORT="-DNOAOUT" +AOUT_SUPPORT="" + +CFLAGS="-g ${AOUT_SUPPORT} ${MOP_PATH} ${DEFAULT_HOSTNAME} ${REAL_HOSTNAME}" + +#make file to build linux-mopd +SUBDIRS=common mopd mopchk mopprobe moptrace + +all: + for dir in ${SUBDIRS}; \ + do \ + echo making $$dir; \ + (cd $$dir; make CFLAGS=$(CFLAGS) ) ; \ + done + + +clean: + for dir in ${SUBDIRS} ; \ + do \ + (cd $$dir ; make clean); \ + done + + diff --git a/package/mopd/src/README b/package/mopd/src/README new file mode 100644 index 000000000..e89184fd9 --- /dev/null +++ b/package/mopd/src/README @@ -0,0 +1,20 @@ +mopd-linux-20000808 + + This is the Linux version of Mats Jansens' Mopd. + + The sources here are taken from the NetBSD version of mopd 2.5.3/4 + in CVS, plus some bits from the OpenBSD port, and the security + fixes reported on BUGTRAQ on 08 Aug 2000. + + I had to rewrite the Makefiles, and hack things about a bit to compile + under Linux, So if this version doesnt work for you, send email to the + Linux/VAX list detailing the problem. + + The mopa.out program does not work. The a.out structures have different + names under NetBSD and Linux (see /usr/include/a.out.h), and so the + code needs re-writing. + + atp@pergamentum.com 8/Aug/2000 + + Patches from John Nall added for Alpha/Linux + diff --git a/package/mopd/src/common/Makefile b/package/mopd/src/common/Makefile new file mode 100644 index 000000000..3b8022378 --- /dev/null +++ b/package/mopd/src/common/Makefile @@ -0,0 +1,14 @@ +#simple make file for linux + + +OBJS=cmp.o dl.o get.o mopdef.o pf-linux2.o put.o device.o file.o loop-linux2.o nma.o print.o rc.o + +libcommon.a: ${OBJS} + ar -rs libcommon.a ${OBJS} + +.c.o: .o + $(CC) -c $(CFLAGS) $< + +clean: + rm -f *.o *.a *~ + diff --git a/package/mopd/src/common/VERSION b/package/mopd/src/common/VERSION new file mode 100644 index 000000000..aedc15bb0 --- /dev/null +++ b/package/mopd/src/common/VERSION @@ -0,0 +1 @@ +2.5.3 diff --git a/package/mopd/src/common/cmp.c b/package/mopd/src/common/cmp.c new file mode 100644 index 000000000..cefa542b9 --- /dev/null +++ b/package/mopd/src/common/cmp.c @@ -0,0 +1,45 @@ +/* $NetBSD: cmp.c,v 1.2 1997/03/25 03:07:02 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: cmp.c,v 1.2 1997/03/25 03:07:02 thorpej Exp $"; +#endif + +#include "os.h" +#include "cmp.h" + +int +mopCmpEAddr(addr1, addr2) + u_char *addr1, *addr2; +{ + return(memcmp((char *)addr1, (char *)addr2, 6)); +} diff --git a/package/mopd/src/common/cmp.h b/package/mopd/src/common/cmp.h new file mode 100644 index 000000000..555403350 --- /dev/null +++ b/package/mopd/src/common/cmp.h @@ -0,0 +1,42 @@ +/* $NetBSD: cmp.h,v 1.2 1997/03/25 03:07:04 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: cmp.h,v 1.2 1997/03/25 03:07:04 thorpej Exp $ + * + */ + +#ifndef _CMP_H_ +#define _CMP_H_ + +__BEGIN_DECLS +int mopCmpEAddr __P((u_char *, u_char *)); +__END_DECLS + +#endif _CMP_H_ diff --git a/package/mopd/src/common/common.h b/package/mopd/src/common/common.h new file mode 100644 index 000000000..ed37f95b9 --- /dev/null +++ b/package/mopd/src/common/common.h @@ -0,0 +1,100 @@ +/* $NetBSD: common.h,v 1.3 1997/10/16 23:24:26 lukem Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: common.h,v 1.3 1997/10/16 23:24:26 lukem Exp $ + * + */ + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#define MAXDL 16 /* maximum number concurrent load */ +#define IFNAME_SIZE 32 /* maximum size if interface name */ +#define BUFSIZE 1600 /* main receive buffer size */ +#define HDRSIZ 22 /* room for 803.2 header */ + +#ifndef DEFAULT_HOSTNAME +#define DEFAULT_HOSTNAME "ipc" +#endif + +#ifndef MOP_FILE_PATH +#define MOP_FILE_PATH "/tftpboot/mop" +#endif + +#define DEBUG_ONELINE 1 +#define DEBUG_HEADER 2 +#define DEBUG_INFO 3 + +/* + * structure per interface + * + */ + +struct if_info { + int fd; /* File Descriptor */ + int trans; /* Transport type Ethernet/802.3 */ + u_char eaddr[6]; /* Ethernet addr of this interface */ + char if_name[IFNAME_SIZE]; /* Interface Name */ + int (*iopen) __P((char *, int, u_short, int)); + /* Interface Open Routine */ + int (*write) __P((int, u_char *, int, int)); + /* Interface Write Routine */ + void (*read) __P((void)); /* Interface Read Routine */ + struct if_info *next; /* Next Interface */ +}; + +#define DL_STATUS_FREE 0 +#define DL_STATUS_READ_IMGHDR 1 +#define DL_STATUS_SENT_MLD 2 +#define DL_STATUS_SENT_PLT 3 + +struct dllist { + u_char status; /* Status byte */ + struct if_info *ii; /* interface pointer */ + u_char eaddr[6]; /* targets ethernet addres */ + int ldfd; /* filedescriptor for loadfile */ + u_short dl_bsz; /* Data Link Buffer Size */ + int timeout; /* Timeout counter */ + u_char count; /* Packet Counter */ + u_int32_t loadaddr; /* Load Address */ + u_int32_t xferaddr; /* Transfer Address */ + u_int32_t nloadaddr; /* Next Load Address */ + off_t lseek; /* Seek before last read */ + int aout; /* Is it an a.out file */ + u_int32_t a_text; /* Size of text segment */ + u_int32_t a_text_fill; /* Size of text segment fill */ + u_int32_t a_data; /* Size of data segment */ + u_int32_t a_data_fill; /* Size of data segment fill */ + u_int32_t a_bss; /* Size of bss segment */ + u_int32_t a_bss_fill; /* Size of bss segment fill */ + off_t a_lseek; /* Keep track of pos in newfile */ +}; + +#endif /* _COMMON_H_ */ diff --git a/package/mopd/src/common/device.c b/package/mopd/src/common/device.c new file mode 100644 index 000000000..536c474cb --- /dev/null +++ b/package/mopd/src/common/device.c @@ -0,0 +1,350 @@ +/* $NetBSD: device.c,v 1.2 1997/03/25 03:07:06 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: device.c,v 1.2 1997/03/25 03:07:06 thorpej Exp $"; +#endif + +#include "os.h" +#include "common.h" +#include "device.h" +#include "mopdef.h" +#include "pf.h" + +struct if_info *iflist; /* Interface List */ + +void deviceOpen __P((char *, u_short, int)); + +/* + * Return ethernet adress for interface + */ + +void +deviceEthAddr(ifname, eaddr) + char *ifname; + u_char *eaddr; +{ + char inbuf[8192]; + struct ifconf ifc; + struct ifreq *ifr; + struct sockaddr_dl *sdl; + int fd; + int i, len; + +#ifdef DEV_NEW_CONF + /* We cannot use SIOCGIFADDR on the BPF descriptor. + We must instead get all the interfaces with SIOCGIFCONF + and find the right one. */ + + /* Use datagram socket to get Ethernet address. */ + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "deviceEthAddr: socket: %m"); + exit(1); + } + + ifc.ifc_len = sizeof(inbuf); + ifc.ifc_buf = inbuf; + if (ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc) < 0 || + ifc.ifc_len < sizeof(struct ifreq)) { + syslog(LOG_ERR, "deviceEthAddr: SIOGIFCONF: %m"); + (void) close(fd); + exit(1); + } + ifr = ifc.ifc_req; + for (i = 0; i < ifc.ifc_len; + i += len, ifr = (struct ifreq *)((caddr_t)ifr + len)) { + len = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len; + sdl = (struct sockaddr_dl *)&ifr->ifr_addr; + if (sdl->sdl_family != AF_LINK || sdl->sdl_type != IFT_ETHER || + sdl->sdl_alen != 6) + continue; + if (!strncmp(ifr->ifr_name, ifname, sizeof(ifr->ifr_name))) { + memmove((caddr_t)eaddr, (caddr_t)LLADDR(sdl), 6); + (void) close(fd); + return; + } + } + + syslog(LOG_ERR, "deviceEthAddr: Never saw interface `%s'!", ifname); + (void) close(fd); + exit(1); + +#else + int j = 0; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "deviceEthAddr: old socket: %m"); + exit(1); + } + ifc.ifc_len = sizeof inbuf; + ifc.ifc_buf = (caddr_t)inbuf; + if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 || + ifc.ifc_len < sizeof(struct ifreq)) { + syslog(LOG_ERR, "deviceEthAddr: old SIOCGIFCONF: %m"); + (void) close(fd); + exit(1); + } + + ifr = ifc.ifc_req; + for(i=0;i<(ifc.ifc_len / sizeof(struct ifreq));i++,ifr++){ + if (ioctl(fd, SIOCGIFHWADDR, (char *)ifr) < 0) { + syslog(LOG_ERR,"deviceEthAddr: SIOGIFHWADDR failed. ERRNO: %d\n",errno); + continue; + } + if(memmove((caddr_t)eaddr, (caddr_t)ifr->ifr_hwaddr.sa_data, 6) == NULL){ + syslog(LOG_ERR, "deviceEthAddr: memmove returned NULL: %m"); + (void) close(fd); + exit(1); + } + } + + (void) close(fd); + return; +#endif /* DEV_NEW_CONF */ +} + +void +deviceOpen(ifname, proto, trans) + char *ifname; + u_short proto; + int trans; +{ + struct if_info *p, tmp; + + strcpy(tmp.if_name,ifname); + tmp.iopen = pfInit; + + switch (proto) { + case MOP_K_PROTO_RC: + tmp.read = mopReadRC; + tmp.fd = mopOpenRC(&tmp, trans); + break; + case MOP_K_PROTO_DL: + tmp.read = mopReadDL; + tmp.fd = mopOpenDL(&tmp, trans); + break; + default: + break; + } + + if (tmp.fd != -1) { + + p = (struct if_info *)malloc(sizeof(*p)); + if (p == 0) { + syslog(LOG_ERR, "deviceOpen: malloc: %m"); + exit(1); + } + + p->next = iflist; + iflist = p; + + strcpy(p->if_name,tmp.if_name); + p->iopen = tmp.iopen; + p->write = pfWrite; + p->read = tmp.read; + memset((char *)p->eaddr, 0, sizeof(p->eaddr)); + p->fd = tmp.fd; + + deviceEthAddr(p->if_name,&p->eaddr[0]); + } +} + +void +deviceInitOne(ifname) + char *ifname; +{ + char interface[IFNAME_SIZE]; + struct if_info *p; + int trans; +#ifdef _AIX + char dev[IFNAME_SIZE]; + int unit,j; + + unit = 0; + for (j = 0; j < strlen(ifname); j++) { + if (isalpha(ifname[j])) { + dev[j] = ifname[j]; + } else { + if (isdigit(ifname[j])) { + unit = unit*10 + ifname[j] - '0'; + dev[j] = '\0'; + } + } + } + + if ((strlen(dev) == 2) && + (dev[0] == 'e') && + ((dev[1] == 'n') || (dev[1] == 't'))) { + sprintf(interface,"ent%d\0",unit); + } else { + sprintf(interface,"%s%d\0",dev,unit); + } +#else + sprintf(interface,"%s",ifname); +#endif /* _AIX */ + + /* Ok, init it just once */ + + p = iflist; + for (p = iflist; p; p = p->next) { + if (strcmp(p->if_name,interface) == 0) { + return; + } + } + + syslog(LOG_INFO, "Initialized %s", interface); + + /* Ok, get transport information */ + + trans = pfTrans(interface); + +#ifndef NORC + /* Start with MOP Remote Console */ + + switch (trans) { + case TRANS_ETHER: + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_ETHER); + break; + case TRANS_8023: + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_8023); + break; + case TRANS_ETHER+TRANS_8023: + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_ETHER); + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_8023); + break; + case TRANS_ETHER+TRANS_8023+TRANS_AND: + deviceOpen(interface,MOP_K_PROTO_RC,TRANS_ETHER+TRANS_8023); + break; + } +#endif + +#ifndef NODL + /* and next MOP Dump/Load */ + + switch (trans) { + case TRANS_ETHER: + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_ETHER); + break; + case TRANS_8023: + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_8023); + break; + case TRANS_ETHER+TRANS_8023: + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_ETHER); + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_8023); + break; + case TRANS_ETHER+TRANS_8023+TRANS_AND: + deviceOpen(interface,MOP_K_PROTO_DL,TRANS_ETHER+TRANS_8023); + break; + } +#endif + +} + +/* + * Initialize all "candidate" interfaces that are in the system + * configuration list. A "candidate" is up, not loopback and not + * point to point. + */ +void +deviceInitAll() +{ +#ifdef DEV_NEW_CONF + char inbuf[8192]; + struct ifconf ifc; + struct ifreq *ifr; + struct sockaddr_dl *sdl; + int fd; + int i, len; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "deviceInitAll: socket: %m"); + exit(1); + } + + ifc.ifc_len = sizeof(inbuf); + ifc.ifc_buf = inbuf; + if (ioctl(fd, SIOCGIFCONF, (caddr_t)&ifc) < 0 || + ifc.ifc_len < sizeof(struct ifreq)) { + syslog(LOG_ERR, "deviceInitAll: SIOCGIFCONF: %m"); + exit(1); + } + ifr = ifc.ifc_req; + for (i = 0; i < ifc.ifc_len; + i += len, ifr = (struct ifreq *)((caddr_t)ifr + len)) { + len = sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len; + sdl = (struct sockaddr_dl *)&ifr->ifr_addr; + if (sdl->sdl_family != AF_LINK || sdl->sdl_type != IFT_ETHER || + sdl->sdl_alen != 6) + continue; + if (ioctl(fd, SIOCGIFFLAGS, (caddr_t)ifr) < 0) { + syslog(LOG_ERR, "deviceInitAll: SIOCGIFFLAGS: %m"); + continue; + } + if ((ifr->ifr_flags & + (IFF_UP | IFF_LOOPBACK | IFF_POINTOPOINT)) != IFF_UP) + continue; + deviceInitOne(ifr->ifr_name); + } + (void) close(fd); +#else + int fd; + int n; + struct ifreq ibuf[8], *ifrp; + struct ifconf ifc; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + syslog(LOG_ERR, "deviceInitAll: old socket: %m"); + exit(1); + } + ifc.ifc_len = sizeof ibuf; + ifc.ifc_buf = (caddr_t)ibuf; + if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0 || + ifc.ifc_len < sizeof(struct ifreq)) { + syslog(LOG_ERR, "deviceInitAll: old SIOCGIFCONF: %m"); + exit(1); + } + ifrp = ibuf; + n = ifc.ifc_len / sizeof(*ifrp); + for (; --n >= 0; ++ifrp) { + if (ioctl(fd, SIOCGIFFLAGS, (char *)ifrp) < 0) { + continue; + } + if (/*(ifrp->ifr_flags & IFF_UP) == 0 ||*/ + ifrp->ifr_flags & IFF_LOOPBACK || + ifrp->ifr_flags & IFF_POINTOPOINT) + continue; + deviceInitOne(ifrp->ifr_name); + } + + (void) close(fd); +#endif /* DEV_NEW_CONF */ +} diff --git a/package/mopd/src/common/device.h b/package/mopd/src/common/device.h new file mode 100644 index 000000000..59c6990b9 --- /dev/null +++ b/package/mopd/src/common/device.h @@ -0,0 +1,53 @@ +/* $NetBSD: device.h,v 1.2 1997/03/25 03:07:07 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: device.h,v 1.2 1997/03/25 03:07:07 thorpej Exp $ + * + */ + +#ifndef _DEVICE_H_ +#define _DEVICE_H_ + +__BEGIN_DECLS +#ifdef DEV_NEW_CONF +void deviceEthAddr __P((char *, u_char *)); +#endif +void deviceInitOne __P((char *)); +void deviceInitAll __P((void)); + +/* from loop-bsd.c */ +void Loop __P((void)); +int mopOpenDL __P((struct if_info *, int)); +int mopOpenRC __P((struct if_info *, int)); +void mopReadDL __P((void)); +void mopReadRC __P((void)); +__END_DECLS + +#endif _DEVICE_H_ diff --git a/package/mopd/src/common/dl.c b/package/mopd/src/common/dl.c new file mode 100644 index 000000000..58774dc14 --- /dev/null +++ b/package/mopd/src/common/dl.c @@ -0,0 +1,322 @@ +/* $NetBSD: dl.c,v 1.3 1997/10/16 23:24:31 lukem Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: dl.c,v 1.3 1997/10/16 23:24:31 lukem Exp $"; +#endif + +#include "os.h" +#include "dl.h" +#include "get.h" +#include "mopdef.h" +#include "print.h" + +void +mopDumpDL(fd, pkt, trans) + FILE *fd; + u_char *pkt; + int trans; +{ + int i,index = 0; + u_int32_t tmpl; + u_char tmpc,c,program[257],code,*ucp; + u_short len,tmps,moplen; + + len = mopGetLength(pkt, trans); + + switch (trans) { + case TRANS_8023: + index = 22; + moplen = len - 8; + break; + default: + index = 16; + moplen = len; + } + code = mopGetChar(pkt,&index); + + /* see above, if (len < 8) then moplen ends up around 65535 */ + if (moplen > len) moplen = len; + + switch (code) { + case MOP_K_CODE_MLT: + + tmpc = mopGetChar(pkt,&index); /* Load Number */ + (void)fprintf(fd,"Load Number : %02x\n",tmpc); + + if (moplen > 6) { + tmpl = mopGetLong(pkt,&index);/* Load Address */ + (void)fprintf(fd,"Load Address : %08x\n", tmpl); + } + + if (moplen > 10) { +#ifndef SHORT_PRINT + for (i = 0; i < (moplen - 10); i++) { + if ((i % 16) == 0) { + if ((i / 16) == 0) { + (void)fprintf(fd, + "Image Data : %04x ", + moplen-10); + } else { + (void)fprintf(fd, + " "); + } + } + + (void)fprintf(fd, "%02x ", + mopGetChar(pkt,&index)); + if ((i % 16) == 15) + (void)fprintf(fd,"\n"); + } + + if ((i % 16) != 15) + (void)fprintf(fd,"\n"); +#else + index = index + moplen - 10; +#endif + } + + tmpl = mopGetLong(pkt,&index); /* Load Address */ + (void)fprintf(fd,"Xfer Address : %08x\n", tmpl); + + break; + case MOP_K_CODE_DCM: + + /* Empty Message */ + + break; + case MOP_K_CODE_MLD: + + tmpc = mopGetChar(pkt,&index); /* Load Number */ + (void)fprintf(fd,"Load Number : %02x\n",tmpc); + + tmpl = mopGetLong(pkt,&index); /* Load Address */ + (void)fprintf(fd,"Load Address : %08x\n", tmpl); + + if (moplen > 6) { +#ifndef SHORT_PRINT + for (i = 0; i < (moplen - 6); i++) { + if ((i % 16) == 0) { + if ((i / 16) == 0) { + (void)fprintf(fd, + "Image Data : %04x ", + moplen-6); + } else { + (void)fprintf(fd, + " "); + } + } + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + if ((i % 16) == 15) + (void)fprintf(fd,"\n"); + } + + if ((i % 16) != 15) + (void)fprintf(fd,"\n"); +#else + index = index + moplen - 6; +#endif + } + + break; + case MOP_K_CODE_ASV: + + /* Empty Message */ + + break; + case MOP_K_CODE_RMD: + + tmpl = mopGetLong(pkt,&index); /* Memory Address */ + (void)fprintf(fd,"Mem Address : %08x\n", tmpl); + + tmps = mopGetShort(pkt,&index); /* Count */ + (void)fprintf(fd,"Count : %04x (%d)\n",tmps,tmps); + + break; + case MOP_K_CODE_RPR: + + tmpc = mopGetChar(pkt,&index); /* Device Type */ + (void)fprintf(fd, "Device Type : %02x ",tmpc); + mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n"); + + tmpc = mopGetChar(pkt,&index); /* Format Version */ + (void)fprintf(fd,"Format : %02x\n",tmpc); + + tmpc = mopGetChar(pkt,&index); /* Program Type */ + (void)fprintf(fd,"Program Type : %02x ",tmpc); + mopPrintPGTY(fd, tmpc); (void)fprintf(fd, "\n"); + + program[0] = 0; + tmpc = mopGetChar(pkt,&index); /* Software ID Len */ + for (i = 0; i < tmpc; i++) { + program[i] = mopGetChar(pkt,&index); + program[i+1] = '\0'; + } + + (void)fprintf(fd,"Software : %02x '%s'\n",tmpc,program); + + tmpc = mopGetChar(pkt,&index); /* Processor */ + (void)fprintf(fd,"Processor : %02x ",tmpc); + mopPrintBPTY(fd, tmpc); (void)fprintf(fd, "\n"); + + mopPrintInfo(fd, pkt, &index, moplen, code, trans); + + break; + case MOP_K_CODE_RML: + + tmpc = mopGetChar(pkt,&index); /* Load Number */ + (void)fprintf(fd,"Load Number : %02x\n",tmpc); + + tmpc = mopGetChar(pkt,&index); /* Error */ + (void)fprintf(fd,"Error : %02x (",tmpc); + if ((tmpc == 0)) { + (void)fprintf(fd,"no error)\n"); + } else { + (void)fprintf(fd,"error)\n"); + } + + break; + case MOP_K_CODE_RDS: + + tmpc = mopGetChar(pkt,&index); /* Device Type */ + (void)fprintf(fd, "Device Type : %02x ",tmpc); + mopPrintDevice(fd, tmpc); (void)fprintf(fd, "\n"); + + tmpc = mopGetChar(pkt,&index); /* Format Version */ + (void)fprintf(fd,"Format : %02x\n",tmpc); + + tmpl = mopGetLong(pkt,&index); /* Memory Size */ + (void)fprintf(fd,"Memory Size : %08x\n", tmpl); + + tmpc = mopGetChar(pkt,&index); /* Bits */ + (void)fprintf(fd,"Bits : %02x\n",tmpc); + + mopPrintInfo(fd, pkt, &index, moplen, code, trans); + + break; + case MOP_K_CODE_MDD: + + tmpl = mopGetLong(pkt,&index); /* Memory Address */ + (void)fprintf(fd,"Mem Address : %08x\n", tmpl); + + if (moplen > 5) { +#ifndef SHORT_PRINT + for (i = 0; i < (moplen - 5); i++) { + if ((i % 16) == 0) { + if ((i / 16) == 0) { + (void)fprintf(fd, + "Image Data : %04x ", + moplen-5); + } else { + (void)fprintf(fd, + " "); + } + } + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + if ((i % 16) == 15) + (void)fprintf(fd,"\n"); + } + if ((i % 16) != 15) + (void)fprintf(fd,"\n"); +#else + index = index + moplen - 5; +#endif + } + + break; + case MOP_K_CODE_PLT: + + tmpc = mopGetChar(pkt,&index); /* Load Number */ + (void)fprintf(fd,"Load Number : %02x\n",tmpc); + + tmpc = mopGetChar(pkt,&index); /* Parameter Type */ + while (tmpc != MOP_K_PLTP_END) { + c = mopGetChar(pkt,&index); /* Parameter Length */ + switch(tmpc) { + case MOP_K_PLTP_TSN: /* Target Name */ + (void)fprintf(fd,"Target Name : %02x '", + tmpc); + for (i = 0; i < ((int) c); i++) { + (void)fprintf(fd,"%c", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"'\n"); + break; + case MOP_K_PLTP_TSA: /* Target Address */ + (void)fprintf(fd,"Target Addr : %02x ",c); + for (i = 0; i < ((int) c); i++) { + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"\n"); + break; + case MOP_K_PLTP_HSN: /* Host Name */ + (void)fprintf(fd,"Host Name : %02x '", + tmpc); + for (i = 0; i < ((int) c); i++) { + (void)fprintf(fd,"%c", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"'\n"); + break; + case MOP_K_PLTP_HSA: /* Host Address */ + (void)fprintf(fd,"Host Addr : %02x ",c); + for (i = 0; i < ((int) c); i++) { + (void)fprintf(fd,"%02x ", + mopGetChar(pkt,&index)); + } + (void)fprintf(fd,"\n"); + break; + case MOP_K_PLTP_HST: /* Host Time */ + ucp = pkt + index; index = index + 10; + (void)fprintf(fd,"Host Time : "); + mopPrintTime(fd, ucp); + (void)fprintf(fd,"\n"); + break; + default: + break; + } + tmpc = mopGetChar(pkt,&index);/* Parameter Type */ + } + + tmpl = mopGetLong(pkt,&index); /* Transfer Address */ + (void)fprintf(fd,"Transfer Addr: %08x\n", tmpl); + + break; + default: + break; + } +} + + diff --git a/package/mopd/src/common/dl.h b/package/mopd/src/common/dl.h new file mode 100644 index 000000000..16a9e0e56 --- /dev/null +++ b/package/mopd/src/common/dl.h @@ -0,0 +1,42 @@ +/* $NetBSD: dl.h,v 1.2 1997/03/25 03:07:10 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: dl.h,v 1.2 1997/03/25 03:07:10 thorpej Exp $ + * + */ + +#ifndef _DL_H_ +#define _DL_H_ + +__BEGIN_DECLS +void mopDumpDL __P((FILE *, u_char *, int)); +__END_DECLS + +#endif _DL_H_ diff --git a/package/mopd/src/common/file.c b/package/mopd/src/common/file.c new file mode 100644 index 000000000..8d2ffcd94 --- /dev/null +++ b/package/mopd/src/common/file.c @@ -0,0 +1,820 @@ +/* $NetBSD: file.c,v 1.5 1998/02/07 00:03:22 cgd Exp $ */ + +/* + * Copyright (c) 1995-96 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: file.c,v 1.5 1998/02/07 00:03:22 cgd Exp $"; +#endif + +#include "os.h" +#include "common.h" +#include "file.h" +#include "mopdef.h" + +#ifndef NOAOUT +#if defined(__NetBSD__) || defined(__OpenBSD__) +#include +#endif +#if defined(__bsdi__) +#define NOAOUT +#endif +#if defined(__FreeBSD__) +#include +#endif +#if !defined(MID_VAX) +#define MID_VAX 140 +#endif +#if defined(__linux__) +#define NOAOUT +#include +#define MID_I386 100 +#define MID_SPARC 3 +#endif +#endif + +int getCLBYTES __P((int)); +int getMID __P((int, int)); + +void +mopFilePutLX(buf, index, value, cnt) + u_char *buf; + int index, cnt; + u_int32_t value; +{ + int i; + for (i = 0; i < cnt; i++) { + buf[index+i] = value % 256; + value = value / 256; + } +} + +void +mopFilePutBX(buf, index, value, cnt) + u_char *buf; + int index, cnt; + u_int32_t value; +{ + int i; + for (i = 0; i < cnt; i++) { + buf[index+cnt-1-i] = value % 256; + value = value / 256; + } +} + +u_int32_t +mopFileGetLX(buf, index, cnt) + u_char *buf; + int index, cnt; +{ + u_int32_t ret = 0; + int i; + + for (i = 0; i < cnt; i++) { + ret = ret*256 + buf[index+cnt-1-i]; + } + + return(ret); +} + +u_int32_t +mopFileGetBX(buf, index, cnt) + u_char *buf; + int index, cnt; +{ + u_int32_t ret = 0; + int i; + + for (i = 0; i < cnt; i++) { + ret = ret*256 + buf[index+i]; + } + + return(ret); +} + +void +mopFileSwapX(buf, index, cnt) + u_char *buf; + int index, cnt; +{ + int i; + u_char c; + + for (i = 0; i < (cnt / 2); i++) { + c = buf[index+i]; + buf[index+i] = buf[index+cnt-1-i]; + buf[index+cnt-1-i] = c; + } + +} + +int +CheckMopFile(fd) + int fd; +{ + u_char header[512]; + short image_type; + + if (read(fd, header, 512) != 512) + return(-1); + + (void)lseek(fd, (off_t) 0, SEEK_SET); + + image_type = (u_short)(header[IHD_W_ALIAS+1]*256 + + header[IHD_W_ALIAS]); + + switch(image_type) { + case IHD_C_NATIVE: /* Native mode image (VAX) */ + case IHD_C_RSX: /* RSX image produced by TKB */ + case IHD_C_BPA: /* BASIC plus analog */ + case IHD_C_ALIAS: /* Alias */ + case IHD_C_CLI: /* Image is CLI */ + case IHD_C_PMAX: /* PMAX system image */ + case IHD_C_ALPHA: /* ALPHA system image */ + break; + default: + return(-1); + } + + return(0); +} + +int +GetMopFileInfo(fd, load, xfr) + int fd; + u_int32_t *load, *xfr; +{ + u_char header[512]; + short image_type; + u_int32_t load_addr, xfr_addr, isd, iha, hbcnt, isize; + + if (read(fd, header, 512) != 512) + return(-1); + + image_type = (u_short)(header[IHD_W_ALIAS+1]*256 + + header[IHD_W_ALIAS]); + + switch(image_type) { + case IHD_C_NATIVE: /* Native mode image (VAX) */ + isd = (header[IHD_W_SIZE+1]*256 + + header[IHD_W_SIZE]); + iha = (header[IHD_W_ACTIVOFF+1]*256 + + header[IHD_W_ACTIVOFF]); + hbcnt = (header[IHD_B_HDRBLKCNT]); + isize = (header[isd+ISD_W_PAGCNT+1]*256 + + header[isd+ISD_W_PAGCNT]) * 512; + load_addr = ((header[isd+ISD_V_VPN+1]*256 + + header[isd+ISD_V_VPN]) & ISD_M_VPN) + * 512; + xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 + + header[iha+IHA_L_TFRADR1+2]*0x10000 + + header[iha+IHA_L_TFRADR1+1]*0x100 + + header[iha+IHA_L_TFRADR1]) & 0x7fffffff; + printf("Native Image (VAX)\n"); + printf("Header Block Count: %d\n",hbcnt); + printf("Image Size: %08x\n",isize); + printf("Load Address: %08x\n",load_addr); + printf("Transfer Address: %08x\n",xfr_addr); + break; + case IHD_C_RSX: /* RSX image produced by TKB */ + hbcnt = header[L_BBLK+1]*256 + header[L_BBLK]; + isize = (header[L_BLDZ+1]*256 + header[L_BLDZ]) * 64; + load_addr = header[L_BSA+1]*256 + header[L_BSA]; + xfr_addr = header[L_BXFR+1]*256 + header[L_BXFR]; + printf("RSX Image\n"); + printf("Header Block Count: %d\n",hbcnt); + printf("Image Size: %08x\n",isize); + printf("Load Address: %08x\n",load_addr); + printf("Transfer Address: %08x\n",xfr_addr); + break; + case IHD_C_BPA: /* BASIC plus analog */ + printf("BASIC-Plus Image, not supported\n"); + return(-1); + break; + case IHD_C_ALIAS: /* Alias */ + printf("Alias, not supported\n"); + return(-1); + break; + case IHD_C_CLI: /* Image is CLI */ + printf("CLI, not supported\n"); + return(-1); + break; + case IHD_C_PMAX: /* PMAX system image */ + isd = (header[IHD_W_SIZE+1]*256 + + header[IHD_W_SIZE]); + iha = (header[IHD_W_ACTIVOFF+1]*256 + + header[IHD_W_ACTIVOFF]); + hbcnt = (header[IHD_B_HDRBLKCNT]); + isize = (header[isd+ISD_W_PAGCNT+1]*256 + + header[isd+ISD_W_PAGCNT]) * 512; + load_addr = (header[isd+ISD_V_VPN+1]*256 + + header[isd+ISD_V_VPN]) * 512; + xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 + + header[iha+IHA_L_TFRADR1+2]*0x10000 + + header[iha+IHA_L_TFRADR1+1]*0x100 + + header[iha+IHA_L_TFRADR1]); + printf("PMAX Image \n"); + printf("Header Block Count: %d\n",hbcnt); + printf("Image Size: %08x\n",isize); + printf("Load Address: %08x\n",load_addr); + printf("Transfer Address: %08x\n",xfr_addr); + break; + case IHD_C_ALPHA: /* ALPHA system image */ + isd = (header[EIHD_L_ISDOFF+3]*0x1000000 + + header[EIHD_L_ISDOFF+2]*0x10000 + + header[EIHD_L_ISDOFF+1]*0x100 + + header[EIHD_L_ISDOFF]); + hbcnt = (header[EIHD_L_HDRBLKCNT+3]*0x1000000 + + header[EIHD_L_HDRBLKCNT+2]*0x10000 + + header[EIHD_L_HDRBLKCNT+1]*0x100 + + header[EIHD_L_HDRBLKCNT]); + isize = (header[isd+EISD_L_SECSIZE+3]*0x1000000 + + header[isd+EISD_L_SECSIZE+2]*0x10000 + + header[isd+EISD_L_SECSIZE+1]*0x100 + + header[isd+EISD_L_SECSIZE]); + load_addr = 0; + xfr_addr = 0; + printf("Alpha Image \n"); + printf("Header Block Count: %d\n",hbcnt); + printf("Image Size: %08x\n",isize); + printf("Load Address: %08x\n",load_addr); + printf("Transfer Address: %08x\n",xfr_addr); + break; + default: + printf("Unknown Image (%d)\n",image_type); + return(-1); + } + + if (load != NULL) { + *load = load_addr; + } + + if (xfr != NULL) { + *xfr = xfr_addr; + } + + return(0); +} + +#ifndef NOAOUT +int +getMID(old_mid,new_mid) + int old_mid, new_mid; +{ + int mid; + + mid = old_mid; + + switch (new_mid) { + case MID_I386: + mid = MID_I386; + break; +#ifdef MID_M68K + case MID_M68K: + mid = MID_M68K; + break; +#endif +#ifdef MID_M68K4K + case MID_M68K4K: + mid = MID_M68K4K; + break; +#endif +#ifdef MID_NS32532 + case MID_NS32532: + mid = MID_NS32532; + break; +#endif + case MID_SPARC: + mid = MID_SPARC; + break; +#ifdef MID_PMAX + case MID_PMAX: + mid = MID_PMAX; + break; +#endif +#ifdef MID_VAX + case MID_VAX: + mid = MID_VAX; + break; +#endif +#ifdef MID_ALPHA + case MID_ALPHA: + mid = MID_ALPHA; + break; +#endif +#ifdef MID_MIPS + case MID_MIPS: + mid = MID_MIPS; + break; +#endif +#ifdef MID_ARM6 + case MID_ARM6: + mid = MID_ARM6; + break; +#endif + default: + break; + } + + return(mid); +} + +int +getCLBYTES(mid) + int mid; +{ + int clbytes; + + switch (mid) { +#ifdef MID_VAX + case MID_VAX: + clbytes = 1024; + break; +#endif +#ifdef MID_I386 + case MID_I386: +#endif +#ifdef MID_M68K4K + case MID_M68K4K: +#endif +#ifdef MID_NS32532 + case MID_NS32532: +#endif +#ifdef MID_PMAX + case MID_PMAX: +#endif +#ifdef MID_MIPS + case MID_MIPS: +#endif +#ifdef MID_ARM6 + case MID_ARM6: +#endif +#if defined(MID_I386) || defined(MID_M68K4K) || defined(MID_NS32532) || \ + defined(MID_PMAX) || defined(MID_MIPS) || defined(MID_ARM6) + clbytes = 4096; + break; +#endif +#ifdef MID_M68K + case MID_M68K: +#endif +#ifdef MID_ALPHA + case MID_ALPHA: +#endif +#ifdef MID_SPARC + case MID_SPARC: +#endif +#if defined(MID_M68K) || defined(MID_ALPHA) || defined(MID_SPARC) + clbytes = 8192; + break; +#endif + default: + clbytes = 0; + } + + return(clbytes); +} +#endif + +int +CheckAOutFile(fd) + int fd; +{ +#ifdef NOAOUT + return(-1); +#else + struct exec ex, ex_swap; + int mid = -1; + + if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex)) + return(-1); + + (void)lseek(fd, (off_t) 0, SEEK_SET); + + if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap)) + return(-1); + + (void)lseek(fd, (off_t) 0, SEEK_SET); + + mid = getMID(mid, N_GETMID (ex)); + + if (mid == -1) { + mid = getMID(mid, N_GETMID (ex_swap)); + } + + if (mid != -1) { + return(0); + } else { + return(-1); + } +#endif NOAOUT +} + +int +GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill, + a_data, a_data_fill, a_bss, a_bss_fill, aout) + int fd; + u_int32_t *load, *xfr, *a_text, *a_text_fill; + u_int32_t *a_data, *a_data_fill, *a_bss, *a_bss_fill; + int *aout; +{ +#ifdef NOAOUT + return(-1); +#else + struct exec ex, ex_swap; + u_int32_t mid = -1; + u_int32_t magic, clbytes, clofset; + + if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex)) + return(-1); + + (void)lseek(fd, (off_t) 0, SEEK_SET); + + if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap)) + return(-1); + + mopFileSwapX((u_char *)&ex_swap, 0, 4); + + mid = getMID(mid, N_GETMID (ex)); + + if (mid == -1) { + mid = getMID(mid, N_GETMID (ex_swap)); + if (mid != -1) { + mopFileSwapX((u_char *)&ex, 0, 4); + } + } + + if (mid == -1) { + return(-1); + } + + if (N_BADMAG (ex)) { + return(-1); + } + + switch (mid) { + case MID_I386: +#ifdef MID_NS32532 + case MID_NS32532: +#endif +#ifdef MID_PMAX + case MID_PMAX: +#endif +#ifdef MID_VAX + case MID_VAX: +#endif +#ifdef MID_ALPHA + case MID_ALPHA: +#endif +#ifdef MID_ARM6 + case MID_ARM6: +#endif + ex.a_text = mopFileGetLX((u_char *)&ex_swap, 4, 4); + ex.a_data = mopFileGetLX((u_char *)&ex_swap, 8, 4); + ex.a_bss = mopFileGetLX((u_char *)&ex_swap, 12, 4); + ex.a_syms = mopFileGetLX((u_char *)&ex_swap, 16, 4); + ex.a_entry = mopFileGetLX((u_char *)&ex_swap, 20, 4); + ex.a_trsize= mopFileGetLX((u_char *)&ex_swap, 24, 4); + ex.a_drsize= mopFileGetLX((u_char *)&ex_swap, 28, 4); + break; +#ifdef MID_M68K + case MID_M68K: +#endif +#ifdef MID_M68K4K + case MID_M68K4K: +#endif + case MID_SPARC: +#ifdef MID_MIPS + case MID_MIPS: +#endif + ex.a_text = mopFileGetBX((u_char *)&ex_swap, 4, 4); + ex.a_data = mopFileGetBX((u_char *)&ex_swap, 8, 4); + ex.a_bss = mopFileGetBX((u_char *)&ex_swap, 12, 4); + ex.a_syms = mopFileGetBX((u_char *)&ex_swap, 16, 4); + ex.a_entry = mopFileGetBX((u_char *)&ex_swap, 20, 4); + ex.a_trsize= mopFileGetBX((u_char *)&ex_swap, 24, 4); + ex.a_drsize= mopFileGetBX((u_char *)&ex_swap, 28, 4); + break; + default: + break; + } + + printf("a.out image ("); + switch (N_GETMID (ex)) { + case MID_I386: + printf("i386"); + break; +#ifdef MID_M68K + case MID_M68K: + printf("m68k"); + break; +#endif +#ifdef MID_M68K4K + case MID_M68K4K: + printf("m68k 4k"); + break; +#endif +#ifdef MID_NS32532 + case MID_NS32532: + printf("pc532"); + break; +#endif + case MID_SPARC: + printf("sparc"); + break; +#ifdef MID_PMAX + case MID_PMAX: + printf("pmax"); + break; +#endif +#ifdef MID_VAX + case MID_VAX: + printf("vax"); + break; +#endif +#ifdef MID_ALPHA + case MID_ALPHA: + printf("alpha"); + break; +#endif +#ifdef MID_MIPS + case MID_MIPS: + printf("mips"); + break; +#endif +#ifdef MID_ARM6 + case MID_ARM6: + printf("arm32"); + break; +#endif + default: + break; + } + printf(") Magic: "); + switch (N_GETMAGIC (ex)) { + case OMAGIC: + printf("OMAGIC"); + break; + case NMAGIC: + printf("NMAGIC"); + break; + case ZMAGIC: + printf("ZMAGIC"); + break; + case QMAGIC: + printf("QMAGIC"); + break; + default: + printf("Unknown %ld", (long) N_GETMAGIC (ex)); + } + printf("\n"); + printf("Size of text: %08lx\n", (long)ex.a_text); + printf("Size of data: %08lx\n", (long)ex.a_data); + printf("Size of bss: %08lx\n", (long)ex.a_bss); + printf("Size of symbol tab: %08lx\n", (long)ex.a_syms); + printf("Transfer Address: %08lx\n", (long)ex.a_entry); + printf("Size of reloc text: %08lx\n", (long)ex.a_trsize); + printf("Size of reloc data: %08lx\n", (long)ex.a_drsize); + + magic = N_GETMAGIC (ex); + clbytes = getCLBYTES(mid); + clofset = clbytes - 1; + + if (load != NULL) { + *load = 0; + } + + if (xfr != NULL) { + *xfr = ex.a_entry; + } + + if (a_text != NULL) { + *a_text = ex.a_text; + } + + if (a_text_fill != NULL) { + if (magic == ZMAGIC || magic == NMAGIC) { + *a_text_fill = clbytes - (ex.a_text & clofset); + if (*a_text_fill == clbytes) { + *a_text_fill = 0; + } + } else { + *a_text_fill = 0; + } + } + + if (a_data != NULL) { + *a_data = ex.a_data; + } + + if (a_data_fill != NULL) { + if (magic == ZMAGIC || magic == NMAGIC) { + *a_data_fill = clbytes - (ex.a_data & clofset); + if (*a_data_fill == clbytes) { + *a_data_fill = 0; + } + } else { + *a_data_fill = 0; + } + } + + if (a_bss != NULL) { + *a_bss = ex.a_bss; + } + + if (a_bss_fill != NULL) { + if (magic == ZMAGIC || magic == NMAGIC) { + *a_bss_fill = clbytes - (ex.a_bss & clofset); + if (*a_bss_fill == clbytes) { + *a_bss_fill = 0; + } + } else { + *a_bss_fill = clbytes - + ((ex.a_text+ex.a_data+ex.a_bss) & clofset); + if (*a_text_fill == clbytes) { + *a_text_fill = 0; + } + } + } + + if (aout != NULL) { + *aout = mid; + } + + return(0); +#endif NOAOUT +} + +int +GetFileInfo(fd, load, xfr, aout, + a_text, a_text_fill, a_data, a_data_fill, a_bss, a_bss_fill) + int fd, *aout; + u_int32_t *load, *xfr, *a_text, *a_text_fill; + u_int32_t *a_data, *a_data_fill, *a_bss, *a_bss_fill; +{ + int err; + + err = CheckAOutFile(fd); + + if (err == 0) { + err = GetAOutFileInfo(fd, load, xfr, + a_text, a_text_fill, + a_data, a_data_fill, + a_bss, a_bss_fill, + aout); + if (err != 0) { + return(-1); + } + } else { + err = CheckMopFile(fd); + + if (err == 0) { + err = GetMopFileInfo(fd, load, xfr); + if (err != 0) { + return(-1); + } + *aout = -1; + } else { + return(-1); + } + } + + return(0); +} + +ssize_t +mopFileRead(dlslot, buf) + struct dllist *dlslot; + u_char *buf; +{ + ssize_t len, outlen; + int bsz; + int32_t pos, notdone, total; + + if (dlslot->aout == -1) { + len = read(dlslot->ldfd,buf,dlslot->dl_bsz); + } else { + bsz = dlslot->dl_bsz; + pos = dlslot->a_lseek; + len = 0; + + total = dlslot->a_text; + + if (pos < total) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = read(dlslot->ldfd,&buf[len],notdone); + } else { + outlen = read(dlslot->ldfd,&buf[len],bsz); + } + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_text_fill; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = notdone; + } else { + outlen = bsz; + } + memset(&buf[len], 0, outlen); + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_data; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = read(dlslot->ldfd,&buf[len],notdone); + } else { + outlen = read(dlslot->ldfd,&buf[len],bsz); + } + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_data_fill; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = notdone; + } else { + outlen = bsz; + } + memset(&buf[len], 0, outlen); + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_bss; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = notdone; + } else { + outlen = bsz; + } + memset(&buf[len], 0, outlen); + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + total = total + dlslot->a_bss_fill; + + if ((bsz > 0) && (pos < total)) { + notdone = total - pos; + if (notdone <= bsz) { + outlen = notdone; + } else { + outlen = bsz; + } + memset(&buf[len], 0, outlen); + len = len + outlen; + pos = pos + outlen; + bsz = bsz - outlen; + } + + dlslot->a_lseek = pos; + + } + + return(len); +} diff --git a/package/mopd/src/common/file.h b/package/mopd/src/common/file.h new file mode 100644 index 000000000..1f012f3a2 --- /dev/null +++ b/package/mopd/src/common/file.h @@ -0,0 +1,56 @@ +/* $NetBSD: file.h,v 1.2 1997/03/25 03:07:13 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $NetBSD: file.h,v 1.2 1997/03/25 03:07:13 thorpej Exp $ + * + */ + +#ifndef _FILE_H_ +#define _FILE_H_ + +__BEGIN_DECLS +void mopFilePutLX __P((u_char *, int, u_int32_t, int)); +void mopFilePutBX __P((u_char *, int, u_int32_t, int)); +u_int32_t mopFileGetLX __P((u_char *, int, int)); +u_int32_t mopFileGetBX __P((u_char *, int, int)); +ssize_t mopFileRead __P((struct dllist *, u_char *)); +void mopFileSwapX __P((u_char *, int, int)); +int CheckMopFile __P((int)); +int GetMopFileInfo __P((int, u_int32_t *, u_int32_t *)); +int CheckAOutFile __P((int)); +int GetAOutFileInfo __P((int, u_int32_t *, u_int32_t *, + u_int32_t *, u_int32_t *, u_int32_t *, u_int32_t *, + u_int32_t *, u_int32_t *, int *)); +int GetFileInfo __P((int, u_int32_t *, u_int32_t *, int *, + u_int32_t *, u_int32_t *, u_int32_t *, u_int32_t *, + u_int32_t *, u_int32_t *)); +__END_DECLS + +#endif /* _FILE_H_ */ diff --git a/package/mopd/src/common/get.c b/package/mopd/src/common/get.c new file mode 100644 index 000000000..995f20a44 --- /dev/null +++ b/package/mopd/src/common/get.c @@ -0,0 +1,152 @@ +/* $NetBSD: get.c,v 1.2 1997/03/25 03:07:15 thorpej Exp $ */ + +/* + * Copyright (c) 1993-95 Mats O Jansson. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Mats O Jansson. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#ifndef lint +static char rcsid[]="$NetBSD: get.c,v 1.2 1997/03/25 03:07:15 thorpej Exp $"; +#endif + +#include "os.h" +#include "get.h" +#include "mopdef.h" + +u_char +mopGetChar(pkt, index) + u_char *pkt; + int *index; +{ + u_char ret; + + ret = pkt[*index]; + *index = *index + 1; + return(ret); +} + +u_short +mopGetShort(pkt, index) + u_char *pkt; + int *index; +{ + u_short ret; + + ret = pkt[*index] + pkt[*index+1]*256; + *index = *index + 2; + return(ret); +} + +u_int32_t +mopGetLong(pkt, index) + u_char *pkt; + int *index; +{ + u_int32_t ret; + + ret = pkt[*index] + + pkt[*index+1]*0x100 + + pkt[*index+2]*0x10000 + + pkt[*index+3]*0x1000000; + *index = *index + 4; + return(ret); +} + +void +mopGetMulti(pkt, index, dest, size) + u_char *pkt,*dest; + int *index,size; +{ + int i; + + for (i = 0; i < size; i++) { + dest[i] = pkt[*index+i]; + } + *index = *index + size; + +} + +int +mopGetTrans(pkt, trans) + u_char *pkt; + int trans; +{ + u_short *ptype; + + if (trans == 0) { + ptype = (u_short *)(pkt+12); + if (ntohs(*ptype) < 1600) { + trans = TRANS_8023; + } else { + trans = TRANS_ETHER; + } + } + return(trans); +} + +void +mopGetHeader(pkt, index, dst, src, proto, len, trans) + u_char *pkt, **dst, **src; + int *index, *len, trans; + u_short *proto; +{ + *dst = pkt; + *src = pkt + 6; + *index = *index + 12; + + switch(trans) { + case TRANS_ETHER: + *proto = (u_short)(pkt[*index]*256 + pkt[*index+1]); + *index = *index + 2; + *len = (int)(pkt[*index+1]*256 + pkt[*index]); + *index = *index + 2; + break; + case TRANS_8023: + *len = (int)(pkt[*index]*256 + pkt[*index+1]); + *index = *index + 8; + *proto = (u_short)(pkt[*index]*256 + pkt[*index+1]); + *index = *index + 2; + break; + } +} + +u_short +mopGetLength(pkt, trans) + u_char *pkt; + int trans; +{ + switch(trans) { + case TRANS_ETHER: + return(pkt[15]*256 + pkt[14]); + break; + case TRANS_8023: + return(pkt[12]*256 + pkt[13]); + break; + } + return(0); +} diff --git a/package/mopd/src/common/get.h b/package/mopd/src/common/get.h new file mode 100644 index 000000000..54ec18dbe --- /dev/null +++ b/package/mopd/src/common/get.h @@ -0,0 +1,4