Nut/OS  5.0.5
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 4473 2012-08-20 15:12:45Z 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 
00078 typedef struct ether_header ETHERHDR;
00079 
00084 struct __attribute__((packed)) ether_header {
00086     uint8_t  ether_dhost[ETHER_ADDR_LEN];
00088     uint8_t  ether_shost[ETHER_ADDR_LEN];
00090     uint16_t ether_type;
00091 };
00092 
00097 #define ETHERMTU    (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
00098 
00103 #define ETHERMIN    (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)
00104 
00105 #define ETHERTYPE_IP    0x0800  
00106 #define ETHERTYPE_ARP   0x0806  
00115 #define ETHER_IS_ZERO(ea) (((ea)[0] | (ea)[1] | (ea)[2] | (ea)[3] | (ea)[4] | (ea)[5]) == 0)
00116 
00124 #define ETHER_IS_BROADCAST(ea) (((ea)[0] & (ea)[1] & (ea)[2] & (ea)[3] & (ea)[4] & (ea)[5]) == 0xFF)
00125 
00135 #define ETHER_IS_MULTICAST(ea) ((ea)[0] & 1)
00136 
00146 #define ETHER_IS_UNICAST(ea) (!ETHER_IS_ZERO(ea) && !ETHER_IS_MULTICAST(ea))
00147 
00148 /* ASCII conversion function prototypes. */
00149 extern uint8_t *ether_aton(const char *str);
00150 extern char *ether_ntoa(const uint8_t *mac);
00151 
00162 typedef struct __attribute__((packed)) ether_arp {
00163     ARPHDR   ea_hdr;        
00164     uint8_t  arp_sha[6];    
00165     uint32_t arp_spa;       
00166     uint8_t  arp_tha[6];    
00167     uint32_t arp_tpa;       
00168 } ETHERARP;
00169 
00170 /* ARP function prototypes. */
00171 extern void NutArpInput(NUTDEVICE *dev, NETBUF *nb);
00172 extern NETBUF *NutArpAllocNetBuf(uint16_t type, uint32_t ip, uint8_t *mac);
00173 extern int NutArpOutput(NUTDEVICE *dev, NETBUF *nb);
00174 extern void NutArpCacheUpdate(NUTDEVICE *dev, uint32_t ip, uint8_t *ha);
00175 extern int NutArpCacheQuery(NUTDEVICE *dev, uint32_t ip, uint8_t *mac);
00176 
00177 #endif