List of libnet functions

Source: Internet
Author: User

The interface functions provided by Libnet can be divided into four categories according to their function:
* Memory management (allocation and deallocation) functions
* Address resolution function
* Packet Constructors
* Packet sending function

these interface functions and their functions are listed below (their parameters are simple to understand and no longer explained):


Memory management functions

single packet Memory initialization:
int Libnet_init_packet (U_short packet_size, U_char **buf);

single packet Memory release:
void Libnet_destroy_packet (U_char **buf);

multi-Packet Memory initialization:
int Libnet_init_packet_arena (struct Libnet_arena **arena,u_short packet_num, U_short packet_size);

accessing the next packet in multi-packet memory:
U_char *libnet_next_packet_from_arena (struct Libnet_arena **arena,u_short packet_size);

multi-packet Memory release:
void Libnet_destroy_packet_arena (struct Libnet_arena **arena);


Address resolution functions

Resolve host name:
U_char *libnet_host_lookup (u_long IP, u_short use_name);

Resolve host name (reentrant function):
void Libnet_host_lookup_r (u_long IP, u_short use_name, U_char *buf);

Domain Name Resolution:
U_long libnet_name_resolve (U_char *ip, u_short use_name);

Get interface Device IP address:
U_long libnet_get_ipaddr (struct libnet_link_int *l,const u_char *device, const U_char *EBUF);

Get interface Device hardware address:
struct ether_addr *libnet_get_hwaddr (struct libnet_link_int *l,const u_char *device,const u_char *ebuf);


★Packet Constructors

ARP Protocol packet:
int Libnet_build_arp (u_short hrdw, u_short prot, U_short h_len,u_short P_len, U_short op, U_char *s_ha,
U_char *s_pa, U_char *t_ha, U_char *t_pa,const u_char *payload, int payload_len,u_char *packet_buf);

DNS Protocol Packets:
int Libnet_build_dns (u_short ID, u_short flags, U_short num_q,u_short NUM_ANSW_RR, U_short num_auth_rr,
U_short NUM_ADD_RR, const U_CHAR * payload,int Payload_len, U_char *packet_buf);

Ethernet Protocol Packets:
int libnet_build_ethernet (U_char *daddr, U_char *saddr, u_short id,const u_char *payload, int payload_len,
U_char *packet_buf);

ICMP Protocol Packet (icmp_echo/icmp_echoreply):
int Libnet_build_icmp_echo (u_char type, U_char code, u_short ID,
U_short seq, const U_char *payload,int payload_len, U_char *packet_buf);

ICMP Protocol Packet (icmp_maskreq/icmp_maskreply):
int Libnet_build_icmp_mask (u_char type, U_char code, u_short ID,
U_short seq, u_long mask,const u_char *payload, int payload_len,
U_char *packet_buf);

ICMP Protocol Packet (Icmp_unreach):
int Libnet_build_icmp_unreach (u_char type, U_char code,
U_short Orig_len, U_char orig_tos,u_short orig_id, U_short Orig_frag,
U_char Orig_ttl, U_char orig_prot,u_long orig_saddr, U_long orig_daddr,
Const U_CHAR *payload, int payload_len,u_char *packet_buf);

ICMP Protocol Packet (icmp_timexceed):
int Libnet_build_icmp_timeexceed (u_char type, U_char code,
U_short Orig_len, U_char orig_tos,u_short orig_id, U_short Orig_frag,
U_char Orig_ttl, U_char orig_prot,u_long orig_saddr, U_long orig_daddr,
Const U_CHAR *payload, int payload_len,u_char *packet_buf);

ICMP Protocol Packet (Icmp_redirect):
int Libnet_build_icmp_redirect (u_char type, U_char code, U_long Gateway,
U_short Orig_len, U_char orig_tos,u_short orig_id, U_short Orig_frag,
U_char Orig_ttl, U_char orig_prot,u_long orig_saddr, U_long orig_daddr,
Const U_CHAR *payload, int payload_len,u_char *packet_buf);

ICMP Protocol Packet (icmp_tstamp/icmp_tstampreply):
int Libnet_build_icmp_timestamp (u_char type, U_char code, u_short ID,
U_short seq, n_time otime, N_time rtime,n_time ttime, const U_char *payload,
int Payload_len, U_char *packet_buf);

IGMP protocol Packets:
int Libnet_build_igmp (u_char type, U_char code, u_long IP,
Const U_CHAR *payload, int payload_len,u_char *packet_buf);

IP protocol Packets:
int Libnet_build_ip (U_short len, U_char tos, U_short ip_id, U_short frag,u_char TTL, U_char protocol, U_long Saddr, U_long DADDR, const U_char *payload, int payload_len,u_char *packet_buf);

OSPF routing protocol packets:
int LIBNET_BUILD_OSPF (U_short len, U_char type, U_long router_id,u_long area_id, U_short Auth_type,
const char *payload, int payload_s, U_char *buf);

