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

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