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 /* $Id: eth.c,v 0.8.4.2 1992/11/10 10:38:48 bir7 Exp $ */
  23 /* $Log: eth.c,v $
  24  * Revision 0.8.4.2  1992/11/10  10:38:48  bir7
  25  * Change free_s to kfree_s and accidently changed free_skb to kfree_skb.
  26  *
  27  * Revision 0.8.4.1  1992/11/10  00:17:18  bir7
  28  * version change only.
  29  *
  30  * Revision 0.8.3.2  1992/11/10  00:14:47  bir7
  31  * Changed malloc to kmalloc and added $iId$ 
  32  *
  33  *
  34  */
  35 
  36 #include <asm/segment.h>
  37 #include <asm/system.h>
  38 #include <linux/types.h>
  39 #include <linux/kernel.h>
  40 #include <linux/sched.h>
  41 #include <linux/string.h>
  42 #include <linux/mm.h>
  43 #include <linux/socket.h>
  44 #include <netinet/in.h>
  45 #include "dev.h"
  46 #include "eth.h"
  47 #include "timer.h"
  48 #include "ip.h"
  49 #include "tcp.h"
  50 #include "sock.h"
  51 #include <linux/errno.h>
  52 #include "arp.h"
  53 
  54 #undef ETH_DEBUG
  55 #ifdef ETH_DEBUG
  56 #define PRINTK printk
  57 #else
  58 #define PRINTK dummy_routine
  59 #endif
  60 
  61 void
  62 print_eth (struct enet_header *eth)
     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64   int i;
  65   PRINTK ("ether source addr: ");
  66   for (i =0 ; i < ETHER_ADDR_LEN; i++)
  67     {
  68       PRINTK ("0x%2X ",eth->saddr[i]);
  69     }
  70   PRINTK ("\n");
  71 
  72   PRINTK ("ether dest addr: ");
  73   for (i =0 ; i < ETHER_ADDR_LEN; i++)
  74     {
  75       PRINTK ("0x%2X ",eth->daddr[i]);
  76     }
  77   PRINTK ("\n");
  78   PRINTK ("ethertype = %X\n",net16(eth->type));
  79 }
  80 
  81 int
  82 eth_hard_header (unsigned char *buff, struct device *dev,
     /* [previous][next][first][last][top][bottom][index][help] */
  83                  unsigned short type, unsigned long daddr,
  84                  unsigned long saddr, unsigned len)
  85 {
  86   struct enet_header *eth;
  87   eth = (struct enet_header *)buff;
  88   eth->type = net16(type);
  89   memcpy (eth->saddr, dev->dev_addr, dev->addr_len);
  90   if (daddr == 0)
  91     {
  92       memset (eth->daddr, 0xff, dev->addr_len);
  93       return (14);
  94     }
  95   if (!arp_find (eth->daddr, daddr, dev, saddr))
  96     {
  97       return (14);
  98     }
  99   else
 100     {
 101       *(unsigned long *)eth->saddr = saddr;
 102        return (-14);
 103     }
 104 }
 105 
 106 int
 107 eth_rebuild_header (void *buff, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 108 {
 109   struct enet_header *eth;
 110   eth = buff;
 111   if (arp_find(eth->daddr, *(unsigned long*)eth->daddr, dev, 
 112                    *(unsigned long *)eth->saddr))
 113     return (1);
 114   memcpy (eth->saddr, dev->dev_addr, dev->addr_len);
 115   return (0);
 116 }
 117 
 118 void
 119 eth_add_arp (unsigned long addr, struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 120 {
 121    struct enet_header *eh;
 122    eh = (struct enet_header *)(skb + 1);
 123    arp_add (addr, eh->saddr, dev);
 124 }
 125 
 126 unsigned short
 127 eth_type_trans (struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 {
 129    struct enet_header *eh;
 130    eh = (struct enet_header *)(skb + 1);
 131    return (eh->type);
 132 }

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