Example of LIBNET (1)

zhaozj2021-02-16  85

libnet use the example (1) 2000-01-01 Baiyun Huang Safety Digest Author: small four Home Page: http: //www.isbase.com Date: 2000-07-24 20:10 Maybe the best help is the source code example, ready to use SYN-FLOOD as an example to use the Libnet. Also caught in the DOS tool, I will drill a few articles. There are a lot of benefits using libnet, considering compatibility, Libnet for NT / 2K has downloaded. First we introduce libnet_name_resolve () functions, as the name suggestions, which implements domain name resolution. Its function prototype is as follows: u_long libnet_name_resolve (u_char * hostname, u_short use_name); Hostname is the standard ASCIIZ string with NULL. It can be diced decimal IPv4 address, such as "192.168.8.30". Can be FQDN, such as "bbs.isbase.com". It can even be a general host name, as long as you are confident that the host name can be parallelly parsed by a domain name system (including / etc / hosts file). There are two macros in the header file /usr/include/libnet/libnet-macros.h corresponding to the value of use_name: #define libnet_dont_resolve 0 / * Correspondence points decimal IPv4 address * / # define libnet_resolve 1 / * correspondence host name * / Determine the HostName used by this value to use the point decimal IPv4 address (0) or the host name (1). Regardless of the word sequence of this machine, the last obtained U_LONG is a BIG-Endian order (also network word sequence) 4-byte value, such as 192.168.8.30 corresponds to 0xc0 A8 08 1E. The domain name parsing function of the modern UNIX operating system supports input "192.168.80" as a meticulum, so the second parameter of the function is generally specified as libnet_resolve.

-------------------------------------------------- ------------------------ / * Compile commands to relatively weird points, confirm that your system has libnet-config scripts * // * gcc -o3 o RT Resolvetest.c `libnet-config --defines --cflags`` libnet-config --libs` * / # include #include #include / * You must include this header file * / # Define Success 0 # Define Failure -1int main (int Argc, char * argv []) {u_long ipul = 0x01020304; / * Test * / u_char * ipuc; INT i; u_short method; if (argc! = 3) {fprintf (stderr, "% s / N ", argv [0]); exit (failure);} method = (u_short) Strtoul (Argv [2], NULL, 10); if ((Method! = 0) && (Method! = 1)) { / * The first parameter is libnet_err_fatal, which will cause exit * / libnet_error (libnet_err_fatal, "bad method:% s / n", argv [2]);} / * Return -1 here indicate an error, in fact I am not sure * / If ((iPul = libnet_name_resolve ((iPul = libnet_name_resolve) == -1) {/ * only displays the warning message * / libnet_rror (libnet_err_warning, "Bad ResolveObject :% S / N ", Argv [1]);}} ipuc = (u_char *) & ipul; i = 0; While (I <4) {fprintf (stderr,"% 02x ", IPUC [i]); i ; } fprintf (stderr, "/ n"); return (success);} / * end of main * / --- -------------------------------------------------- ---------------------- Pay attention to compilation using the source code of the libnet library to assist in libnet-config scripts: [SCZ @ / home / scz / src]> GCC -O3 -O RT Resolvetest.c `libnet-config --defines --cflags`` libnet-config --libs` [scz @ / home / scz / src]> ./rt Scz 0warning: Bad ResolveObject: SCZ < - Although there is a warning message, it has not terminated the process FF FF FF <- forward parsing failed, because 0, SCZ is not point 10 credit IPv4 address [SCZ @ / home / SCZ / SRC]> ./rt SCZ 1C0 A8 08 5A <- forward parsing success [SCZ @ / home / SCZ / SRC]>. /RT 192.168.8.30 0c0 A8 08 1E [SCZ @ / Home / SCZ / SRC]>

转载请注明原文地址:https://www.9cbs.com/read-16449.html

New Post(0)