2 * lib/strip.c This file contains an implementation of the STRIP
5 * Version: strip.c 1.20 1999/04/22 eswierk
7 * Author: Stuart Cheshire <cheshire@cs.stanford.edu>
9 * This program is free software; you can redistribute it
10 * and/or modify it under the terms of the GNU General
11 * Public License as published by the Free Software
12 * Foundation; either version 2 of the License, or (at
13 * your option) any later version.
19 #include <sys/types.h>
20 #include <sys/ioctl.h>
21 #include <sys/socket.h>
22 #include <net/if_arp.h>
23 #include <linux/types.h>
24 #include <linux/if_strip.h>
33 #include "net-support.h"
34 #include "pathnames.h"
39 extern struct hwtype strip_hwtype
;
42 pr_strip(unsigned char *ptr
)
46 sprintf(buff
, "%02x-%02x%02x-%02x%02x", *(ptr
+1), *(ptr
+2), *(ptr
+3),
49 sprintf(buff
, "%02x%02x-%02x%02x", *(ptr
+2), *(ptr
+3), *(ptr
+4),
55 in_strip(char *bufp
, struct sockaddr
*sap
)
58 MetricomAddress
*haddr
= (MetricomAddress
*) (sap
->sa_data
);
61 sap
->sa_family
= strip_hwtype
.type
;
63 /* figure out what the device-address should be */
64 i0
= i
= (bufp
[0] == '*') ? 1 : 0;
66 while (bufp
[i
] && (bufp
[i
] != '-'))
74 haddr
->c
[1] = strtol(&bufp
[i0
], 0, 16);
76 if(bufp
[i
] == 0) return -1;
81 haddr
->c
[2] = strtol(&bufp
[i
], 0, 16) >> 8;
82 haddr
->c
[3] = strtol(&bufp
[i
], 0, 16) & 0xFF;
84 while (bufp
[i
] && (bufp
[i
] != '-'))
90 haddr
->c
[4] = strtol(&bufp
[i
+1], 0, 16) >> 8;
91 haddr
->c
[5] = strtol(&bufp
[i
+1], 0, 16) & 0xFF;
99 /* Start the STRIP encapsulation on the file descriptor. */
100 static int do_strip(int fd
)
103 if (ioctl(fd
, TIOCSETD
, &disc
) < 0)
105 fprintf(stderr
, "STRIP_set_disc(%d): %s\n", disc
, strerror(errno
));
111 struct hwtype strip_hwtype
= {
112 "strip", "Metricom Starmode IP", ARPHRD_METRICOM
, sizeof(MetricomAddress
),
113 pr_strip
, in_strip
, do_strip
, 0
116 #endif /* HAVE_HWSTRIP */