2 * lib/rose.c This file contains an implementation of the "ROSE"
3 * support functions for the NET-2 base distribution.
5 * Version: @(#)rose.c 1.00 03/08/97
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"
39 #include <netrose/rose.h>
42 static char ROSE_errmsg[128];
44 extern struct aftype rose_aftype;
47 ROSE_print(unsigned char *ptr)
51 snprintf(buff,sizeof(buff),"%02x%02x%02x%02x%02x",ptr[0],ptr[1],ptr[2],ptr[3],ptr[4]);
56 /* Display a ROSE socket address. */
58 ROSE_sprint(struct sockaddr *sap, int numeric)
60 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
61 return _("[NONE SET]");
63 return(ROSE_print(((struct sockaddr_rose *)sap)->srose_addr.rose_addr));
68 ROSE_input(int type, char *bufp, struct sockaddr *sap)
73 sap->sa_family = rose_aftype.af;
74 ptr = ((struct sockaddr_rose *)sap)->srose_addr.rose_addr;
76 /* Node address the correct length ? */
77 if (strlen(bufp)!=10) {
78 strcpy(ROSE_errmsg, _("Node address must be ten digits"));
80 fprintf(stderr, "rose_input(%s): %s !\n", ROSE_errmsg, orig);
87 for (i=0, o=0; i<5; i++) {
89 ptr[i]=(((bufp[o]-'0')<<4) | (bufp[o+1]-'0'));
94 fprintf(stderr, "rose_input(%s): ", orig);
95 for (i = 0; i < sizeof(rose_address); i++)
96 fprintf(stderr, "%02X ", sap->sa_data[i] & 0377);
97 fprintf(stderr, "\n");
104 /* Display an error message. */
106 ROSE_herror(char *text)
108 if (text == NULL) fprintf(stderr, "%s\n", ROSE_errmsg);
109 else fprintf(stderr, "%s: %s\n", text, ROSE_errmsg);
114 ROSE_hprint(struct sockaddr *sap)
116 if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
117 return _("[NONE SET]");
119 return(ROSE_print(((struct sockaddr_rose *)sap)->srose_addr.rose_addr));
124 ROSE_hinput(char *bufp, struct sockaddr *sap)
126 if (ROSE_input(0, bufp, sap) < 0) return(-1);
127 sap->sa_family = ARPHRD_ROSE;
131 struct hwtype rose_hwtype = {
132 "rose", NULL, /*"AMPR ROSE",*/ ARPHRD_ROSE, 10,
133 ROSE_print, ROSE_hprint, ROSE_hinput, NULL
136 struct aftype rose_aftype = {
137 "rose", NULL, /*"AMPR ROSE",*/ AF_ROSE, 10,
138 ROSE_print, ROSE_sprint, ROSE_input, ROSE_herror,
144 #endif /* HAVE_xxROSE */