-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patharcnet.c
118 lines (107 loc) · 2.31 KB
/
arcnet.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Stuff generic to all ARCnet controllers
* Copyright 1990 Russ Nelson
*/
#include <stdio.h>
#include "global.h"
#include "mbuf.h"
#include "iface.h"
#include "timer.h"
#include "arp.h"
#include "ip.h"
#include "arcnet.h"
uint8 ARC_bdcst[] = { 0 };
/* Convert ARCnet header in host form to network mbuf */
void
htonarc(
struct arc *arc,
struct mbuf **bpp
){
register uint8 *cp;
pushdown(bpp,NULL,ARCLEN);
cp = (*bpp)->data;
memcpy(cp,arc->source,AADDR_LEN);
cp += AADDR_LEN;
memcpy(cp,arc->dest,AADDR_LEN);
cp += AADDR_LEN;
*cp++ = arc->type;
}
/* Extract ARCnet header */
int
ntoharc(arc,bpp)
struct arc *arc;
struct mbuf **bpp;
{
pullup(bpp,arc->source,AADDR_LEN);
pullup(bpp,arc->dest,AADDR_LEN);
arc->type = PULLCHAR(bpp);
return ARCLEN;
}
/* Format an ARCnet address into a printable ascii string */
char *
parc(out,addr)
char *out;
uint8 *addr;
{
sprintf(out,"%02x", addr[0]);
return out;
}
/* Convert an ARCnet address from Hex/ASCII to binary */
int
garc(out,cp)
register uint8 *out;
register char *cp;
{
*out = htoi(cp);
return 0;
}
/* Send an IP datagram on ARCnet */
int
anet_send(
struct mbuf **bpp, /* Buffer to send */
struct iface *iface, /* Pointer to interface control block */
int32 gateway, /* IP address of next hop */
uint8 tos
){
uint8 *agate;
agate = res_arp(iface,ARP_ARCNET,gateway,bpp);
if(agate != NULL)
return (*iface->output)(iface,agate,iface->hwaddr,ARC_IP,bpp);
return 0;
}
/* Send a packet with ARCnet header */
int
anet_output(
struct iface *iface, /* Pointer to interface control block */
uint8 *dest, /* Destination ARCnet address */
uint8 *source, /* Source ARCnet address */
uint16 type, /* Type field */
struct mbuf **data /* Data field */
){
struct arc ap;
memcpy(ap.dest,dest,AADDR_LEN);
memcpy(ap.source,source,AADDR_LEN);
ap.type = type;
htonarc(&ap,data);
return (*iface->raw)(iface,data);
}
/* Process incoming ARCnet packets. Shared by all ARCnet drivers. */
void
aproc(
struct iface *iface,
struct mbuf **bpp
){
struct arc hdr;
/* Remove ARCnet header and kick packet upstairs */
ntoharc(&hdr,bpp);
switch(hdr.type){
case ARC_ARP:
arp_input(iface,bpp);
break;
case ARC_IP:
ip_route(iface,bpp,0);
break;
default:
free_p(bpp);
break;
}
}