2 * lib/tr.c This file contains an implementation of the "Tokenring"
5 * Version: $Id: tr.c,v 1.9 2005/05/16 03:15:12 ecki Exp $
7 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
8 * Copyright 1993 MicroWalt Corporation
10 * This program is free software; you can redistribute it
11 * and/or modify it under the terms of the GNU General
12 * Public License as published by the Free Software
13 * Foundation; either version 2 of the License, or (at
14 * your option) any later version.
19 #include <asm/types.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <net/if_arp.h>
23 #include <linux/if_tr.h>
30 #include "net-support.h"
31 #include "pathnames.h"
36 /* actual definition at the end of file */
37 extern struct hwtype tr_hwtype;
38 #ifdef ARPHRD_IEEE802_TR
39 extern struct hwtype tr_hwtype1;
42 static char *pr_tr(unsigned char *ptr)
46 snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
47 (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
48 (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
54 static int in_tr(char *bufp, struct sockaddr *sap)
60 #ifdef ARPHRD_IEEE802_TR
61 if (kernel_version() < KRELEASE(2,3,30)) {
62 sap->sa_family = tr_hwtype.type;
64 sap->sa_family = tr_hwtype1.type;
67 sap->sa_family = tr_hwtype.type;
68 #warning "Limited functionality, no support for ARPHRD_IEEE802_TR (old kernel headers?)"
75 while ((*bufp != '\0') && (i < TR_ALEN)) {
80 else if (c >= 'a' && c <= 'f')
82 else if (c >= 'A' && c <= 'F')
86 fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);
95 else if (c >= 'a' && c <= 'f')
97 else if (c >= 'A' && c <= 'F')
101 fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);
106 *ptr++ = (unsigned char) (val & 0377);
109 /* We might get a semicolon here - not required. */
113 fprintf(stderr, _("in_tr(%s): trailing : ignored!\n"),
122 /* That's it. Any trailing junk? */
123 if ((i == TR_ALEN) && (*bufp != '\0')) {
125 fprintf(stderr, _("in_tr(%s): trailing junk!\n"), orig);
131 fprintf(stderr, "in_tr(%s): %s\n", orig, pr_tr(sap->sa_data));
138 struct hwtype tr_hwtype =
140 "tr", NULL /* "16/4 Mbps Token Ring" */, ARPHRD_IEEE802, TR_ALEN,
143 #ifdef ARPHRD_IEEE802_TR
144 struct hwtype tr_hwtype1 =
146 "tr", NULL /* "16/4 Mbps Token Ring" */, ARPHRD_IEEE802_TR, TR_ALEN,
152 #endif /* HAVE_HWTR */