|
|
1.1 root 1: /* eth.c */
2: /*
3: Copyright (C) 1992 Ross Biro
4:
5: This program is free software; you can redistribute it and/or modify
6: it under the terms of the GNU General Public License as published by
7: the Free Software Foundation; either version 2, or (at your option)
8: any later version.
9:
10: This program is distributed in the hope that it will be useful,
11: but WITHOUT ANY WARRANTY; without even the implied warranty of
12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: GNU General Public License for more details.
14:
15: You should have received a copy of the GNU General Public License
16: along with this program; if not, write to the Free Software
17: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18:
19: The Author may be reached as [email protected] or
20: C/O Department of Mathematics; Stanford University; Stanford, CA 94305
21: */
22:
23: #include <asm/segment.h>
24: #include <asm/system.h>
25: #include <linux/types.h>
26: #include <linux/kernel.h>
27: #include <linux/sched.h>
28: #include <linux/string.h>
29: #include <linux/mm.h>
30: #include <linux/socket.h>
31: #include <netinet/in.h>
32: #include <asm/memory.h>
33: #include "dev.h"
34: #include "eth.h"
35: #include "timer.h"
36: #include "ip.h"
37: #include "tcp.h"
38: #include "sock.h"
39: #include <linux/errno.h>
40: #include "arp.h"
41:
42: #undef ETH_DEBUG
43: #ifdef ETH_DEBUG
44: #define PRINTK printk
45: #else
46: #define PRINTK dummy_routine
47: #endif
48:
49: void
50: print_eth (struct enet_header *eth)
51: {
52: int i;
53: PRINTK ("ether source addr: ");
54: for (i =0 ; i < ETHER_ADDR_LEN; i++)
55: {
56: PRINTK ("0x%2X ",eth->saddr[i]);
57: }
58: PRINTK ("\n");
59:
60: PRINTK ("ether dest addr: ");
61: for (i =0 ; i < ETHER_ADDR_LEN; i++)
62: {
63: PRINTK ("0x%2X ",eth->daddr[i]);
64: }
65: PRINTK ("\n");
66: PRINTK ("ethertype = %X\n",net16(eth->type));
67: }
68:
69: int
70: eth_hard_header (unsigned char *buff, struct device *dev,
71: unsigned short type, unsigned long daddr,
72: unsigned long saddr, unsigned len)
73: {
74: struct enet_header *eth;
75: eth = (struct enet_header *)buff;
76: eth->type = net16(type);
77: memcpy (eth->saddr, dev->dev_addr, dev->addr_len);
78: if (daddr == 0)
79: {
80: memset (eth->daddr, 0xff, dev->addr_len);
81: return (14);
82: }
83: if (!arp_find (eth->daddr, daddr, dev, saddr))
84: {
85: return (14);
86: }
87: else
88: {
89: *(unsigned long *)eth->saddr = saddr;
90: return (-14);
91: }
92: }
93:
94: int
95: eth_rebuild_header (void *buff, struct device *dev)
96: {
97: struct enet_header *eth;
98: eth = buff;
99: if (arp_find(eth->daddr, *(unsigned long*)eth->daddr, dev,
100: *(unsigned long *)eth->saddr))
101: return (1);
102: memcpy (eth->saddr, dev->dev_addr, dev->addr_len);
103: return (0);
104: }
105:
106: void
107: eth_add_arp (unsigned long addr, struct sk_buff *skb, struct device *dev)
108: {
109: struct enet_header *eh;
110: eh = (struct enet_header *)(skb + 1);
111: arp_add (addr, eh->saddr, dev);
112: }
113:
114: unsigned short
115: eth_type_trans (struct sk_buff *skb, struct device *dev)
116: {
117: struct enet_header *eh;
118: eh = (struct enet_header *)(skb + 1);
119: return (eh->type);
120: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.