lib/mdns/src/Packet.h
author Saverio Proto <zioproto@gmail.com>
Thu Mar 26 01:25:34 2009 +0100 (3 years ago)
changeset 2289 10ad22c88dbb
child 2310a2bf097f3756
permissions -rw-r--r--
Adding first version of the OLSR mdns plugin written by Saverio Proto and
Claudio Pisa (Ninux.org)
zioproto@2289
     1
/*
zioproto@2289
     2
OLSR MDNS plugin.
zioproto@2289
     3
Written by Saverio Proto <zioproto@gmail.com> and Claudio Pisa <clauz@ninux.org>.
zioproto@2289
     4
zioproto@2289
     5
    This file is part of OLSR MDNS PLUGIN.
zioproto@2289
     6
zioproto@2289
     7
    The OLSR MDNS PLUGIN is free software: you can redistribute it and/or modify
zioproto@2289
     8
    it under the terms of the GNU General Public License as published by
zioproto@2289
     9
    the Free Software Foundation, either version 3 of the License, or
zioproto@2289
    10
    (at your option) any later version.
zioproto@2289
    11
zioproto@2289
    12
    The OLSR MDNS PLUGIN is distributed in the hope that it will be useful,
zioproto@2289
    13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
zioproto@2289
    14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
zioproto@2289
    15
    GNU General Public License for more details.
zioproto@2289
    16
zioproto@2289
    17
    You should have received a copy of the GNU General Public License
zioproto@2289
    18
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
zioproto@2289
    19
zioproto@2289
    20
zioproto@2289
    21
 */
zioproto@2289
    22
zioproto@2289
    23
zioproto@2289
    24
#ifndef _MDNS_PACKET_H
zioproto@2289
    25
#define _MDNS_PACKET_H
zioproto@2289
    26
zioproto@2289
    27
zioproto@2289
    28
/* System includes */
zioproto@2289
    29
#include <net/if.h> /* IFNAMSIZ, IFHWADDRLEN */
zioproto@2289
    30
#include <sys/types.h> /* u_int8_t, u_int16_t */
zioproto@2289
    31
zioproto@2289
    32
/* BMF-encapsulated packets are Ethernet-IP-UDP packets, which start
zioproto@2289
    33
 * with a 8-bytes BMF header (struct TEncapHeader), followed by the
zioproto@2289
    34
 * encapsulated Ethernet-IP packet itself */
zioproto@2289
    35
zioproto@2289
    36
struct TEncapHeader
zioproto@2289
    37
{
zioproto@2289
    38
  /* Use a standard Type-Length-Value (TLV) element */
zioproto@2289
    39
  u_int8_t type;
zioproto@2289
    40
  u_int8_t len;
zioproto@2289
    41
  u_int16_t reserved; /* Always 0 */
zioproto@2289
    42
  u_int32_t crc32;
zioproto@2289
    43
} __attribute__((__packed__));
zioproto@2289
    44
zioproto@2289
    45
#define ENCAP_HDR_LEN ((int)sizeof(struct TEncapHeader))
zioproto@2289
    46
#define BMF_ENCAP_TYPE 1
zioproto@2289
    47
#define BMF_ENCAP_LEN 6
zioproto@2289
    48
zioproto@2289
    49
struct TSaveTtl
zioproto@2289
    50
{
zioproto@2289
    51
  u_int8_t ttl;
zioproto@2289
    52
  u_int16_t check;
zioproto@2289
    53
} __attribute__((__packed__));
zioproto@2289
    54
zioproto@2289
    55
int IsIpFragment(unsigned char* ipPacket);
zioproto@2289
    56
u_int16_t GetIpTotalLength(unsigned char* ipPacket);
zioproto@2289
    57
unsigned int GetIpHeaderLength(unsigned char* ipPacket);
zioproto@2289
    58
u_int8_t GetTtl(unsigned char* ipPacket);
zioproto@2289
    59
void SaveTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl);
zioproto@2289
    60
void RestoreTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl);
zioproto@2289
    61
void DecreaseTtlAndUpdateHeaderChecksum(unsigned char* ipPacket);
zioproto@2289
    62
struct ip* GetIpHeader(unsigned char* encapsulationUdpData);
zioproto@2289
    63
unsigned char* GetIpPacket(unsigned char* encapsulationUdpData);
zioproto@2289
    64
zioproto@2289
    65
#endif /* _MDNS_PACKET_H */
zioproto@2289
    66