summaryrefslogtreecommitdiff
path: root/src/protocols/netbios/netbios.h
blob: c3f40f7e8ce199b88e54b5f3a0f7031a8f1096e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//------------------------------------------------------------------------------
// Author: Andrey Kuznetsov
// Description: Helpers for parsing NetBIOS structures.
// Copyright (c) 2014 EPAM Systems
//------------------------------------------------------------------------------
/*
    This file is part of Nfstrace.

    Nfstrace is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 2 of the License.

    Nfstrace is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Nfstrace.  If not, see <http://www.gnu.org/licenses/>.
*/
//------------------------------------------------------------------------------
#ifndef NETBIOS_HEADER_H
#define NETBIOS_HEADER_H
//------------------------------------------------------------------------------
#include <cstdint>
#include <cstdlib>
//------------------------------------------------------------------------------
namespace NST
{
namespace protocols
{
namespace NetBIOS
{
/*! \class NetBIOS message header in SMB-direct case
 */
struct RawMessageHeader
{
    uint8_t  _start; //!< In SMB direct always 0x00
    uint8_t  _;
    uint16_t length; //!< Packet length
} __attribute__((__packed__));

/*! \class NetBIOS message header wrapper
 */
struct MessageHeader : private RawMessageHeader
{
    int8_t start() const;
    size_t len() const;
};

/*! Check is data valid NetBIOS message's header and return header or nullptr
 * \param data - raw packet data
 * \return pointer to input data which is casted to header structure or nullptr (if it is not valid header)
 */
inline const struct MessageHeader* get_header(const uint8_t* data)
{
    const MessageHeader* header(reinterpret_cast<const MessageHeader*>(data));
    if(header->start() == 0x00)
    {
        return header;
    }
    return nullptr;
}

} // namespace NetBIOS
} // namespace protocols
} // namespace NST
//------------------------------------------------------------------------------
#endif // NETBIOS_HEADER_H
//------------------------------------------------------------------------------