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

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