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 3 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, see <http://www.gnu.org/licenses/>. 17 * 18 * Written by Anthony Liguori <aliguori@us.ibm.com> 19\*/ 20 21#include <netinet/in.h> 22 23#include "smb.hpp" 24 25smb::smb(const uint8_t *data, size_t length) 26{ 27 if (length < 36) { 28 memset(magic, 0, 4); 29 return; 30 } 31 32 /* This code assumes Little Endian... Don't say I didn't warn you */ 33 memcpy(&size, data + 2, 2); 34 memcpy(magic, data + 4, 4); 35 36 command = data[8]; 37 38 memcpy(&nt_status, data + 9, 4); 39 40 flags = data[13]; 41 42 memcpy(&flags2, data + 14, 2); 43 memcpy(&pid_hi, data + 16, 2); 44 memcpy(signature, data + 18, 8); 45 memcpy(&reserved, data + 26, 2); 46 memcpy(&tid, data + 28, 2); 47 memcpy(&pid, data + 30, 2); 48 memcpy(&uid, data + 32, 2); 49 memcpy(&mid, data + 34, 2); 50} 51 52std::ostream &operator<<(std::ostream &lhs, const smb &rhs) 53{ 54 lhs << "Magic: "; 55 for (int i = 1; i < 4; i++) { 56 lhs << rhs.magic[i]; 57 } 58 lhs << std::endl; 59 60 lhs << "Command: " << (uint16_t)rhs.command << std::endl 61 << "NT Status: " << rhs.nt_status << std::endl 62 << "Flags: " << (uint16_t)rhs.flags << std::endl 63 << "Flags2: " << rhs.flags2 << std::endl 64 << "Pid Hi: " << rhs.pid_hi << std::endl 65 << "Tid: " << rhs.tid << std::endl 66 << "Pid: " << rhs.pid << std::endl 67 << "Uid: " << rhs.uid << std::endl 68 << "Mid: " << rhs.mid << std::endl; 69 70 return lhs; 71} 72