root/net/tcp/eth.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. print_eth
  2. eth_hard_header
  3. eth_rebuild_header
  4. eth_add_arp
  5. eth_type_trans

   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 bir7@leland.stanford.edu 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 "dev.h"
  33 #include "eth.h"
  34 #include "timer.h"
  35 #include "ip.h"
  36 #include "tcp.h"
  37 #include "sock.h"
  38 #include <linux/errno.h>
  39 #include "arp.h"
  40 
  41 #undef ETH_DEBUG
  42 #ifdef ETH_DEBUG
  43 #define PRINTK printk
  44 #else
  45 #define PRINTK dummy_routine
  46 #endif
  47 
  48 void
  49 print_eth (struct enet_header *eth)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51   int i;
  52   PRINTK ("ether source addr: ");
  53   for (i =0 ; i < ETHER_ADDR_LEN; i++)
  54     {
  55       PRINTK ("0x%2X ",eth->saddr[i]);
  56     }
  57   PRINTK ("\n");
  58 
  59   PRINTK ("ether dest addr: ");
  60   for (i =0 ; i < ETHER_ADDR_LEN; i++)
  61     {
  62       PRINTK ("0x%2X ",eth->daddr[i]);
  63     }
  64   PRINTK ("\n");
  65   PRINTK ("ethertype = %X\n",net16(eth->type));
  66 }
  67 
  68 int
  69 eth_hard_header (unsigned char *buff, struct device *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
  70                  unsigned short type, unsigned long daddr,
  71                  unsigned long saddr, unsigned len)
  72 {
  73   struct enet_header *eth;
  74   eth = (struct enet_header *)buff;
  75   eth->type = net16(type);
  76   memcpy (eth->saddr, dev->dev_addr, dev->addr_len);
  77   if (daddr == 0)
  78     {
  79       memset (eth->daddr, 0xff, dev->addr_len);
  80       return (14);
  81     }
  82   if (!arp_find (eth->daddr, daddr, dev, saddr))
  83     {
  84       return (14);
  85     }
  86   else
  87     {
  88       *(unsigned long *)eth->saddr = saddr;
  89        return (-14);
  90     }
  91 }
  92 
  93 int
  94 eth_rebuild_header (void *buff, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96   struct enet_header *eth;
  97   eth = buff;
  98   if (arp_find(eth->daddr, *(unsigned long*)eth->daddr, dev, 
  99                    *(unsigned long *)eth->saddr))
 100     return (1);
 101   memcpy (eth->saddr, dev->dev_addr, dev->addr_len);
 102   return (0);
 103 }
 104 
 105 void
 106 eth_add_arp (unsigned long addr, struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 107 {
 108    struct enet_header *eh;
 109    eh = (struct enet_header *)(skb + 1);
 110    arp_add (addr, eh->saddr, dev);
 111 }
 112 
 113 unsigned short
 114 eth_type_trans (struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 115 {
 116    struct enet_header *eh;
 117    eh = (struct enet_header *)(skb + 1);
 118    return (eh->type);
 119 }

/* [previous][next][first][last][top][bottom][index][help] */