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>
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.
20 #if HAVE_AFROSE || HAVE_HWROSE
22 #include <sys/types.h>
23 #include <sys/ioctl.h>
24 #include <sys/socket.h>
25 #include <net/if_arp.h> /* ARPHRD_ROSE */
34 #include "net-support.h"
35 #include "pathnames.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 */
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)"
46 #define PF_ROSE 11 /* Amateur Radio X.25 PLP */
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
52 static char ROSE_errmsg
[128];
54 extern struct aftype rose_aftype
;
57 ROSE_print(unsigned char *ptr
)
61 snprintf(buff
, sizeof(buff
), "%02x%02x%02x%02x%02x", ptr
[0], ptr
[1], ptr
[2], ptr
[3], ptr
[4]);
66 /* Display a ROSE socket address. */
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
)
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"));
89 fprintf(stderr
, "rose_input(%s): %s !\n", ROSE_errmsg
, orig
);
95 for (i
= 0, o
= 0; i
< 5; i
++) {
97 ptr
[i
] = (((bufp
[o
] - '0') << 4) | (bufp
[o
+ 1] - '0'));
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");
112 /* Display an error message. */
113 static void ROSE_herror(char *text
)
116 fprintf(stderr
, "%s\n", ROSE_errmsg
);
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)
126 sap
->sa_family
= ARPHRD_ROSE
;
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
,
145 #endif /* HAVE_xxROSE */