This source file includes following definitions.
- eth_print
- eth_dump
- eth_header
- eth_rebuild_header
- eth_add_arp
- eth_type_trans
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <asm/segment.h>
20 #include <asm/system.h>
21 #include <linux/types.h>
22 #include <linux/kernel.h>
23 #include <linux/sched.h>
24 #include <linux/string.h>
25 #include <linux/mm.h>
26 #include <linux/socket.h>
27 #include <linux/in.h>
28 #include "inet.h"
29 #include "dev.h"
30 #include "eth.h"
31 #include "timer.h"
32 #include "ip.h"
33 #include "route.h"
34 #include "protocol.h"
35 #include "tcp.h"
36 #include "skbuff.h"
37 #include "sock.h"
38 #include <linux/errno.h>
39 #include "arp.h"
40
41
42
43 char *eth_print(unsigned char *ptr)
44 {
45 static char buff[64];
46
47 if (ptr == NULL) return("[NONE]");
48 sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X",
49 (ptr[0] & 255), (ptr[1] & 255), (ptr[2] & 255),
50 (ptr[3] & 255), (ptr[4] & 255), (ptr[5] & 255)
51 );
52 return(buff);
53 }
54
55
56
57 void
58 eth_dump(struct ethhdr *eth)
59 {
60 if (inet_debug != DBG_ETH) return;
61
62 printk("eth: SRC = %s ", eth_print(eth->h_source));
63 printk("DST = %s ", eth_print(eth->h_dest));
64 printk("TYPE = %04X\n", ntohs(eth->h_proto));
65 }
66
67
68
69 int
70 eth_header(unsigned char *buff, struct device *dev, unsigned short type,
71 unsigned long daddr, unsigned long saddr, unsigned len)
72 {
73 struct ethhdr *eth;
74
75 DPRINTF((DBG_DEV, "ETH: header(%s, ", in_ntoa(saddr)));
76 DPRINTF((DBG_DEV, "%s, 0x%X)\n", in_ntoa(daddr), type));
77
78
79 eth = (struct ethhdr *) buff;
80 eth->h_proto = ntohs(type);
81 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
82
83
84 if (dev->flags & IFF_LOOPBACK) {
85 DPRINTF((DBG_DEV, "ETH: No header for loopback\n"));
86 memset(eth->h_dest, 0, dev->addr_len);
87 return(dev->hard_header_len);
88 }
89
90
91 if (chk_addr(daddr) == IS_BROADCAST) {
92 DPRINTF((DBG_DEV, "ETH: Using MAC Broadcast\n"));
93 memcpy(eth->h_dest, dev->broadcast, dev->addr_len);
94 return(dev->hard_header_len);
95 }
96
97
98 if (arp_find(eth->h_dest, daddr, dev, saddr)) {
99 return(-dev->hard_header_len);
100 } else return(dev->hard_header_len);
101 }
102
103
104
105 int
106 eth_rebuild_header(void *buff, struct device *dev)
107 {
108 struct ethhdr *eth;
109 unsigned long src, dst;
110
111 DPRINTF((DBG_DEV, "ETH: Using MAC Broadcast\n"));
112 eth = buff;
113 src = *(unsigned long *) eth->h_source;
114 dst = *(unsigned long *) eth->h_dest;
115 DPRINTF((DBG_DEV, "ETH: RebuildHeader: SRC=%s ", in_ntoa(src)));
116 DPRINTF((DBG_DEV, "DST=%s\n", in_ntoa(dst)));
117 if (arp_find(eth->h_dest, dst, dev, src)) return(1);
118 memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
119 return(0);
120 }
121
122
123
124 void
125 eth_add_arp(unsigned long addr, struct sk_buff *skb, struct device *dev)
126 {
127 struct ethhdr *eth;
128
129 eth = (struct ethhdr *) (skb + 1);
130 arp_add(addr, eth->h_source, dev);
131 }
132
133
134
135 unsigned short
136 eth_type_trans(struct sk_buff *skb, struct device *dev)
137 {
138 struct ethhdr *eth;
139
140 eth = (struct ethhdr *) (skb + 1);
141 return(eth->h_proto);
142 }