我正在尝试编译洋红色包捕获单位到64位。
https://www.magsys.co.uk/delphi/magmonsock.asp
当我编译时,我得到的可怕的左边不能在下面的代码行上被分配
LongWord(bp) := LongWord(bp) + BPF_WORDALIGN(caplen + hdrlen);
这是因为
LongWord
在64中强制转换的字节长度不同,对吗?有谁能帮我把这行代码修好,让它在32位和64位版本中编译得很好吗?
bp
声明为指针。
caplen
和
hdrlen
被声明为整数。
这个
BPF_WORDALIGN
功能是
function BPF_WORDALIGN(X:LongWord) : LongWord;
begin
result := (((X)+(BPF_ALIGNMENT-1))and not(BPF_ALIGNMENT-1));
end;
谢谢你的帮忙。
如果有帮助的话,这里是故障线路的完整程序;
function pcap_read( p:PPcap;cnt:integer;CallBack:Tpcap_handler;User:pointer)
: integer;
var cc : Longword;//Counter ?
n : integer;
bp,ep: pointer; //Begin and End Point ?
//bhp : Pbpf_hdr;//pointer to BPF header struct - removed by Lars Peter
hdrlen, //Length of Header
caplen: integer;//Length of captured
begin
if NOT LoadPacketDll then
begin
p.errbuf := 'Cannot load packet.dll';
result:=-1;
exit;
end;
cc := p.cc;
n := 0;
if p.cc = 0 then
begin
// *Capture the Packets*
if PacketReceivePacket(p.adapter,p.packet,TRUE)=false then
begin
// ERROR!
p.errbuf :='Read Error: PacketRecievePacket failed';
result:=-1;
exit;
end;
cc := p.packet.ulBytesReceived;
bp := p.buffer;
end else bp := p.bp;
// Loop through each packet.
ep := ptr(longword(bp)+cc); //move end pointer
while (longword(bp) < longword(ep) ) do
begin
caplen := Pbpf_hdr(bp).bh_caplen;
hdrlen := Pbpf_hdr(bp).bh_hdrlen;
// XXX A bpf_hdr matches apcap_pkthdr.
callback(user,
Ppcap_pkthdr(bp),
ptr(longword(bp)+longword(HdrLen)));
LongWord(bp) := LongWord(bp) + BPF_WORDALIGN(caplen + hdrlen);
inc(n);
if (n >= cnt)and(cnt>0) then
begin
p.bp := bp;
p.cc := longword(ep)-longword(bp);
result := n;
exit;
end;
end;
p.cc := 0;
result:=n;
end;