minor fix to return E_USAGE on -V instead of exit(0);
[oss-qm-packages.git] / lib / strip.c
blobfd396ba100546b45d4e8d493de9c60f107e9d60f
1 /*
2 * lib/strip.c This file contains an implementation of the STRIP
3 * support functions.
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.
15 #include "config.h"
17 #if HAVE_HWSTRIP
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>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <ctype.h>
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <string.h>
31 #include <termios.h>
32 #include <unistd.h>
33 #include "net-support.h"
34 #include "pathnames.h"
35 #include "util.h"
36 #include "intl.h"
39 extern struct hwtype strip_hwtype;
41 static char *
42 pr_strip(unsigned char *ptr)
44 static char buff[64];
45 if(ptr[1])
46 sprintf(buff, "%02x-%02x%02x-%02x%02x", *(ptr+1), *(ptr+2), *(ptr+3),
47 *(ptr+4), *(ptr+5));
48 else
49 sprintf(buff, "%02x%02x-%02x%02x", *(ptr+2), *(ptr+3), *(ptr+4),
50 *(ptr+5));
51 return buff;
54 static int
55 in_strip(char *bufp, struct sockaddr *sap)
57 int i,i0;
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] != '-'))
67 i++;
69 if (bufp[i] != '-')
70 return -1;
72 if(i-i0 == 2)
74 haddr->c[1] = strtol(&bufp[i0], 0, 16);
75 i++;
76 if(bufp[i] == 0) return -1;
77 }else{
78 haddr->c[1] = 0;
79 i=i0;
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] != '-'))
85 i++;
87 if (bufp[i] != '-')
88 return -1;
90 haddr->c[4] = strtol(&bufp[i+1], 0, 16) >> 8;
91 haddr->c[5] = strtol(&bufp[i+1], 0, 16) & 0xFF;
92 haddr->c[0] = 0;
94 return 0;
99 /* Start the STRIP encapsulation on the file descriptor. */
100 static int do_strip(int fd)
102 int disc = N_STRIP;
103 if (ioctl(fd, TIOCSETD, &disc) < 0)
105 fprintf(stderr, "STRIP_set_disc(%d): %s\n", disc, strerror(errno));
106 return(-errno);
108 return(0);
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 */