can somebody tell me does my conversation from c to delphi is well:
c code
struct nfq_data {
/* packet_hdr - it HAVE to be the same as struct nfqnl_msg_packet_hdr */
struct {
uint32_t packet_id; /* unique ID of packet in queue in network order */
uint16_t hw_protocol; /* hw protocol in network order */
uint8_t hook; /* netfilter hook */
} packet_hdr;
/* packet_hw - it HAVE to be the same as struct nfqnl_msg_packet_hw */
struct {
uint16_t hw_addrlen; /* len of hw_addr in network order */
uint16_t _pad;
uint8_t hw_addr[8];
} packet_hw;
/* tm */
struct {
long sec;
long usec;
} tm;
uint32_t if_index; /* Unique iface id */
uint32_t verdict; /* Netfilter verdict value */
uint32_t mark; /* Mark value */
uint8_t if_name[IFNAMSIZE]; /* Name of incoming or outgoing iface */
uint32_t data_len; /* Length of packet */
uint8_t payload[0]; /* packet data */
};
where
typedef unsigned char uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
delphi
_packet_hdr = record
packet_id: Cardinal;
hw_protocol: Word;
hook: Byte;
end;
_packet_hw = record
hw_addrlen: Word;
_pad: Word;
hw_addr: array[0..7] of byte;
end;
_tm = record
sec: Int64;
usec: Int64;
end;
pnfq_data = ^nfq_data;
nfq_data = record
packet_hdr: _packet_hdr;
packet_hw: _packet_hw;
tm: _tm;
if_index: Cardinal;
verdict: Cardinal;
mark: Cardinal;
if_name: array[0..254] of Byte;
data_len: Cardinal;
payload: PChar; //TBytes;
end;
packet_hdr: _packet_hdr;
packet_hw: _packet_hw;
I am receiving well, but after those nothing well.
Thanks in advance
Bojan
Is that really a pointer(as in your delphi-code) or an inplace array of size 0 used to represent data coming after the header
And you should mark your records as
packed.I don’t think it makes a difference in your specific code, butit is good practice since the packing rules are easy to get wrong, might change and not everybody knows them.It probably makes a difference because packet_hdr is 7 bytes larges when packed, so the following packet_hw starts at offset 7 when packed, and probably at 8 when aligned.