libnet use the example (1) 2000-01-01 Baiyun Huang Safety Digest Author: small four
-------------------------------------------------- ------------------------ / * 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]>