mirror of
https://github.com/dreamlayers/netbsd-mopd.git
synced 2026-01-11 23:43:12 +00:00
Quick+Dirty port to linux
This commit is contained in:
parent
dc7585852f
commit
e87ffe7de2
15
common/Makefile.linux
Normal file
15
common/Makefile.linux
Normal file
@ -0,0 +1,15 @@
|
||||
# $NetBSD: Makefile.linux,v 1.1 2016/06/08 01:11:49 christos Exp $
|
||||
SRCS+=cmp.c device.c dl.c file.c get.c log.c loop-linux2.c mopdef.c nma.c
|
||||
SRCS+=pf-linux2.c print.c put.c rc.c version.c
|
||||
OBJS+=${SRCS:.c=.o}
|
||||
|
||||
CFLAGS+=-DNOAOUT
|
||||
|
||||
libcommon.a: ${OBJS}
|
||||
ar cr $@ ${OBJS}
|
||||
|
||||
version.c: VERSION
|
||||
@rm -f $@
|
||||
sed -e 's/.*/char version[] = "&";/' VERSION > $@
|
||||
clean:
|
||||
rm -f ${OBJS} libcommon.a version.c
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cmp.c,v 1.5 2009/11/17 18:58:07 drochner Exp $ */
|
||||
/* $NetBSD: cmp.c,v 1.6 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: cmp.c,v 1.5 2009/11/17 18:58:07 drochner Exp $");
|
||||
__RCSID("$NetBSD: cmp.c,v 1.6 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: device.c,v 1.12 2011/08/30 19:49:10 joerg Exp $ */
|
||||
/* $NetBSD: device.c,v 1.13 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: device.c,v 1.12 2011/08/30 19:49:10 joerg Exp $");
|
||||
__RCSID("$NetBSD: device.c,v 1.13 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
@ -40,7 +40,6 @@ struct if_info *iflist; /* Interface List */
|
||||
|
||||
void deviceOpen(const char *, u_short, int);
|
||||
|
||||
#ifdef DEV_NEW_CONF
|
||||
/*
|
||||
* Return ethernet address for interface
|
||||
*/
|
||||
@ -48,6 +47,20 @@ void deviceOpen(const char *, u_short, int);
|
||||
void
|
||||
deviceEthAddr(const char *ifname, u_char *eaddr)
|
||||
{
|
||||
#ifndef AF_LINK
|
||||
int fd;
|
||||
struct ifreq ifr;
|
||||
|
||||
/* Use datagram socket to get Ethernet address. */
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
|
||||
mopLogErr("deviceEthAddr: socket");
|
||||
|
||||
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||
if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1)
|
||||
mopLogErr("deviceEthAddr: SIOGIFHWADDR");
|
||||
memcpy(eaddr, ifr.ifr_hwaddr.sa_data, 6);
|
||||
close(fd);
|
||||
#else
|
||||
struct sockaddr_dl *sdl;
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
|
||||
@ -68,8 +81,8 @@ deviceEthAddr(const char *ifname, u_char *eaddr)
|
||||
|
||||
freeifaddrs(ifap);
|
||||
mopLogErrX("deviceEthAddr: Never saw interface `%s'!", ifname);
|
||||
#endif
|
||||
}
|
||||
#endif /* DEV_NEW_CONF */
|
||||
|
||||
void
|
||||
deviceOpen(const char *ifname, u_short proto, int trans)
|
||||
@ -93,7 +106,7 @@ deviceOpen(const char *ifname, u_short proto, int trans)
|
||||
}
|
||||
|
||||
if (tmp.fd != -1) {
|
||||
p = (struct if_info *)malloc(sizeof(*p));
|
||||
p = malloc(sizeof(*p));
|
||||
if (p == 0)
|
||||
mopLogErr("deviceOpen: malloc");
|
||||
|
||||
@ -220,18 +233,19 @@ deviceInitOne(const char *ifname)
|
||||
void
|
||||
deviceInitAll(void)
|
||||
{
|
||||
#ifdef DEV_NEW_CONF
|
||||
struct sockaddr_dl *sdl;
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
|
||||
if (getifaddrs(&ifap) != 0)
|
||||
mopLogErr("deviceInitAll: socket");
|
||||
|
||||
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
||||
#ifdef AF_LINK
|
||||
struct sockaddr_dl *sdl;
|
||||
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
||||
if (sdl->sdl_family != AF_LINK || sdl->sdl_type != IFT_ETHER ||
|
||||
sdl->sdl_alen != 6)
|
||||
continue;
|
||||
#endif
|
||||
if ((ifa->ifa_flags &
|
||||
(IFF_UP | IFF_LOOPBACK | IFF_POINTOPOINT)) != IFF_UP)
|
||||
continue;
|
||||
@ -239,20 +253,4 @@ deviceInitAll(void)
|
||||
}
|
||||
|
||||
freeifaddrs(ifap);
|
||||
#else
|
||||
struct ifaddrs *ifap, *ifa;
|
||||
|
||||
if (getifaddrs(&ifap) != 0)
|
||||
mopLogErr("deviceInitAll: old socket");
|
||||
|
||||
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
||||
if (/*(ifa->ifa_flags & IFF_UP) == 0 ||*/
|
||||
ifa->ifa_flags & IFF_LOOPBACK ||
|
||||
ifa->ifa_flags & IFF_POINTOPOINT)
|
||||
continue;
|
||||
deviceInitOne(ifa->ifa_name);
|
||||
}
|
||||
|
||||
freeifaddrs(ifap);
|
||||
#endif /* DEV_NEW_CONF */
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dl.c,v 1.8 2011/05/24 13:08:16 joerg Exp $ */
|
||||
/* $NetBSD: dl.c,v 1.9 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: dl.c,v 1.8 2011/05/24 13:08:16 joerg Exp $");
|
||||
__RCSID("$NetBSD: dl.c,v 1.9 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: file.c,v 1.15 2011/08/31 13:09:10 nakayama Exp $ */
|
||||
/* $NetBSD: file.c,v 1.16 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995-96 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: file.c,v 1.15 2011/08/31 13:09:10 nakayama Exp $");
|
||||
__RCSID("$NetBSD: file.c,v 1.16 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: get.c,v 1.6 2009/11/17 18:58:07 drochner Exp $ */
|
||||
/* $NetBSD: get.c,v 1.7 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: get.c,v 1.6 2009/11/17 18:58:07 drochner Exp $");
|
||||
__RCSID("$NetBSD: get.c,v 1.7 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: log.c,v 1.3 2014/07/27 04:38:03 dholland Exp $ */
|
||||
/* $NetBSD: log.c,v 1.4 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
@ -29,9 +29,9 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: log.c,v 1.3 2014/07/27 04:38:03 dholland Exp $");
|
||||
__RCSID("$NetBSD: log.c,v 1.4 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: loop-bsd.c,v 1.11 2011/08/30 19:49:10 joerg Exp $ */
|
||||
/* $NetBSD: loop-bsd.c,v 1.12 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: loop-bsd.c,v 1.11 2011/08/30 19:49:10 joerg Exp $");
|
||||
__RCSID("$NetBSD: loop-bsd.c,v 1.12 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
158
common/loop-linux2.c
Normal file
158
common/loop-linux2.c
Normal file
@ -0,0 +1,158 @@
|
||||
/* $NetBSD: loop-linux2.c,v 1.1 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Mats O Jansson.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: loop-linux2.c,v 1.1 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#if defined(__bsdi__) || defined(__FreeBSD__)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "common.h"
|
||||
#include "mopdef.h"
|
||||
|
||||
int
|
||||
mopOpenRC(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(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)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
mopReadDL(void)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* The list of all interfaces that are being listened to. loop()
|
||||
* "selects" on the descriptors in this list.
|
||||
*/
|
||||
struct if_info *iflist;
|
||||
|
||||
void mopProcess(struct if_info *, u_char *);
|
||||
|
||||
/*
|
||||
* Loop indefinitely listening for MOP requests on the
|
||||
* interfaces in 'iflist'.
|
||||
*/
|
||||
void
|
||||
Loop(void)
|
||||
{
|
||||
u_char *buf, *bp, *ep;
|
||||
int cc;
|
||||
fd_set fds, listeners;
|
||||
int bufsize = 1100, maxfd =0;
|
||||
struct if_info *ii;
|
||||
|
||||
|
||||
if (iflist == 0) {
|
||||
syslog(LOG_ERR, "no interfaces");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
buf = (u_char *) malloc((unsigned) bufsize);
|
||||
|
||||
if (buf == 0) {
|
||||
syslog(LOG_ERR, "malloc: %m");
|
||||
exit(0);
|
||||
}
|
||||
/*
|
||||
* Find the highest numbered file descriptor for select().
|
||||
* Initialize the set of descriptors to listen to.
|
||||
*/
|
||||
FD_ZERO(&fds);
|
||||
for (ii = iflist; ii; ii = ii->next) {
|
||||
if (ii->fd != -1) {
|
||||
FD_SET(ii->fd, &fds);
|
||||
if (ii->fd > maxfd)
|
||||
maxfd = ii->fd;
|
||||
}
|
||||
}
|
||||
while (1) {
|
||||
listeners = fds;
|
||||
if (select(maxfd + 1, &listeners, (fd_set *) 0,
|
||||
(fd_set *) 0, (struct timeval *) 0) < 0) {
|
||||
syslog(LOG_ERR, "select: %m");
|
||||
exit(0);
|
||||
}
|
||||
for (ii = iflist; ii; ii = ii->next) {
|
||||
if (ii->fd != -1) {
|
||||
if (!FD_ISSET(ii->fd, &listeners))
|
||||
continue;
|
||||
}
|
||||
again:
|
||||
cc = read(ii->fd, (char *) buf, bufsize);
|
||||
/* Don't choke when we get ptraced */
|
||||
if (cc < 0 && errno == EINTR)
|
||||
goto again;
|
||||
|
||||
bp = buf;
|
||||
ep = bp + cc;
|
||||
|
||||
if(bp < ep) {
|
||||
mopProcess(ii,buf);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mopdef.c,v 1.5 2011/08/30 19:49:10 joerg Exp $ */
|
||||
/* $NetBSD: mopdef.c,v 1.6 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: mopdef.c,v 1.5 2011/08/30 19:49:10 joerg Exp $");
|
||||
__RCSID("$NetBSD: mopdef.c,v 1.6 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#define MOPDEF_SURPESS_EXTERN
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: nma.c,v 1.6 2011/08/30 19:49:11 joerg Exp $ */
|
||||
/* $NetBSD: nma.c,v 1.7 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: nma.c,v 1.6 2011/08/30 19:49:11 joerg Exp $");
|
||||
__RCSID("$NetBSD: nma.c,v 1.7 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: os.h,v 1.6 2009/10/20 00:51:13 snj Exp $ */
|
||||
/* $NetBSD: os.h,v 1.7 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994-95 Mats O Jansson. All rights reserved.
|
||||
@ -23,7 +23,7 @@
|
||||
* (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: os.h,v 1.6 2009/10/20 00:51:13 snj Exp $
|
||||
* $NetBSD: os.h,v 1.7 2016/06/08 01:11:49 christos Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -37,8 +37,11 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
#ifdef __NetBSD__
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_types.h>
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
|
||||
305
common/pf-linux2.c
Normal file
305
common/pf-linux2.c
Normal file
@ -0,0 +1,305 @@
|
||||
/* $NetBSD: pf-linux2.c,v 1.1 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* General Purpose AppleTalk Packet Filter Interface
|
||||
*
|
||||
* Copyright (c) 1992-1995, The University of Melbourne.
|
||||
* All Rights Reserved. Permission to redistribute or
|
||||
* use any part of this software for any purpose must
|
||||
* be obtained in writing from the copyright owner.
|
||||
*
|
||||
* This software is supplied "as is" without express
|
||||
* or implied warranty.
|
||||
*
|
||||
* djh@munnari.OZ.AU
|
||||
*
|
||||
* Supports:
|
||||
* Linux SOCK_PACKET
|
||||
*
|
||||
*
|
||||
* Modified for use with the linux-mopd port by Karl Maftoum
|
||||
* u963870@student.canberra.edu.au
|
||||
*
|
||||
*/
|
||||
|
||||
#include "port.h"
|
||||
__RCSID("$NetBSD: pf-linux2.c,v 1.1 2016/06/08 01:11:49 christos Exp $");
|
||||
|
||||
/*
|
||||
* include header files
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.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 <net/if.h>
|
||||
#include <sys/errno.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <netdb.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MOPDEF_SUPRESS_EXTERN
|
||||
#include "mopdef.h"
|
||||
|
||||
/*
|
||||
* definitions
|
||||
*
|
||||
*/
|
||||
|
||||
#define READBUFSIZ 4096
|
||||
#define NUMRDS 32
|
||||
|
||||
struct RDS {
|
||||
u_short dataLen;
|
||||
u_char *dataPtr;
|
||||
};
|
||||
|
||||
/*
|
||||
* variables
|
||||
*
|
||||
*/
|
||||
|
||||
struct socklist {
|
||||
int iflen;
|
||||
struct sockaddr sa;
|
||||
} socklist[32];
|
||||
|
||||
struct ifreq ifr;
|
||||
extern int errno;
|
||||
extern int promisc;
|
||||
|
||||
struct RDS RDS[NUMRDS];
|
||||
static int setup_pf(int, int, u_short);
|
||||
|
||||
/*
|
||||
* Open and initialize packet filter
|
||||
* for a particular protocol type.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
int
|
||||
pfInit(char *interface, u_short protocol, int typ, int mode)
|
||||
{
|
||||
int s;
|
||||
int ioarg;
|
||||
char device[64];
|
||||
unsigned long if_flags;
|
||||
|
||||
|
||||
{ u_short prot;
|
||||
|
||||
prot = ((typ == TRANS_8023) ? htons(ETH_P_802_2) : htons(protocol));
|
||||
if ((s = socket(AF_INET, SOCK_PACKET, prot)) < 0) {
|
||||
perror(interface);
|
||||
return(-1);
|
||||
}
|
||||
if (s >= 32) {
|
||||
close(s);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* set filter for protocol and type (IPTalk, Phase 1/2)
|
||||
*
|
||||
*/
|
||||
|
||||
if (setup_pf(s, protocol, typ) < 0)
|
||||
return(-1);
|
||||
|
||||
/*
|
||||
* set options, bind to underlying interface
|
||||
*
|
||||
*/
|
||||
|
||||
strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
|
||||
|
||||
/* record socket interface name and length */
|
||||
strncpy(socklist[s].sa.sa_data, interface, sizeof(socklist[s].sa.sa_data));
|
||||
socklist[s].iflen = strlen(interface);
|
||||
|
||||
return(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* establish protocol filter
|
||||
*
|
||||
*/
|
||||
|
||||
static int
|
||||
setup_pf(int s, int typ, u_short prot)
|
||||
{
|
||||
int ioarg;
|
||||
u_short offset;
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* get the interface ethernet address
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
pfEthAddr(int s, char *interface, u_char *addr)
|
||||
{
|
||||
strncpy(ifr.ifr_name, interface, sizeof (ifr.ifr_name) -1);
|
||||
ifr.ifr_name[sizeof(ifr.ifr_name)] = 0;
|
||||
ifr.ifr_addr.sa_family = AF_INET;
|
||||
if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
|
||||
perror("SIOCGIFHWADDR");
|
||||
return(-1);
|
||||
}
|
||||
memcpy((char *)addr, ifr.ifr_hwaddr.sa_data, 6);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* add a multicast address to the interface
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
pfAddMulti(int s, char *interface, u_char *addr)
|
||||
{
|
||||
int sock;
|
||||
|
||||
strncpy(ifr.ifr_name, interface, sizeof (ifr.ifr_name) - 1);
|
||||
ifr.ifr_name[sizeof(ifr.ifr_name)] = 0;
|
||||
|
||||
ifr.ifr_addr.sa_family = AF_UNSPEC;
|
||||
bcopy((char *)addr, ifr.ifr_addr.sa_data, 6);
|
||||
|
||||
/*
|
||||
* open a socket, temporarily, to use for SIOC* ioctls
|
||||
*
|
||||
*/
|
||||
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("socket()");
|
||||
return(-1);
|
||||
}
|
||||
if (ioctl(sock, SIOCADDMULTI, (caddr_t)&ifr) < 0) {
|
||||
perror("SIOCADDMULTI");
|
||||
close(sock);
|
||||
return(-1);
|
||||
}
|
||||
close(sock);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* delete a multicast address from the interface
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
pfDelMulti(int s, char *interface, u_char *addr)
|
||||
{
|
||||
int sock;
|
||||
|
||||
strncpy(ifr.ifr_name, interface, sizeof (ifr.ifr_name) - 1);
|
||||
ifr.ifr_name[sizeof(ifr.ifr_name)] = 0;
|
||||
|
||||
ifr.ifr_addr.sa_family = AF_UNSPEC;
|
||||
bcopy((char *)addr, ifr.ifr_addr.sa_data, 6);
|
||||
|
||||
/*
|
||||
* open a socket, temporarily, to use for SIOC* ioctls
|
||||
*
|
||||
*/
|
||||
if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("socket()");
|
||||
return(-1);
|
||||
}
|
||||
if (ioctl(sock, SIOCDELMULTI, (caddr_t)&ifr) < 0) {
|
||||
perror("SIOCDELMULTI");
|
||||
close(sock);
|
||||
return(-1);
|
||||
}
|
||||
close(sock);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* return 1 if ethernet interface capable of multiple opens
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
eth_mopen(int phase)
|
||||
{
|
||||
if (phase == 2)
|
||||
return(0);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* read a packet
|
||||
* Read Data Structure describes packet(s) received
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
pfRead(int fd, u_char *buf, int len)
|
||||
{
|
||||
int i, cc;
|
||||
|
||||
int fromlen;
|
||||
struct sockaddr sa;
|
||||
|
||||
RDS[0].dataLen = 0;
|
||||
fromlen = sizeof(struct sockaddr);
|
||||
|
||||
if ((cc = recvfrom(fd, (char *)buf, len, 0, &sa, &fromlen)) <= 0)
|
||||
return(cc);
|
||||
|
||||
/* check if from right interface */
|
||||
for (i = socklist[fd].iflen-1; i >= 0; i--)
|
||||
if (sa.sa_data[i] != socklist[fd].sa.sa_data[i])
|
||||
return(0);
|
||||
|
||||
RDS[0].dataLen = cc;
|
||||
RDS[0].dataPtr = buf;
|
||||
RDS[1].dataLen = 0;
|
||||
|
||||
return(cc);
|
||||
}
|
||||
|
||||
/*
|
||||
* write a packet
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
pfWrite(int fd, u_char *buf, int len)
|
||||
{
|
||||
|
||||
if (sendto(fd, buf, len, 0, &socklist[fd].sa, sizeof(struct sockaddr)) == len)
|
||||
return(len);
|
||||
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return information to device.c how to open device.
|
||||
* In this case the driver can handle both Ethernet type II and
|
||||
* IEEE 802.3 frames (SNAP) in a single pfOpen.
|
||||
*/
|
||||
|
||||
int
|
||||
pfTrans(char *interface)
|
||||
{
|
||||
return TRANS_ETHER+TRANS_8023;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pf.c,v 1.12 2009/11/17 18:58:07 drochner Exp $ */
|
||||
/* $NetBSD: pf.c,v 1.13 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
@ -30,9 +30,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: pf.c,v 1.12 2009/11/17 18:58:07 drochner Exp $");
|
||||
__RCSID("$NetBSD: pf.c,v 1.13 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: print.c,v 1.7 2011/05/24 13:08:16 joerg Exp $ */
|
||||
/* $NetBSD: print.c,v 1.8 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-96 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: print.c,v 1.7 2011/05/24 13:08:16 joerg Exp $");
|
||||
__RCSID("$NetBSD: print.c,v 1.8 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: put.c,v 1.7 2011/05/24 13:08:16 joerg Exp $ */
|
||||
/* $NetBSD: put.c,v 1.8 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: put.c,v 1.7 2011/05/24 13:08:16 joerg Exp $");
|
||||
__RCSID("$NetBSD: put.c,v 1.8 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: rc.c,v 1.7 2011/05/24 13:08:16 joerg Exp $ */
|
||||
/* $NetBSD: rc.c,v 1.8 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: rc.c,v 1.7 2011/05/24 13:08:16 joerg Exp $");
|
||||
__RCSID("$NetBSD: rc.c,v 1.8 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
1
common/version.c
Normal file
1
common/version.c
Normal file
@ -0,0 +1 @@
|
||||
char version[] = "2.5.3";
|
||||
11
mopd/Makefile.linux
Normal file
11
mopd/Makefile.linux
Normal file
@ -0,0 +1,11 @@
|
||||
# $NetBSD: Makefile.linux,v 1.1 2016/06/08 01:11:49 christos Exp $
|
||||
SRCS=mopd.c process.c
|
||||
OBJS=${SRCS:.c=.o}
|
||||
|
||||
LDLIBS+=../common/libcommon.a
|
||||
CFLAGS+=-I../common
|
||||
|
||||
mopd: ${OBJS}
|
||||
|
||||
clean:
|
||||
rm -f ${OBJS} mopd
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: mopd.c,v 1.14 2011/08/30 19:49:11 joerg Exp $ */
|
||||
/* $NetBSD: mopd.c,v 1.15 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-96 Mats O Jansson. All rights reserved.
|
||||
@ -23,10 +23,9 @@
|
||||
* (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 <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: mopd.c,v 1.14 2011/08/30 19:49:11 joerg Exp $");
|
||||
__RCSID("$NetBSD: mopd.c,v 1.15 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -48,8 +47,6 @@ __RCSID("$NetBSD: mopd.c,v 1.14 2011/08/30 19:49:11 joerg Exp $");
|
||||
#include "process.h"
|
||||
#include "rc.h"
|
||||
|
||||
#include <util.h>
|
||||
|
||||
/*
|
||||
* The list of all interfaces that are being listened to.
|
||||
* "selects" on the descriptors in this list.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: process.c,v 1.20 2014/10/18 08:33:31 snj Exp $ */
|
||||
/* $NetBSD: process.c,v 1.21 2016/06/08 01:11:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
|
||||
@ -24,9 +24,9 @@
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include "port.h"
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: process.c,v 1.20 2014/10/18 08:33:31 snj Exp $");
|
||||
__RCSID("$NetBSD: process.c,v 1.21 2016/06/08 01:11:49 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user