I. Source of libnids Problems
Using Libnids-win32 1.19 In vc6.0 environment programming to get data packets, most of the Code is according to the network security development kit detailed description of the Code for example. However, a connection error occurs during compilation, or libnids cannot catch the package after running. Check the program framework first:
Bytes ------------------------------------------------------------------------------------------------------------
# Include "NIDs. H"
# Include <stdio. h>
// Read and analyze the obtained ASCII string content
Char * char_to_ascii (char ch)
{
... // Function Code
}
// Callback function, analyze the TCP connection and TCP connection status, and analyze the data transmitted over TCP
Void tcp_protocol_callback (struct tcp_stream * tcp_connection, void ** Arg)
{
...... // Callback function code
}
// Main Function
Void main ()
{
Nids_params.device = "2 ";
If (! Nids_init ())
{
Printf ("error: % s \ n", nids_errbuf );
Exit (1 );
}
Nids_register_tcp (tcp_protocol_callback );
Nids_run ();
}
Bytes -------------------------------------------------------------------------------------------------------------
Ii. libnids compilation connection problems
The header files and library packages of libnids and Winpcap have been included in the vc6.0 environment, but the following similar problems still occur, which is tricky.
Linking...
Error lnk2001: unresolved external symbol "Void _ cdecl nids_run (void )"(? Nids_run @ yaxxz)
Error lnk2001: unresolved external symbol "Void _ cdecl nids_register_tcp (void *)"(? Nids_register_tcp @ yaxpax @ Z)
Error lnk2001: unresolved external symbol "char * nids_errbuf "(? Nids_errbuf @ 3 PADA)
Error lnk2001: unresolved external symbol "int _ cdecl nids_init (void )"(? Nids_init @ yahxz)
Debug/test.exe: Fatal error lnk1120: 4 unresolved externals
The solution is as follows:
Under the Libnids-1.19 folder, there is a WIN32-Includes folder that stores the header file of libnids and finds NIDs. h header file, open it, find int nids_init (); line, add the following code before this line:
# Ifdef _ cplusplus
Extern "C "{
# Endif
Add the following code to the last line of the header file:
# Ifdef _ cplusplus
}
# Endif
Save and compile. The compilation can be run.
3. libnids cannot catch the package
After running, data packets cannot be captured, but packets can be captured using other packet capture software, such as Wireshark.
This is because our computer has an adapter called adapter for generic dialup and VPN capture, which is a universal dial-up and virtual dedicated adapter. What we need to capture is not through its data packets, it is a package through the machine Nic. The packet cannot be captured because libnids selects "adapter for generic dialup and VPN capture" by default, So we add a code in the first line of the main () function: nids_params.device = "2"; set the adapter to a device that actually works. The modified main () function is as follows:
Void main ()
{
Nids_params.device = "2 ";
If (! Nids_init ())
{
Printf ("error: % s \ n", nids_errbuf );
Exit (1 );
}
Printf ("initialization successful! \ N ");
Nids_register_tcp (tcp_protocol_callback );
Nids_run ();
}
Compile and run the SDK.