diff options
author | Phil Blundell <philb@gnu.org> | 2000-04-02 12:56:41 +0000 |
---|---|---|
committer | Phil Blundell <philb@gnu.org> | 2000-04-02 12:56:41 +0000 |
commit | 5e0493697ce2cdee271467d5a1aa547a278a3920 (patch) | |
tree | 727d625db241e92e59bd48f8413a466c14e908e8 /lib | |
parent | fix from Lapo Pieri to support non ethernet Default HW types (diff) | |
download | net-tools-5e0493697ce2cdee271467d5a1aa547a278a3920.tar.gz net-tools-5e0493697ce2cdee271467d5a1aa547a278a3920.tar.bz2 net-tools-5e0493697ce2cdee271467d5a1aa547a278a3920.zip |
Add STRIP support.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/hw.c | 6 | ||||
-rw-r--r-- | lib/strip.c | 98 |
3 files changed, 104 insertions, 2 deletions
diff --git a/lib/Makefile b/lib/Makefile index d8070bf..e5720e0 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -16,7 +16,7 @@ # -HWOBJS = hw.o loopback.o slip.o ether.o ax25.o ppp.o arcnet.o tr.o tunnel.o frame.o sit.o rose.o ash.o fddi.o hippi.o hdlclapb.o irda.o ec_hw.o +HWOBJS = hw.o loopback.o slip.o ether.o ax25.o ppp.o arcnet.o tr.o tunnel.o frame.o sit.o rose.o ash.o fddi.o hippi.o hdlclapb.o strip.o irda.o ec_hw.o AFOBJS = unix.o inet.o inet6.o ax25.o ipx.o ddp.o ipx.o netrom.o af.o rose.o econet.o AFGROBJS = inet_gr.o inet6_gr.o ipx_gr.o ddp_gr.o netrom_gr.o ax25_gr.o rose_gr.o getroute.o AFSROBJS = inet_sr.o inet6_sr.o netrom_sr.o ipx_sr.o setroute.o @@ -2,7 +2,7 @@ * lib/hw.c This file contains the top-level part of the hardware * support functions module. * - * Version: $Id: hw.c,v 1.15 1999/12/11 12:09:23 philip Exp $ + * Version: $Id: hw.c,v 1.16 2000/04/02 12:56:44 philip Exp $ * * Maintainer: Bernd 'eckes' Eckenfels, <net-tools@lina.inka.de> * @@ -39,6 +39,7 @@ extern struct hwtype cslip_hwtype; extern struct hwtype slip6_hwtype; extern struct hwtype cslip6_hwtype; extern struct hwtype adaptive_hwtype; +extern struct hwtype strip_hwtype; extern struct hwtype ether_hwtype; extern struct hwtype fddi_hwtype; @@ -83,6 +84,9 @@ static struct hwtype *hwtypes[] = &cslip6_hwtype, &adaptive_hwtype, #endif +#if HAVE_HWSTRIP + &strip_hwtype, +#endif #if HAVE_HWASH &ash_hwtype, #endif diff --git a/lib/strip.c b/lib/strip.c new file mode 100644 index 0000000..eb74ce8 --- /dev/null +++ b/lib/strip.c @@ -0,0 +1,98 @@ +/* + * lib/strip.c This file contains an implementation of the STRIP + * support functions. + * + * Version: strip.c 1.20 1999/04/22 eswierk + * + * Author: Stuart Cheshire <cheshire@cs.stanford.edu> + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at + * your option) any later version. + */ +#include "config.h" + +#if HAVE_HWSTRIP + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <net/if_arp.h> +#include <linux/types.h> +#include <linux/if_strip.h> +#include <stdlib.h> +#include <stdio.h> +#include <ctype.h> +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <termios.h> +#include <unistd.h> +#include "net-support.h" +#include "pathnames.h" +#include "util.h" +#include "intl.h" + + +extern struct hwtype strip_hwtype; + +static char * +pr_strip(unsigned char *ptr) +{ + static char buff[64]; + + sprintf(buff, "%02x%02x-%02x%02x", *(ptr+2), *(ptr+3), *(ptr+4), + *(ptr+5)); + return buff; +} + +static int +in_strip(char *bufp, struct sockaddr *sap) +{ + int i; + MetricomAddress *haddr = (MetricomAddress *) (sap->sa_data); + + + sap->sa_family = strip_hwtype.type; + + /* figure out what the device-address should be */ + i = (bufp[0] == '*') ? 1 : 0; + haddr->c[2] = strtol(&bufp[i], 0, 16) >> 8; + haddr->c[3] = strtol(&bufp[i], 0, 16) & 0xFF; + + while (bufp[i] && (bufp[i] != '-')) + i++; + + if (bufp[i] != '-') + return -1; + + haddr->c[4] = strtol(&bufp[i+1], 0, 16) >> 8; + haddr->c[5] = strtol(&bufp[i+1], 0, 16) & 0xFF; + haddr->c[0] = 0; + haddr->c[1] = 0; + + return 0; +} + + + +/* Start the STRIP encapsulation on the file descriptor. */ +static int do_strip(int fd) + { + int disc = N_STRIP; + if (ioctl(fd, TIOCSETD, &disc) < 0) + { + fprintf(stderr, "STRIP_set_disc(%d): %s\n", disc, strerror(errno)); + return(-errno); + } + return(0); + } + +struct hwtype strip_hwtype = { + "strip", "Metricom Starmode IP", ARPHRD_METRICOM, sizeof(MetricomAddress), + pr_strip, in_strip, do_strip, 0 +}; + +#endif /* HAVE_HWSTRIP */ |