minor fix to return E_USAGE on -V instead of exit(0);
[oss-qm-packages.git] / lib / rose.c
blob381226b316b6df6442e2ce1e6231b8867b03aee7
1 /*
2 * lib/rose.c This file contains an implementation of the "ROSE"
3 * support functions for the NET-2 base distribution.
5 * Version: $Id: rose.c,v 1.7 2000/03/05 11:26:03 philip Exp $
7 * Author: Terry Dawson, VK2KTJ, <terry@perf.no.itg.telstra.com.au>
8 * based on ax25.c by:
9 * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
10 * Copyright 1993 MicroWalt Corporation
12 * This program is free software; you can redistribute it
13 * and/or modify it under the terms of the GNU General
14 * Public License as published by the Free Software
15 * Foundation; either version 2 of the License, or (at
16 * your option) any later version.
18 #include "config.h"
20 #if HAVE_AFROSE || HAVE_HWROSE
21 #include <features.h>
22 #include <sys/types.h>
23 #include <sys/ioctl.h>
24 #include <sys/socket.h>
25 #include <net/if_arp.h> /* ARPHRD_ROSE */
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <ctype.h>
29 #include <errno.h>
30 #include <fcntl.h>
31 #include <string.h>
32 #include <termios.h>
33 #include <unistd.h>
34 #include "net-support.h"
35 #include "pathnames.h"
36 #include "intl.h"
38 #ifndef _NETROSE_ROSE_H
39 #include <linux/ax25.h>
40 #include <linux/rose.h>
41 /* this will check for the broken #define PF_ROSE AF_ROSE define in some older kernel headers */
42 #undef AF_ROSE
43 #if PF_ROSE == AF_ROSE
44 #warning "Your <linux/rose.h> is broken and defines PF_ROSE, better remove the define in /usr/include/linux/rose.h (using private define for PF_ROSE meanwhile)"
45 #undef PF_ROSE
46 #define PF_ROSE 11 /* Amateur Radio X.25 PLP */
47 #endif
48 /* now restore the value of AF_ROSE (which had to be deleted to catch the case where #define AF_ROSE PF_ROSE) */
49 #define AF_ROSE PF_ROSE
50 #endif
52 static char ROSE_errmsg[128];
54 extern struct aftype rose_aftype;
56 static char *
57 ROSE_print(unsigned char *ptr)
59 static char buff[12];
61 snprintf(buff, sizeof(buff), "%02x%02x%02x%02x%02x", ptr[0], ptr[1], ptr[2], ptr[3], ptr[4]);
62 buff[10] = '\0';
63 return (buff);
66 /* Display a ROSE socket address. */
67 static char *
68 ROSE_sprint(struct sockaddr *sap, int numeric)
70 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
71 return _("[NONE SET]");
73 return (ROSE_print(((struct sockaddr_rose *) sap)->srose_addr.rose_addr));
77 static int ROSE_input(int type, char *bufp, struct sockaddr *sap)
79 char *ptr;
80 int i, o;
82 sap->sa_family = rose_aftype.af;
83 ptr = ((struct sockaddr_rose *) sap)->srose_addr.rose_addr;
85 /* Node address the correct length ? */
86 if (strlen(bufp) != 10) {
87 strcpy(ROSE_errmsg, _("Node address must be ten digits"));
88 #ifdef DEBUG
89 fprintf(stderr, "rose_input(%s): %s !\n", ROSE_errmsg, orig);
90 #endif
91 errno = EINVAL;
92 return (-1);
94 /* Ok, lets set it */
95 for (i = 0, o = 0; i < 5; i++) {
96 o = i * 2;
97 ptr[i] = (((bufp[o] - '0') << 4) | (bufp[o + 1] - '0'));
100 /* All done. */
101 #ifdef DEBUG
102 fprintf(stderr, "rose_input(%s): ", orig);
103 for (i = 0; i < sizeof(rose_address); i++)
104 fprintf(stderr, "%02X ", sap->sa_data[i] & 0377);
105 fprintf(stderr, "\n");
106 #endif
108 return (0);
112 /* Display an error message. */
113 static void ROSE_herror(char *text)
115 if (text == NULL)
116 fprintf(stderr, "%s\n", ROSE_errmsg);
117 else
118 fprintf(stderr, "%s: %s\n", text, ROSE_errmsg);
122 static int ROSE_hinput(char *bufp, struct sockaddr *sap)
124 if (ROSE_input(0, bufp, sap) < 0)
125 return (-1);
126 sap->sa_family = ARPHRD_ROSE;
127 return (0);
130 struct hwtype rose_hwtype =
132 "rose", NULL, /*"AMPR ROSE", */ ARPHRD_ROSE, 10,
133 ROSE_print, ROSE_hinput, NULL
136 struct aftype rose_aftype =
138 "rose", NULL, /*"AMPR ROSE", */ AF_ROSE, 10,
139 ROSE_print, ROSE_sprint, ROSE_input, ROSE_herror,
140 NULL, NULL, NULL,
142 "/proc/net/rose"
145 #endif /* HAVE_xxROSE */