rust/snmp: fix libc deprecation warnings

pull/3998/head
Jeff Lucovsky 7 years ago committed by Victor Julien
parent 3f6624bf16
commit 643864a8f5

@ -22,7 +22,6 @@ use core;
use core::{AppProto,Flow,ALPROTO_UNKNOWN,ALPROTO_FAILED,STREAM_TOSERVER,STREAM_TOCLIENT}; use core::{AppProto,Flow,ALPROTO_UNKNOWN,ALPROTO_FAILED,STREAM_TOSERVER,STREAM_TOCLIENT};
use applayer; use applayer;
use parser::*; use parser::*;
use libc;
use std; use std;
use std::ffi::{CStr,CString}; use std::ffi::{CStr,CString};
use std::mem::transmute; use std::mem::transmute;
@ -300,7 +299,7 @@ impl Drop for SNMPTransaction {
/// Returns *mut SNMPState /// Returns *mut SNMPState
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_new() -> *mut libc::c_void { pub extern "C" fn rs_snmp_state_new() -> *mut std::os::raw::c_void {
let state = SNMPState::new(); let state = SNMPState::new();
let boxed = Box::new(state); let boxed = Box::new(state);
return unsafe{std::mem::transmute(boxed)}; return unsafe{std::mem::transmute(boxed)};
@ -309,7 +308,7 @@ pub extern "C" fn rs_snmp_state_new() -> *mut libc::c_void {
/// Params: /// Params:
/// - state: *mut SNMPState as void pointer /// - state: *mut SNMPState as void pointer
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_free(state: *mut libc::c_void) { pub extern "C" fn rs_snmp_state_free(state: *mut std::os::raw::c_void) {
// Just unbox... // Just unbox...
let mut snmp_state: Box<SNMPState> = unsafe{std::mem::transmute(state)}; let mut snmp_state: Box<SNMPState> = unsafe{std::mem::transmute(state)};
snmp_state.free(); snmp_state.free();
@ -317,11 +316,11 @@ pub extern "C" fn rs_snmp_state_free(state: *mut libc::c_void) {
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_parse_request(_flow: *const core::Flow, pub extern "C" fn rs_snmp_parse_request(_flow: *const core::Flow,
state: *mut libc::c_void, state: *mut std::os::raw::c_void,
_pstate: *mut libc::c_void, _pstate: *mut std::os::raw::c_void,
input: *const u8, input: *const u8,
input_len: u32, input_len: u32,
_data: *const libc::c_void, _data: *const std::os::raw::c_void,
_flags: u8) -> i32 { _flags: u8) -> i32 {
let buf = build_slice!(input,input_len as usize); let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,SNMPState); let state = cast_pointer!(state,SNMPState);
@ -330,11 +329,11 @@ pub extern "C" fn rs_snmp_parse_request(_flow: *const core::Flow,
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_parse_response(_flow: *const core::Flow, pub extern "C" fn rs_snmp_parse_response(_flow: *const core::Flow,
state: *mut libc::c_void, state: *mut std::os::raw::c_void,
_pstate: *mut libc::c_void, _pstate: *mut std::os::raw::c_void,
input: *const u8, input: *const u8,
input_len: u32, input_len: u32,
_data: *const libc::c_void, _data: *const std::os::raw::c_void,
_flags: u8) -> i32 { _flags: u8) -> i32 {
let buf = build_slice!(input,input_len as usize); let buf = build_slice!(input,input_len as usize);
let state = cast_pointer!(state,SNMPState); let state = cast_pointer!(state,SNMPState);
@ -342,9 +341,9 @@ pub extern "C" fn rs_snmp_parse_response(_flow: *const core::Flow,
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_get_tx(state: *mut libc::c_void, pub extern "C" fn rs_snmp_state_get_tx(state: *mut std::os::raw::c_void,
tx_id: u64) tx_id: u64)
-> *mut libc::c_void -> *mut std::os::raw::c_void
{ {
let state = cast_pointer!(state,SNMPState); let state = cast_pointer!(state,SNMPState);
match state.get_tx_by_id(tx_id) { match state.get_tx_by_id(tx_id) {
@ -354,7 +353,7 @@ pub extern "C" fn rs_snmp_state_get_tx(state: *mut libc::c_void,
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_get_tx_count(state: *mut libc::c_void) pub extern "C" fn rs_snmp_state_get_tx_count(state: *mut std::os::raw::c_void)
-> u64 -> u64
{ {
let state = cast_pointer!(state,SNMPState); let state = cast_pointer!(state,SNMPState);
@ -362,7 +361,7 @@ pub extern "C" fn rs_snmp_state_get_tx_count(state: *mut libc::c_void)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_tx_free(state: *mut libc::c_void, pub extern "C" fn rs_snmp_state_tx_free(state: *mut std::os::raw::c_void,
tx_id: u64) tx_id: u64)
{ {
let state = cast_pointer!(state,SNMPState); let state = cast_pointer!(state,SNMPState);
@ -372,15 +371,15 @@ pub extern "C" fn rs_snmp_state_tx_free(state: *mut libc::c_void,
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_progress_completion_status( pub extern "C" fn rs_snmp_state_progress_completion_status(
_direction: u8) _direction: u8)
-> libc::c_int -> std::os::raw::c_int
{ {
return 1; return 1;
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_tx_get_alstate_progress(_tx: *mut libc::c_void, pub extern "C" fn rs_snmp_tx_get_alstate_progress(_tx: *mut std::os::raw::c_void,
_direction: u8) _direction: u8)
-> libc::c_int -> std::os::raw::c_int
{ {
1 1
} }
@ -390,8 +389,8 @@ pub extern "C" fn rs_snmp_tx_get_alstate_progress(_tx: *mut libc::c_void,
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_tx_set_logged(_state: *mut libc::c_void, pub extern "C" fn rs_snmp_tx_set_logged(_state: *mut std::os::raw::c_void,
tx: *mut libc::c_void, tx: *mut std::os::raw::c_void,
logged: u32) logged: u32)
{ {
let tx = cast_pointer!(tx,SNMPTransaction); let tx = cast_pointer!(tx,SNMPTransaction);
@ -399,8 +398,8 @@ pub extern "C" fn rs_snmp_tx_set_logged(_state: *mut libc::c_void,
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_tx_get_logged(_state: *mut libc::c_void, pub extern "C" fn rs_snmp_tx_get_logged(_state: *mut std::os::raw::c_void,
tx: *mut libc::c_void) tx: *mut std::os::raw::c_void)
-> u32 -> u32
{ {
let tx = cast_pointer!(tx,SNMPTransaction); let tx = cast_pointer!(tx,SNMPTransaction);
@ -410,8 +409,8 @@ pub extern "C" fn rs_snmp_tx_get_logged(_state: *mut libc::c_void,
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_set_tx_detect_state( pub extern "C" fn rs_snmp_state_set_tx_detect_state(
tx: *mut libc::c_void, tx: *mut std::os::raw::c_void,
de_state: &mut core::DetectEngineState) -> libc::c_int de_state: &mut core::DetectEngineState) -> std::os::raw::c_int
{ {
let tx = cast_pointer!(tx,SNMPTransaction); let tx = cast_pointer!(tx,SNMPTransaction);
tx.de_state = Some(de_state); tx.de_state = Some(de_state);
@ -420,7 +419,7 @@ pub extern "C" fn rs_snmp_state_set_tx_detect_state(
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_get_tx_detect_state( pub extern "C" fn rs_snmp_state_get_tx_detect_state(
tx: *mut libc::c_void) tx: *mut std::os::raw::c_void)
-> *mut core::DetectEngineState -> *mut core::DetectEngineState
{ {
let tx = cast_pointer!(tx,SNMPTransaction); let tx = cast_pointer!(tx,SNMPTransaction);
@ -432,22 +431,18 @@ pub extern "C" fn rs_snmp_state_get_tx_detect_state(
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_get_events(state: *mut libc::c_void, pub extern "C" fn rs_snmp_state_get_events(tx: *mut std::os::raw::c_void)
tx_id: u64) -> *mut core::AppLayerDecoderEvents
-> *mut core::AppLayerDecoderEvents
{ {
let state = cast_pointer!(state,SNMPState); let tx = cast_pointer!(tx, SNMPTransaction);
match state.get_tx_by_id(tx_id) { return tx.events;
Some(tx) => tx.events,
_ => std::ptr::null_mut(),
}
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_state_get_event_info(event_name: *const libc::c_char, pub extern "C" fn rs_snmp_state_get_event_info(event_name: *const std::os::raw::c_char,
event_id: *mut libc::c_int, event_id: *mut std::os::raw::c_int,
event_type: *mut core::AppLayerEventType) event_type: *mut core::AppLayerEventType)
-> libc::c_int -> std::os::raw::c_int
{ {
if event_name == std::ptr::null() { return -1; } if event_name == std::ptr::null() { return -1; }
let c_event_name: &CStr = unsafe { CStr::from_ptr(event_name) }; let c_event_name: &CStr = unsafe { CStr::from_ptr(event_name) };
@ -463,7 +458,7 @@ pub extern "C" fn rs_snmp_state_get_event_info(event_name: *const libc::c_char,
}; };
unsafe{ unsafe{
*event_type = core::APP_LAYER_EVENT_TYPE_TRANSACTION; *event_type = core::APP_LAYER_EVENT_TYPE_TRANSACTION;
*event_id = event as libc::c_int; *event_id = event as std::os::raw::c_int;
}; };
0 0
} }
@ -492,7 +487,7 @@ pub extern "C" fn rs_snmp_state_get_tx_iterator(
#[no_mangle] #[no_mangle]
pub extern "C" fn rs_snmp_get_tx_iterator(_ipproto: u8, pub extern "C" fn rs_snmp_get_tx_iterator(_ipproto: u8,
_alproto: AppProto, _alproto: AppProto,
alstate: *mut libc::c_void, alstate: *mut std::os::raw::c_void,
min_tx_id: u64, min_tx_id: u64,
_max_tx_id: u64, _max_tx_id: u64,
istate: &mut u64) -> applayer::AppLayerGetTxIterTuple istate: &mut u64) -> applayer::AppLayerGetTxIterTuple
@ -562,7 +557,7 @@ const PARSER_NAME : &'static [u8] = b"snmp\0";
pub unsafe extern "C" fn rs_register_snmp_parser() { pub unsafe extern "C" fn rs_register_snmp_parser() {
let default_port = CString::new("161").unwrap(); let default_port = CString::new("161").unwrap();
let mut parser = RustParser { let mut parser = RustParser {
name : PARSER_NAME.as_ptr() as *const libc::c_char, name : PARSER_NAME.as_ptr() as *const std::os::raw::c_char,
default_port : default_port.as_ptr(), default_port : default_port.as_ptr(),
ipproto : core::IPPROTO_UDP, ipproto : core::IPPROTO_UDP,
probe_ts : rs_snmp_probing_parser, probe_ts : rs_snmp_probing_parser,

Loading…
Cancel
Save