/src/suricata8/rust/src/ntp/log.rs
Line | Count | Source |
1 | | /* Copyright (C) 2026 Open Information Security Foundation |
2 | | * |
3 | | * You can copy, redistribute or modify this Program under the terms of |
4 | | * the GNU General Public License version 2 as published by the Free |
5 | | * Software Foundation. |
6 | | * |
7 | | * This program is distributed in the hope that it will be useful, |
8 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
10 | | * GNU General Public License for more details. |
11 | | * |
12 | | * You should have received a copy of the GNU General Public License |
13 | | * version 2 along with this program; if not, write to the Free Software |
14 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
15 | | * 02110-1301, USA. |
16 | | */ |
17 | | |
18 | | use super::ntp::NTPTransaction; |
19 | | use crate::jsonbuilder::{JsonBuilder, JsonError}; |
20 | | |
21 | 0 | fn log(jb: &mut JsonBuilder, tx: &NTPTransaction) -> Result<(), JsonError> { |
22 | 0 | jb.open_object("ntp")?; |
23 | 0 | jb.set_uint("version", tx.version)?; |
24 | 0 | jb.set_uint("mode", tx.mode)?; |
25 | 0 | jb.set_uint("stratum", tx.stratum)?; |
26 | 0 | jb.set_string( |
27 | 0 | "reference_id", |
28 | 0 | &format!( |
29 | 0 | "{:02x}:{:02x}:{:02x}:{:02x}", |
30 | 0 | tx.reference_id[0], tx.reference_id[1], tx.reference_id[2], tx.reference_id[3] |
31 | 0 | ), |
32 | 0 | )?; |
33 | 0 | jb.close()?; |
34 | 0 | Ok(()) |
35 | 0 | } |
36 | | |
37 | 0 | pub(super) unsafe extern "C" fn ntp_log_json( |
38 | 0 | tx: *const std::os::raw::c_void, jb: *mut std::os::raw::c_void, |
39 | 0 | ) -> bool { |
40 | 0 | let tx = cast_pointer!(tx, NTPTransaction); |
41 | 0 | let jb = cast_pointer!(jb, JsonBuilder); |
42 | 0 | log(jb, tx).is_ok() |
43 | 0 | } |