2 * OLSR Basic Multicast Forwarding (BMF) plugin.
3 * Copyright (c) 2005, 2006, Thales Communications, Huizen, The Netherlands.
4 * Written by Erik Tromp.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Thales, BMF nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* $Id: Address.c,v 1.1 2006/05/03 08:59:04 kattemat Exp $ */
38 #include <assert.h> /* assert() */
41 #include "defs.h" /* COMP_IP */
44 #include "Bmf.h" /* BMF_ENCAP_PORT */
46 int IsMulticast(union olsr_ip_addr* ipAddress)
48 assert(ipAddress != NULL);
50 return (ntohl(ipAddress->v4) & 0xF0000000) == 0xE0000000;
53 int IsLocalBroadcast(union olsr_ip_addr* destIp, struct interface* ifFrom)
55 struct sockaddr_in* sin;
57 assert(destIp != NULL);
59 /* Protect ourselves against bogus input */
60 if (ifFrom == NULL) return 0;
62 /* Cast down to correct sockaddr subtype */
63 sin = (struct sockaddr_in*)&(ifFrom->int_broadaddr);
65 /* Just in case OLSR does not have int_broadaddr filled in for this
67 if (sin == NULL) return 0;
69 return COMP_IP(&(sin->sin_addr.s_addr), destIp);
72 int IsOlsrOrBmfPacket(unsigned char* buffer, ssize_t len)
76 assert(buffer != NULL);
78 /* Consider OLSR and BMF packets not to be local broadcast
79 * OLSR packets are UDP - port 698
80 * BMF packets are UDP - port 50505 */
82 memcpy(&port, buffer + 0x24, 2);
86 buffer[0x17] == 0x11 && /* UDP */
87 (port == OLSRPORT || port == BMF_ENCAP_PORT))