include updates
[tomato.git] / release / src-rt-6.x.4708 / router / samba-3.0.25b / examples / pcap2nbench / smb.cpp
blobdf3f84b4afa0b87d3b137eef6a7083cb575cdd1e
1 /*\
2 * pcap2nbench - Converts libpcap network traces to nbench input
3 * Copyright (C) 2004 Jim McDonough <jmcd@us.ibm.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * Written by Anthony Liguori <aliguori@us.ibm.com>
20 \*/
22 #include <netinet/in.h>
24 #include "smb.hpp"
26 smb::smb(const uint8_t *data, size_t length)
28 if (length < 36) {
29 memset(magic, 0, 4);
30 return;
33 /* This code assumes Little Endian... Don't say I didn't warn you */
34 memcpy(&size, data + 2, 2);
35 memcpy(magic, data + 4, 4);
37 command = data[8];
39 memcpy(&nt_status, data + 9, 4);
41 flags = data[13];
43 memcpy(&flags2, data + 14, 2);
44 memcpy(&pid_hi, data + 16, 2);
45 memcpy(signature, data + 18, 8);
46 memcpy(&reserved, data + 26, 2);
47 memcpy(&tid, data + 28, 2);
48 memcpy(&pid, data + 30, 2);
49 memcpy(&uid, data + 32, 2);
50 memcpy(&mid, data + 34, 2);
53 std::ostream &operator<<(std::ostream &lhs, const smb &rhs)
55 lhs << "Magic: ";
56 for (int i = 1; i < 4; i++) {
57 lhs << rhs.magic[i];
59 lhs << std::endl;
61 lhs << "Command: " << (uint16_t)rhs.command << std::endl
62 << "NT Status: " << rhs.nt_status << std::endl
63 << "Flags: " << (uint16_t)rhs.flags << std::endl
64 << "Flags2: " << rhs.flags2 << std::endl
65 << "Pid Hi: " << rhs.pid_hi << std::endl
66 << "Tid: " << rhs.tid << std::endl
67 << "Pid: " << rhs.pid << std::endl
68 << "Uid: " << rhs.uid << std::endl
69 << "Mid: " << rhs.mid << std::endl;
71 return lhs;