lib/mdns/src/Packet.h
changeset 2289 10ad22c88dbb
child 2310a2bf097f3756
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/mdns/src/Packet.h	Thu Mar 26 01:25:34 2009 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/*
     1.5 +OLSR MDNS plugin.
     1.6 +Written by Saverio Proto <zioproto@gmail.com> and Claudio Pisa <clauz@ninux.org>.
     1.7 +
     1.8 +    This file is part of OLSR MDNS PLUGIN.
     1.9 +
    1.10 +    The OLSR MDNS PLUGIN is free software: you can redistribute it and/or modify
    1.11 +    it under the terms of the GNU General Public License as published by
    1.12 +    the Free Software Foundation, either version 3 of the License, or
    1.13 +    (at your option) any later version.
    1.14 +
    1.15 +    The OLSR MDNS PLUGIN is distributed in the hope that it will be useful,
    1.16 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.18 +    GNU General Public License for more details.
    1.19 +
    1.20 +    You should have received a copy of the GNU General Public License
    1.21 +    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
    1.22 +
    1.23 +
    1.24 + */
    1.25 +
    1.26 +
    1.27 +#ifndef _MDNS_PACKET_H
    1.28 +#define _MDNS_PACKET_H
    1.29 +
    1.30 +
    1.31 +/* System includes */
    1.32 +#include <net/if.h> /* IFNAMSIZ, IFHWADDRLEN */
    1.33 +#include <sys/types.h> /* u_int8_t, u_int16_t */
    1.34 +
    1.35 +/* BMF-encapsulated packets are Ethernet-IP-UDP packets, which start
    1.36 + * with a 8-bytes BMF header (struct TEncapHeader), followed by the
    1.37 + * encapsulated Ethernet-IP packet itself */
    1.38 +
    1.39 +struct TEncapHeader
    1.40 +{
    1.41 +  /* Use a standard Type-Length-Value (TLV) element */
    1.42 +  u_int8_t type;
    1.43 +  u_int8_t len;
    1.44 +  u_int16_t reserved; /* Always 0 */
    1.45 +  u_int32_t crc32;
    1.46 +} __attribute__((__packed__));
    1.47 +
    1.48 +#define ENCAP_HDR_LEN ((int)sizeof(struct TEncapHeader))
    1.49 +#define BMF_ENCAP_TYPE 1
    1.50 +#define BMF_ENCAP_LEN 6
    1.51 +
    1.52 +struct TSaveTtl
    1.53 +{
    1.54 +  u_int8_t ttl;
    1.55 +  u_int16_t check;
    1.56 +} __attribute__((__packed__));
    1.57 +
    1.58 +int IsIpFragment(unsigned char* ipPacket);
    1.59 +u_int16_t GetIpTotalLength(unsigned char* ipPacket);
    1.60 +unsigned int GetIpHeaderLength(unsigned char* ipPacket);
    1.61 +u_int8_t GetTtl(unsigned char* ipPacket);
    1.62 +void SaveTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl);
    1.63 +void RestoreTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl);
    1.64 +void DecreaseTtlAndUpdateHeaderChecksum(unsigned char* ipPacket);
    1.65 +struct ip* GetIpHeader(unsigned char* encapsulationUdpData);
    1.66 +unsigned char* GetIpPacket(unsigned char* encapsulationUdpData);
    1.67 +
    1.68 +#endif /* _MDNS_PACKET_H */
    1.69 +