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

Subversion Repositories or1k_old

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/*
2
 * lib/ash.c  This file contains an implementation of the Ash
3
 *              support functions for the NET-2 base distribution.
4
 * $Id: ash.c,v 1.1 2002-03-17 19:58:53 simons Exp $
5
 */
6
 
7
#include "config.h"
8
 
9
#if HAVE_HWASH
10
 
11
#include <sys/types.h>
12
#include <sys/socket.h>
13
#include <net/if_arp.h>
14
#include <stdlib.h>
15
#include <stdio.h>
16
#include <errno.h>
17
#include <ctype.h>
18
#include <string.h>
19
#include <unistd.h>
20
#include "net-support.h"
21
#include "pathnames.h"
22
#include "intl.h"
23
#include "util.h"
24
 
25
#ifndef ARPHRD_ASH
26
#warning "No definition of ARPHRD_ASH in <net/if_arp.h>, using private value 517"
27
#define ARPHRD_ASH 517
28
#endif
29
 
30
#define ASH_ALEN                64
31
 
32
extern struct hwtype ash_hwtype;
33
 
34
/* Display an Ash address in readable format. */
35
static char *pr_ash(unsigned char *ptr)
36
{
37
    static char buff[128];
38
    char *p = buff;
39
    unsigned int i = 0;
40
 
41
    p[0] = '[';
42
    p++;
43
    while (ptr[i] != 0xc9 && ptr[i] != 0xff && (i < ASH_ALEN))
44
        sprintf(p++, "%1x", ptr[i++]);
45
    *(p++) = ']';
46
    *p = 0;
47
 
48
    return buff;
49
}
50
 
51
/* Display an Ash socket address. */
52
static char *pr_sash(struct sockaddr *sap)
53
{
54
    static char buf[64];
55
 
56
    if (sap->sa_family == 0xFFFF || sap->sa_family == 0)
57
        return safe_strncpy(buf, "[NONE SET]", 64);
58
    return pr_ash(sap->sa_data);
59
}
60
 
61
static unsigned char hamming[16] =
62
{
63
    0x15, 0x02, 0x49, 0x5e, 0x64, 0x73, 0x38, 0x2f,
64
    0xd0, 0xc7, 0x8c, 0x9b, 0xa1, 0xb6, 0xfd, 0xea
65
};
66
 
67
 
68
static int in_ash(char *bufp, struct sockaddr *sap)
69
{
70
    unsigned char *ptr;
71
    unsigned int i = 0;
72
 
73
    sap->sa_family = ash_hwtype.type;
74
    ptr = sap->sa_data;
75
 
76
    while (bufp && i < ASH_ALEN) {
77
        char *next;
78
        int hop = strtol(bufp, &next, 16);
79
        ptr[i++] = hamming[hop];
80
        switch (*next) {
81
        case ':':
82
            bufp = next + 1;
83
            break;
84
        case 0:
85
            bufp = NULL;
86
            break;
87
        default:
88
            fprintf(stderr, _("Malformed Ash address"));
89
            memset(ptr, 0xc9, ASH_ALEN);
90
            return -1;
91
        }
92
    }
93
 
94
    while (i < ASH_ALEN)
95
        ptr[i++] = 0xc9;
96
 
97
    return 0;
98
}
99
 
100
 
101
struct hwtype ash_hwtype =
102
{
103
    "ash", NULL, ARPHRD_ASH, ASH_ALEN,
104
    pr_ash, pr_sash, in_ash, NULL,
105
    1
106
};
107
 
108
#endif

powered by: WebSVN 2.1.0

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