OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [userland/] [route/] [lib/] [tr.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/*
2
 * lib/tr.c   This file contains an implementation of the "Tokenring"
3
 *              support functions.
4
 *
5
 * Version:     $Id: tr.c,v 1.1 2002-03-17 19:58:53 simons Exp $
6
 *
7
 * Author:      Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
8
 *              Copyright 1993 MicroWalt Corporation
9
 *
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.
15
 */
16
#include "config.h"
17
 
18
#if HAVE_HWTR
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>
24
#include <stdlib.h>
25
#include <stdio.h>
26
#include <errno.h>
27
#include <ctype.h>
28
#include <string.h>
29
#include <unistd.h>
30
#include "net-support.h"
31
#include "pathnames.h"
32
#include "intl.h"
33
 
34
extern struct hwtype tr_hwtype;
35
 
36
static char *pr_tr(unsigned char *ptr)
37
{
38
    static char buff[64];
39
 
40
    snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X",
41
             (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
42
             (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
43
        );
44
    return (buff);
45
}
46
 
47
 
48
static char *pr_str(struct sockaddr *sap)
49
{
50
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
51
        return ("[NONE SET]");
52
    return (pr_tr(sap->sa_data));
53
}
54
 
55
 
56
static int in_tr(char *bufp, struct sockaddr *sap)
57
{
58
    unsigned char *ptr;
59
    char c, *orig;
60
    int i, val;
61
 
62
    sap->sa_family = tr_hwtype.type;
63
    ptr = sap->sa_data;
64
 
65
    i = 0;
66
    orig = bufp;
67
    while ((*bufp != '\0') && (i < TR_ALEN)) {
68
        val = 0;
69
        c = *bufp++;
70
        if (isdigit(c))
71
            val = c - '0';
72
        else if (c >= 'a' && c <= 'f')
73
            val = c - 'a' + 10;
74
        else if (c >= 'A' && c <= 'F')
75
            val = c - 'A' + 10;
76
        else {
77
#ifdef DEBUG
78
            fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);
79
#endif
80
            errno = EINVAL;
81
            return (-1);
82
        }
83
        val <<= 4;
84
        c = *bufp++;
85
        if (isdigit(c))
86
            val |= c - '0';
87
        else if (c >= 'a' && c <= 'f')
88
            val |= c - 'a' + 10;
89
        else if (c >= 'A' && c <= 'F')
90
            val |= c - 'A' + 10;
91
        else {
92
#ifdef DEBUG
93
            fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);
94
#endif
95
            errno = EINVAL;
96
            return (-1);
97
        }
98
        *ptr++ = (unsigned char) (val & 0377);
99
        i++;
100
 
101
        /* We might get a semicolon here - not required. */
102
        if (*bufp == ':') {
103
            if (i == TR_ALEN) {
104
#ifdef DEBUG
105
                fprintf(stderr, _("in_tr(%s): trailing : ignored!\n"),
106
                        orig)
107
#endif
108
                    ;           /* nothing */
109
            }
110
            bufp++;
111
        }
112
    }
113
 
114
    /* That's it.  Any trailing junk? */
115
    if ((i == TR_ALEN) && (*bufp != '\0')) {
116
#ifdef DEBUG
117
        fprintf(stderr, _("in_tr(%s): trailing junk!\n"), orig);
118
        errno = EINVAL;
119
        return (-1);
120
#endif
121
    }
122
#ifdef DEBUG
123
    fprintf(stderr, "in_tr(%s): %s\n", orig, pr_tr(sap->sa_data));
124
#endif
125
 
126
    return (0);
127
}
128
 
129
 
130
struct hwtype tr_hwtype =
131
{
132
    "tr", "16/4 Mbps Token Ring", ARPHRD_IEEE802, TR_ALEN,
133
    pr_tr, pr_str, in_tr, NULL
134
};
135
 
136
 
137
#endif                          /* HAVE_HWTR */

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.