OSPF Routing protocol Packet (Hello):
int Libnet_build_ospf_hello (u_long netmask, u_short interval,
U_char options, U_char priority,u_int dead_interval, U_long Des_router,
U_long Backup, U_long neighbor,const char *payload, int payload_s,u_char *buf);

OSPF routing protocol Packet (database Description (DBD)):
int libnet_build_ospf_dbd (U_short len, U_char options, U_char type,
U_int sequence_num, const char *payload,int payload_s, U_char *buf);

OSPF Routing protocol packet (Link state Request (LSR)):
int LIBNET_BUILD_OSPF_LSR (u_int type, U_int ls_id, U_long Adv_router,
const char *payload, int payload_s,u_char *buf);

OSPF Routing protocol packet (Link state Update (LSU)):
int LIBNET_BUILD_OSPF_LSU (u_int num, const char *payload,int payload_s, U_char *buf);

OSPF Routing protocol packet (Link State acknowledgement (LSA)):
int Libnet_build_ospf_lsa (u_short age, U_char options, U_char type,u_int ls_id, U_long adv_router, U_int sequence_num, u_s Hort len,const char *payload, int payload_s,u_char *buf);

OSPF Routing protocol packet (OSPF Link Sate networklink State Router):
int libnet_build_ospf_lsa_net (U_long netmask, U_int router_id,
const char *payload, int payload_s,u_char *buf);

OSPF Routing protocol packet (Link state Router):
int LIBNET_BUILD_OSPF_LSA_RTR (u_short flags, u_short num, u_int ID,
U_int data, U_char type, U_char tos,u_short metric, const char *payload,int payload_s, U_char *buf);

OSPF Routing protocol packet (Link state Summary):
int Libnet_build_ospf_lsa_sum (u_long netmask, U_int metric, U_int tos,
const char *payload, int payload_s,u_char *buf);

OSPF Routing protocol packet (Link State as External):
int Libnet_build_ospf_lsa_as (u_long netmask, U_int metric,
U_long fwd_addr, U_int tag,const char *payload, int payload_s,u_char *buf);

RIP Routing protocol packets:
int Libnet_build_rip (u_char cmd, U_char ver, u_short domain,
U_short Addr_fam, U_short route_tag, U_long Ip,u_long mask, u_long next_hop, U_long metric,
Const U_CHAR *payload, int payload_len,u_char *packet_buf);

TCP protocol Packets:
int libnet_build_tcp (u_short th_sport, U_short th_dport, U_long th_seq,
U_long Th_ack, U_char th_flags, u_short th_win,u_short Th_urg, const U_char *payload,int payload_len, U_char *packet_buf);

UDP protocol Packets:
int libnet_build_udp (U_short sport, u_short dport, const U_char *payload,int payload_len, U_char *packet_buf);

IP Protocol Packet Options:
int Libnet_insert_ipo (struct ipoption *opt, U_char Opt_len,u_char *packet_buf);

TCP protocol Packet options:
int LIBNET_INSERT_TCPO (struct tcpoption *opt, U_char Opt_len,u_char *packet_buf);


★Packet send function

Open the raw socket:
int Libnet_open_raw_sock (int protocol);

Close Raw Socket:
int libnet_close_raw_sock (int socket);

Select an interface device:
int Libnet_select_device (struct sockaddr_in *sin,
U_char **device, U_char *ebuf);

Open the link layer interface device:
struct Libnet_link_int *libnet_open_link_interface (char *device,char *ebuf);

close the link layer Interface device:
int libnet_close_link_interface (struct libnet_link_int *l);

Sending IP packets:
int libnet_write_ip (int socket, U_char *packet, int packet_size);

Send link Layer packets:
int Libnet_write_link_layer (struct libnet_link_int *l,const u_char *device, U_char *packet,int packet_size);

Inspection and calculation:
int Libnet_do_checksum (U_char *packet, int protocol, int packet_size);


Related support functions

random number seed generator:
int Libnet_seed_prand ();

get random number:
U_long libnet_get_prand (int modulus);

16 binary data output:
void Libnet_hex_dump (U_char * buf, int len, int swap, FILE *stream);

Port list Chain initialization:
int libnet_plist_chain_new (struct libnet_plist_chain **plist,char *token_list);


get port list Next item (port range) for the chain :
int libnet_plist_chain_next_pair (struct Libnet_plist_chain * Plist,u_short *bport, U_short *eport);

port list Chain output display :
int libnet_plist_chain_dump (struct libnet_plist_chain *plist);

get port list chain :
u_char *libnet_plist_chain_dump_string (struct libnet_plist_chain *plist) ;

port list Chain Memory release :

void Libnet_plist_chain_free (struct libnet_plist_chain *plist);


Transfer from: Libnet of the underlying network development library

List of libnet functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.