Nut/OS  4.10.3
API Reference
ethin.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 by egnite GmbH.
00003  * Copyright (C) 2001-2003 by egnite Software GmbH.
00004  * Copyright (c) 1993 by Digital Equipment Corporation.
00005  * Copyright (c) 1983, 1993 by The Regents of the University of California.
00006  *
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  * 3. Neither the name of the copyright holders nor the names of
00019  *    contributors may be used to endorse or promote products derived
00020  *    from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00023  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00026  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00029  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00030  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00032  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  * For additional information see http://www.ethernut.de/
00036  *
00037  * -
00038  * Portions Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk>
00039  *
00040  * This file is distributed in the hope that it will be useful, but WITHOUT
00041  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00042  * FITNESS FOR A PARTICULAR PURPOSE.
00043  *
00044  * You can redistribute this file and/or modify it under the terms of the GNU
00045  * General Public License (GPL) as published by the Free Software Foundation;
00046  * either version 2 of the License, or (at your discretion) any later version.
00047  * See the accompanying file "copying-gpl.txt" for more details.
00048  *
00049  * As a special exception to the GPL, permission is granted for additional
00050  * uses of the text contained in this file.  See the accompanying file
00051  * "copying-liquorice.txt" for details.
00052  * -
00053  * Portions Copyright (c) 1983, 1993 by
00054  *  The Regents of the University of California.  All rights reserved.
00055  *
00056  * Redistribution and use in source and binary forms, with or without
00057  * modification, are permitted provided that the following conditions
00058  * are met:
00059  * 1. Redistributions of source code must retain the above copyright
00060  *    notice, this list of conditions and the following disclaimer.
00061  * 2. Redistributions in binary form must reproduce the above copyright
00062  *    notice, this list of conditions and the following disclaimer in the
00063  *    documentation and/or other materials provided with the distribution.
00064  * 3. Neither the name of the University nor the names of its contributors
00065  *    may be used to endorse or promote products derived from this software
00066  *    without specific prior written permission.
00067  *
00068  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00069  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00070  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00071  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00072  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00073  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00074  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00075  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00076  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00077  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00078  * SUCH DAMAGE.
00079  * -
00080  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
00081  *
00082  * Permission to use, copy, modify, and distribute this software for any
00083  * purpose with or without fee is hereby granted, provided that the above
00084  * copyright notice and this permission notice appear in all copies, and that
00085  * the name of Digital Equipment Corporation not be used in advertising or
00086  * publicity pertaining to distribution of the document or software without
00087  * specific, written prior permission.
00088  * 
00089  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
00090  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
00091  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
00092  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
00093  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
00094  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
00095  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00096  * SOFTWARE.
00097  */
00098 
00099 /*
00100  * $Log$
00101  * Revision 1.3  2008/08/11 17:38:27  haraldkipp
00102  * Added an Ethernet protocol demultiplexer.
00103  *
00104  * Revision 1.2  2005/04/08 15:20:50  olereinhardt
00105  * added <sys/types.h> (__APPLE__) and <netinet/in.h> (__linux__)
00106  * for htons and simmilar.
00107  *
00108  * Revision 1.1.1.1  2003/05/09 14:41:27  haraldkipp
00109  * Initial using 3.2.1
00110  *
00111  * Revision 1.12  2003/02/04 18:14:57  harald
00112  * Version 3 released
00113  *
00114  * Revision 1.11  2002/06/26 17:29:35  harald
00115  * First pre-release with 2.4 stack
00116  *
00117  */
00118 
00119 #include <sys/types.h>
00120 #include <netinet/if_ether.h>
00121 #include <netinet/ip.h>
00122 #include <netinet/in.h>
00123 #include <net/ether.h>
00124 
00129 
00135 int (*ether_demux) (NUTDEVICE *, NETBUF *);
00136 
00156 void NutEtherInput(NUTDEVICE * dev, NETBUF * nb)
00157 {
00158     ETHERHDR *eh;
00159 
00160     /*
00161      * Split the Ethernet frame.
00162      */
00163     eh = (ETHERHDR *) nb->nb_dl.vp;
00164     nb->nb_nw.vp = eh + 1;
00165     nb->nb_nw.sz = nb->nb_dl.sz - sizeof(ETHERHDR);
00166     nb->nb_dl.sz = sizeof(ETHERHDR);
00167 
00168     /* Route frame to the correct handler. Process registered handlers
00169     ** first, IP next and ARP last. */
00170     if (ether_demux == NULL || (*ether_demux) (dev, nb)) {
00171         switch (ntohs(eh->ether_type)) {
00172         case ETHERTYPE_IP:
00173             NutIpInput(dev, nb);
00174             break;
00175         case ETHERTYPE_ARP:
00176             NutArpInput(dev, nb);
00177             break;
00178         default:
00179             /* No handler found. Silently discard the frame. */
00180             NutNetBufFree(nb);
00181             break;
00182         }
00183     }
00184 }
00185