Nut/OS  4.10.3
API Reference
if_ether.h
Go to the documentation of this file.
00001 #ifndef _NETINET_IF_ETHER_H_
00002 #define _NETINET_IF_ETHER_H_
00003 
00004 /*
00005  * Copyright (C) 2008 by egnite GmbH.
00006  * Copyright (C) 2001-2003 by egnite Software GmbH.
00007  * Copyright (c) 1983, 1993 by The Regents of the University of California.
00008  *
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions
00013  * are met:
00014  *
00015  * 1. Redistributions of source code must retain the above copyright
00016  *    notice, this list of conditions and the following disclaimer.
00017  * 2. Redistributions in binary form must reproduce the above copyright
00018  *    notice, this list of conditions and the following disclaimer in the
00019  *    documentation and/or other materials provided with the distribution.
00020  * 3. Neither the name of the copyright holders nor the names of
00021  *    contributors may be used to endorse or promote products derived
00022  *    from this software without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00031  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00032  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00034  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00035  * SUCH DAMAGE.
00036  *
00037  * For additional information see http://www.ethernut.de/
00038  */
00039 
00040 /*
00041  * $Id: if_ether.h 2238 2008-08-11 17:38:27Z haraldkipp $
00042  */
00043 
00044 #include <net/if_var.h>
00045 #include <net/if_arp.h>
00046 
00053 #define ETHER_ADDR_LEN      6
00054 
00056 #define ETHER_TYPE_LEN      2
00057 
00059 #define ETHER_CRC_LEN       4
00060 
00062 #define ETHER_HDR_LEN       (ETHER_ADDR_LEN + ETHER_ADDR_LEN + ETHER_TYPE_LEN)
00063 
00064 #ifndef ETHER_MIN_LEN
00065 
00066 #define ETHER_MIN_LEN       64
00067 #endif
00068 
00069 #ifndef ETHER_MAX_LEN
00070 
00071 #define ETHER_MAX_LEN       1518
00072 #endif
00073 
00082 typedef struct __attribute__((packed)) ether_header {
00084     uint8_t  ether_dhost[ETHER_ADDR_LEN];
00086     uint8_t  ether_shost[ETHER_ADDR_LEN];
00088     uint16_t ether_type;
00089 } ETHERHDR;
00090 
00095 #define ETHERMTU    (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
00096 
00101 #define ETHERMIN    (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
00102 
00103 #define ETHERTYPE_IP    0x0800  
00104 #define ETHERTYPE_ARP   0x0806  
00113 #define ETHER_IS_ZERO(ea) (((ea)[0] | (ea)[1] | (ea)[2] | (ea)[3] | (ea)[4] | (ea)[5]) == 0)
00114 
00122 #define ETHER_IS_BROADCAST(ea) (((ea)[0] & (ea)[1] & (ea)[2] & (ea)[3] & (ea)[4] & (ea)[5]) == 0xFF)
00123 
00133 #define ETHER_IS_MULTICAST(ea) ((ea)[0] & 1) 
00134 
00144 #define ETHER_IS_UNICAST(ea) (!ETHER_IS_ZERO(ea) && !ETHER_IS_MULTICAST(ea)) 
00145 
00146 __BEGIN_DECLS
00147 /* ASCII conversion function prototypes. */
00148 extern uint8_t *ether_aton(CONST char *str);
00149 extern char *ether_ntoa(CONST uint8_t *mac);
00150 
00151 __END_DECLS
00152 
00163 typedef struct __attribute__((packed)) ether_arp {
00164     ARPHDR   ea_hdr;        
00165     uint8_t  arp_sha[6];    
00166     uint32_t arp_spa;       
00167     uint8_t  arp_tha[6];    
00168     uint32_t arp_tpa;       
00169 } ETHERARP;
00170 
00171 __BEGIN_DECLS
00172 /* ARP function prototypes. */
00173 extern void NutArpInput(NUTDEVICE *dev, NETBUF *nb);
00174 extern NETBUF *NutArpAllocNetBuf(uint16_t type, uint32_t ip, uint8_t *mac);
00175 extern int NutArpOutput(NUTDEVICE *dev, NETBUF *nb);
00176 extern void NutArpCacheUpdate(NUTDEVICE *dev, uint32_t ip, uint8_t *ha);
00177 extern int NutArpCacheQuery(NUTDEVICE *dev, uint32_t ip, uint8_t *mac);
00178 
00179 __END_DECLS
00180 /* */
00181 
00182 #endif