⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u_ethernetframe.pas

📁 linux program to read packet data
💻 PAS
字号:
(*
 * One Way Network Sniffer (OWNS)
 * Copyright (C) 2001-2002 OWNS
 *
 * http://owns.sourceforge.net/
 * http://www.owns.st
 *
 * This program 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; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *)

(*
 * $Id: u_EthernetFrame.pas,v 1.5 2002/11/02 14:05:37 owns Exp $
 * represents an ethernet frame
 *)

unit u_EthernetFrame;

interface

////////////////////////////////////////////////////////////////////////////////
//
// ethernet packet
//
////////////////////////////////////////////////////////////////////////////////

const
//rfc1340
PROTO_IP      =	$0800;
PROTO_ARP     =	$0806;
PROTO_XNS     =	$0600;
PROTO_SNMP    =	$814C;
PROTO_OLD_IPX =	$8137;
PROTO_NOVELL  =	$8138;
PROTO_IPNG    =	$86DD;

type
MAC_ADDR = array[0..5] of Byte;

ETHERNET_HDR = packed record
  Destination: MAC_ADDR;              // destination mac address
  Source:      MAC_ADDR;              // source mac address
  Protocol:    array[0..1] of Byte;   // protocol
  Data:        array[0..0] of Byte;   // data of the packet
end;
PETHERNET_HDR = ^ETHERNET_HDR;

 TEthernetFrame = class(TObject)
  private
    FEthernetHdr: PETHERNET_HDR;
    function getEthernetProtocol : Word;
    function getEthernetData : PChar;
  protected
  public
    constructor Create(uBuffer: PChar); virtual;
    destructor Destroy; override;

    property EthernetProtocol: Word read getEthernetProtocol;
    property EthernetHeader: PETHERNET_HDR read FEthernetHdr;
    property EthernetData: PChar read getEthernetData;
  end;

function TOUSHORT(x: PChar): Word;
function TOULONG(x: PChar): Cardinal;
implementation



function TOUSHORT(x: PChar): Word;
begin
    Result := (Word(x^) shl 8) or (Word((x + 1)^));
end;

function TOULONG(x: PChar): Cardinal;
begin
    Result := (Cardinal(x^) shl 24) or
              (Cardinal((x + 1)^) shl 16) or
              (Cardinal((x + 2)^) shl 8) or
              (Cardinal((x + 3)^));
end;

////////////////////////////////////////////////////////////////////////////////
//
// ethernet packet
//
////////////////////////////////////////////////////////////////////////////////

constructor TEthernetFrame.Create(uBuffer: PChar);
begin
  inherited Create;
  FEthernetHdr := PETHERNET_HDR(uBuffer);
end;

// renvoie le protocole utilis

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -