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

Subversion Repositories or1k_old

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/*
2
 * lib/hippi.c        This file contains an implementation of the "HIPPI"
3
 *              support functions for the NET-2 base distribution.
4
 *
5
 * Version:     $Id: hippi.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
 *              Modified for HIPPI by Jes Sorensen, <Jes.Sorensen@cern.ch>
11
 *
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.
17
 */
18
#include "config.h"
19
 
20
#if HAVE_HWHIPPI
21
#include <sys/types.h>
22
#include <sys/socket.h>
23
#include <net/if_arp.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
#include "util.h"
34
 
35
/*
36
 *    HIPPI magic constants.
37
 */
38
 
39
#define HIPPI_ALEN      6       /* Bytes in one HIPPI hw-addr        */
40
#ifndef ARPHRD_HIPPI
41
#define ARPHRD_HIPPI    780
42
#warning "ARPHRD_HIPPI is not defined in <net/if_arp.h>. Using private value 708"
43
#endif
44
 
45
extern struct hwtype hippi_hwtype;
46
 
47
 
48
/* Display an HIPPI address in readable format. */
49
static char *pr_hippi(unsigned char *ptr)
50
{
51
    static char buff[64];
52
 
53
    sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X",
54
            (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377),
55
            (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377)
56
        );
57
    return (buff);
58
}
59
 
60
 
61
/* Display an HIPPI socket address. */
62
static char *
63
 pr_shippi(struct sockaddr *sap)
64
{
65
    static char buf[64];
66
 
67
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
68
        return (safe_strncpy(buf, _("[NONE SET]"), 64));
69
    return (pr_hippi(sap->sa_data));
70
}
71
 
72
 
73
/* Input an HIPPI address and convert to binary. */
74
static int in_hippi(char *bufp, struct sockaddr *sap)
75
{
76
    unsigned char *ptr;
77
    char c, *orig;
78
    int i, val;
79
 
80
    sap->sa_family = hippi_hwtype.type;
81
    ptr = sap->sa_data;
82
 
83
    i = 0;
84
    orig = bufp;
85
    while ((*bufp != '\0') && (i < HIPPI_ALEN)) {
86
        val = 0;
87
        c = *bufp++;
88
        if (isdigit(c))
89
            val = c - '0';
90
        else if (c >= 'a' && c <= 'f')
91
            val = c - 'a' + 10;
92
        else if (c >= 'A' && c <= 'F')
93
            val = c - 'A' + 10;
94
        else {
95
#ifdef DEBUG
96
            fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig);
97
#endif
98
            errno = EINVAL;
99
            return (-1);
100
        }
101
        val <<= 4;
102
        c = *bufp++;
103
        if (isdigit(c))
104
            val |= c - '0';
105
        else if (c >= 'a' && c <= 'f')
106
            val |= c - 'a' + 10;
107
        else if (c >= 'A' && c <= 'F')
108
            val |= c - 'A' + 10;
109
        else {
110
#ifdef DEBUG
111
            fprintf(stderr, _("in_hippi(%s): invalid hippi address!\n"), orig);
112
#endif
113
            errno = EINVAL;
114
            return (-1);
115
        }
116
        *ptr++ = (unsigned char) (val & 0377);
117
        i++;
118
 
119
        /* We might get a semicolon here - not required. */
120
        if (*bufp == ':') {
121
            if (i == HIPPI_ALEN) {
122
#ifdef DEBUG
123
                fprintf(stderr, _("in_hippi(%s): trailing : ignored!\n"), orig)
124
#endif
125
                    ;           /* nothing */
126
            }
127
            bufp++;
128
        }
129
    }
130
 
131
    /* That's it.  Any trailing junk? */
132
    if ((i == HIPPI_ALEN) && (*bufp != '\0')) {
133
#ifdef DEBUG
134
        fprintf(stderr, _("in_hippi(%s): trailing junk!\n"), orig);
135
        errno = EINVAL;
136
        return (-1);
137
#endif
138
    }
139
#ifdef DEBUG
140
    fprintf(stderr, "in_hippi(%s): %s\n", orig, pr_hippi(sap->sa_data));
141
#endif
142
 
143
    return (0);
144
}
145
 
146
 
147
struct hwtype hippi_hwtype =
148
{
149
    "hippi", NULL, /*"HIPPI", */ ARPHRD_HIPPI, HIPPI_ALEN,
150
    pr_hippi, pr_shippi, in_hippi, NULL
151
};
152
 
153
 
154
#endif                          /* HAVE_HWHIPPI */

powered by: WebSVN 2.1.0

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