Skip to content

Commit 650084a

Browse files
committed
examples: use flow access functions
To prevent direct access to the flow structure and be subject to changes in its size. Ticket: OISF#8632
1 parent b2069ec commit 650084a

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

examples/plugins/c-custom-loggers/custom-logger.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "output-packet.h"
2222
#include "output-flow.h"
2323
#include "output-tx.h"
24+
#include "flow-bindgen.h"
2425
#include "util-print.h"
2526
#include "output.h"
2627

@@ -53,26 +54,26 @@ static int CustomFlowLogger(ThreadVars *tv, void *thread_data, Flow *f)
5354
char src_ip[46] = { 0 }, dst_ip[46] = { 0 };
5455
Port sp, dp;
5556

56-
if ((f->flags & FLOW_DIR_REVERSED) == 0) {
57-
if (FLOW_IS_IPV4(f)) {
58-
PrintInet(AF_INET, (const void *)&(f->src.addr_data32[0]), src_ip, sizeof(src_ip));
59-
PrintInet(AF_INET, (const void *)&(f->dst.addr_data32[0]), dst_ip, sizeof(dst_ip));
60-
} else if (FLOW_IS_IPV6(f)) {
61-
PrintInet(AF_INET6, (const void *)&(f->src.address), src_ip, sizeof(src_ip));
62-
PrintInet(AF_INET6, (const void *)&(f->dst.address), dst_ip, sizeof(dst_ip));
57+
if ((SCFlowGetFlags(f) & FLOW_DIR_REVERSED) == 0) {
58+
if (SCFlowIsIPv4(f)) {
59+
PrintInet(AF_INET, SCFlowGetSourceAddress(f, AF_INET), src_ip, sizeof(src_ip));
60+
PrintInet(AF_INET, SCFlowGetDestinationAddress(f, AF_INET), dst_ip, sizeof(dst_ip));
61+
} else if (SCFlowIsIPv6(f)) {
62+
PrintInet(AF_INET6, SCFlowGetSourceAddress(f, AF_INET6), src_ip, sizeof(src_ip));
63+
PrintInet(AF_INET6, SCFlowGetDestinationAddress(f, AF_INET6), dst_ip, sizeof(dst_ip));
6364
}
64-
sp = f->sp;
65-
dp = f->dp;
65+
sp = SCFlowGetSourcePort(f);
66+
dp = SCFlowGetDestinationPort(f);
6667
} else {
67-
if (FLOW_IS_IPV4(f)) {
68-
PrintInet(AF_INET, (const void *)&(f->dst.addr_data32[0]), src_ip, sizeof(src_ip));
69-
PrintInet(AF_INET, (const void *)&(f->src.addr_data32[0]), dst_ip, sizeof(dst_ip));
70-
} else if (FLOW_IS_IPV6(f)) {
71-
PrintInet(AF_INET6, (const void *)&(f->dst.address), src_ip, sizeof(src_ip));
72-
PrintInet(AF_INET6, (const void *)&(f->src.address), dst_ip, sizeof(dst_ip));
68+
if (SCFlowIsIPv4(f)) {
69+
PrintInet(AF_INET, SCFlowGetDestinationAddress(f, AF_INET), src_ip, sizeof(src_ip));
70+
PrintInet(AF_INET, SCFlowGetSourceAddress(f, AF_INET), dst_ip, sizeof(dst_ip));
71+
} else if (SCFlowIsIPv6(f)) {
72+
PrintInet(AF_INET6, SCFlowGetDestinationAddress(f, AF_INET6), src_ip, sizeof(src_ip));
73+
PrintInet(AF_INET6, SCFlowGetSourceAddress(f, AF_INET6), dst_ip, sizeof(dst_ip));
7374
}
74-
sp = f->dp;
75-
dp = f->sp;
75+
sp = SCFlowGetDestinationPort(f);
76+
dp = SCFlowGetSourcePort(f);
7677
}
7778

7879
SCLogNotice("Flow: %s:%u -> %s:%u", src_ip, sp, dst_ip, dp);

0 commit comments

Comments
 (0)