• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/samba-3.0.25b/examples/pcap2nbench/
1/*\
2 *  pcap2nbench - Converts libpcap network traces to nbench input
3 *  Copyright (C) 2004  Jim McDonough <jmcd@us.ibm.com>
4 *
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.
9 *
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.
14 *
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.
18 *
19 *  Written by Anthony Liguori <aliguori@us.ibm.com>
20\*/
21
22#include <netinet/in.h>
23
24#include "smb.hpp"
25
26smb::smb(const uint8_t *data, size_t length)
27{
28  if (length < 36) {
29    memset(magic, 0, 4);
30    return;
31  }
32
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);
36
37  command = data[8];
38
39  memcpy(&nt_status, data + 9, 4);
40
41  flags = data[13];
42
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);
51}
52
53std::ostream &operator<<(std::ostream &lhs, const smb &rhs)
54{
55  lhs << "Magic: ";
56  for (int i = 1; i < 4; i++) {
57    lhs << rhs.magic[i];
58  }
59  lhs << std::endl;
60
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;
70
71  return lhs;
72}
73