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