libnet-functions.h(3)
π libnet-functions.h β a manual page, but make it a group chat π
okay so bestie, welcome to libnet-functions.h(3) β¨ this is the Library Functions Manual and we are SO back.
πΈ NAME πΈ
libnet-functions.h β the libnet exported function prototypes π
that's it, that's the whole vibe for now. this header file is where all the function prototypes that libnet actually lets the outside world see live. like, the public-facing roster. the main characters π
okay don't go anywhere yet π«Ά this page is LONG long, so it's getting split into 13 parts, and this was just part 1. more is coming, i promise. stay tuned bestie π
β¨ SYNOPSIS β¨
okay bestie, deep breath, because this is the whole function roster and it is long β but lowkey that's the point π«Ά this is your master list of everything libnet hands you. every signature below is copy-paste-exact, no cap, so you can scroll, find your girl, and go.
π setup, teardown & general housekeeping
these are the ones you literally cannot skip β you make a libnet context, you do stuff, you clean up. it's giving "leave no trace" β¨
LIBNET_API libnet_t * libnet_init (int injection_type, const char *device, char *err_buf)
LIBNET_API void libnet_destroy (libnet_t *l)
LIBNET_API void libnet_clear_packet (libnet_t *l)
LIBNET_API void libnet_stats (libnet_t *l, struct libnet_stats *ls)
libnet_initβ spawns your whole libnet context, main character energy fr πlibnet_destroyβ bye bestie, free everything π¦libnet_clear_packetβ wipe the packet build state, fresh start β¨libnet_statsβ pull the stats into astruct libnet_statsπ
πͺ peeking under the hood (getters)
the little nosy functions that tell you what's going on inside your context πΈ
LIBNET_API int libnet_getfd (libnet_t *l)
LIBNET_API const char * libnet_getdevice (libnet_t *l)
LIBNET_API uint8_t * libnet_getpbuf (libnet_t *l, libnet_ptag_t ptag)
LIBNET_API uint32_t libnet_getpbuf_size (libnet_t *l, libnet_ptag_t ptag)
LIBNET_API char * libnet_geterror (libnet_t *l)
LIBNET_API uint32_t libnet_getpacket_size (libnet_t *l)
libnet_getfdβ the file descriptor, iykyk πlibnet_getdeviceβ which device you're on πlibnet_getpbufβ grab the packet buffer for a givenlibnet_ptag_t ptagπlibnet_getpbuf_sizeβ how big that buffer is πlibnet_geterrorβ the error string, your emotional support text πlibnet_getpacket_sizeβ total packet size, periodt β
π² randomness & checksum control
LIBNET_API int libnet_seed_prand (libnet_t *l)
LIBNET_API uint32_t libnet_get_prand (int mod)
LIBNET_API int libnet_toggle_checksum (libnet_t *l, libnet_ptag_t ptag, int mode)
libnet_seed_prandβ seed the pseudo-random generator π±β¨libnet_get_prandβ pull a pseudo-random number, modded bymodπ²libnet_toggle_checksumβ flip checksums on/off for aptagπ§
π address β name conversions
turning numbers into names and names into numbers, the classic glow-up pipeline π
LIBNET_API char * libnet_addr2name4 (uint32_t in, uint8_t use_name)
LIBNET_API uint32_t libnet_name2addr4 (libnet_t *l, const char *host_name, uint8_t use_name)
LIBNET_API int libnet_in6_is_error (struct libnet_in6_addr addr)
LIBNET_API struct libnet_in6_addr libnet_name2addr6 (libnet_t *l, const char *host_name, uint8_t use_name)
LIBNET_API void libnet_addr2name6_r (struct libnet_in6_addr addr, uint8_t use_name, char *host_name, int host_name_len)
libnet_addr2name4β v4 address β name π¦libnet_name2addr4β name β v4 address β¨libnet_in6_is_errorβ is this v6 addr an error? vibe check π΅οΈββοΈlibnet_name2addr6β name β v6 address πlibnet_addr2name6_rβ v6 address β name, reentrant version, writes intohost_name(maxhost_name_len) π
π port list chains
for when you've got a whole list of ports and you're being extra about it π
LIBNET_API int libnet_plist_chain_new (libnet_t *l, libnet_plist_t **plist, char *token_list)
LIBNET_API int libnet_plist_chain_next_pair (libnet_plist_t *plist, uint16_t *bport, uint16_t *eport)
LIBNET_API int libnet_plist_chain_dump (libnet_plist_t *plist)
LIBNET_API char * libnet_plist_chain_dump_string (libnet_plist_t *plist)
LIBNET_API int libnet_plist_chain_free (libnet_plist_t *plist)
libnet_plist_chain_newβ build a fresh chain fromtoken_listπΈlibnet_plist_chain_next_pairβ iterate the nextbport/eportpair πlibnet_plist_chain_dumpβ dump it out πΎlibnet_plist_chain_dump_stringβ same but as a string πlibnet_plist_chain_freeβ free the chain, be responsible bestie π§Ή
π§± the packet builders (aka the main event)
okay this is the section where libnet really ate π₯ every libnet_build_* makes a protocol header, and every libnet_autobuild_* does part of it for you. strap in.
π·οΈ link layer β 802.1Q, 802.1X, 802.2, 802.2 SNAP, 802.3
LIBNET_API libnet_ptag_t libnet_build_802_1q (const uint8_t *dst, const uint8_t *src, uint16_t tpi, uint8_t priority, uint8_t cfi, uint16_t vlan_id, uint16_t len_proto, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_802_1x (uint8_t eap_ver, uint8_t eap_type, uint16_t length, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_802_2 (uint8_t dsap, uint8_t ssap, uint8_t control, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_802_2snap (uint8_t dsap, uint8_t ssap, uint8_t control, uint8_t *oui, uint16_t type, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_802_3 (const uint8_t *dst, const uint8_t *src, uint16_t len, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
π ethernet & FDDI
LIBNET_API libnet_ptag_t libnet_build_ethernet (const uint8_t *dst, const uint8_t *src, uint16_t type, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_autobuild_ethernet (const uint8_t *dst, uint16_t type, libnet_t *l)
LIBNET_API libnet_ptag_t libnet_build_fddi (uint8_t fc, const uint8_t *dst, const uint8_t *src, uint8_t dsap, uint8_t ssap, uint8_t cf, const uint8_t *oui, uint16_t type, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_autobuild_fddi (uint8_t fc, const uint8_t *dst, uint8_t dsap, uint8_t ssap, uint8_t cf, const uint8_t *oui, uint16_t type, libnet_t *l)
π«Ά ARP
LIBNET_API libnet_ptag_t libnet_build_arp (uint16_t hrd, uint16_t pro, uint8_t hln, uint8_t pln, uint16_t op, const uint8_t *sha, const uint8_t *spa, const uint8_t *tha, const uint8_t *tpa, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_autobuild_arp (uint16_t op, const uint8_t *sha, const uint8_t *spa, const uint8_t *tha, const uint8_t *tpa, libnet_t *l)
π TCP & UDP (+ TCP options)
LIBNET_API libnet_ptag_t libnet_build_tcp (uint16_t sp, uint16_t dp, uint32_t seq, uint32_t ack, uint8_t control, uint16_t win, uint16_t sum, uint16_t urg, uint16_t len, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_tcp_options (const uint8_t *options, uint32_t options_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_udp (uint16_t sp, uint16_t dp, uint16_t len, uint16_t sum, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
π‘ CDP & LLDP
LIBNET_API libnet_ptag_t libnet_build_cdp (uint8_t version, uint8_t ttl, uint16_t sum, uint16_t type, uint16_t value_s, const uint8_t *value, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_lldp_chassis (const uint8_t subtype, const uint8_t *value, const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_lldp_port (const uint8_t subtype, const uint8_t *value, const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_lldp_ttl (const uint16_t ttl, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_lldp_end (libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_lldp_org_spec (const uint8_t *value, const uint16_t value_s, libnet_t *l, libnet_ptag_t ptag)
π ICMPv4 (so many flavors)
LIBNET_API libnet_ptag_t libnet_build_icmpv4_echo (uint8_t type, uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_icmpv4_mask (uint8_t type, uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, uint32_t mask, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_icmpv4_unreach (uint8_t type, uint8_t code, uint16_t sum, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_icmpv4_redirect (uint8_t type, uint8_t code, uint16_t sum, uint32_t gateway, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_icmpv4_timeexceed (uint8_t type, uint8_t code, uint16_t sum, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_icmpv4_timestamp (uint8_t type, uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, uint32_t otime, uint32_t rtime, uint32_t ttime, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
π¦ ICMPv6 + NDP
LIBNET_API libnet_ptag_t libnet_build_icmpv6_echo (uint8_t type, uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_icmpv6_unreach (uint8_t type, uint8_t code, uint16_t sum, uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_nsol (uint8_t type, uint8_t code, uint16_t sum, struct libnet_in6_addr target, uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_nadv (uint8_t type, uint8_t code, uint16_t sum, uint32_t flags, struct libnet_in6_addr target, uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_opt (uint8_t type, uint8_t *option, uint32_t option_s, libnet_t *l, libnet_ptag_t ptag)
π IGMP
LIBNET_API libnet_ptag_t libnet_build_igmp (uint8_t type, uint8_t reserved, uint16_t sum, uint32_t ip, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
π IPv4 (+ options + autobuild)
LIBNET_API libnet_ptag_t libnet_build_ipv4 (uint16_t ip_len, uint8_t tos, uint16_t id, uint16_t frag, uint8_t ttl, uint8_t prot, uint16_t sum, uint32_t src, uint32_t dst, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ipv4_options (const uint8_t *options, uint32_t options_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_autobuild_ipv4 (uint16_t len, uint8_t prot, uint32_t dst, libnet_t *l)
π IPv6 (+ extensions + autobuild)
LIBNET_API libnet_ptag_t libnet_build_ipv6 (uint8_t tc, uint32_t fl, uint16_t len, uint8_t nh, uint8_t hl, struct libnet_in6_addr src, struct libnet_in6_addr dst, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ipv6_frag (uint8_t nh, uint8_t reserved, uint16_t frag, uint32_t id, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ipv6_routing (uint8_t nh, uint8_t len, uint8_t rtype, uint8_t segments, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ipv6_destopts (uint8_t nh, uint8_t len, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ipv6_hbhopts (uint8_t nh, uint8_t len, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_autobuild_ipv6 (uint16_t len, uint8_t nh, struct libnet_in6_addr dst, libnet_t *l, libnet_ptag_t ptag)
π ISL & IPsec (ESP + AH)
LIBNET_API libnet_ptag_t libnet_build_isl (uint8_t *dhost, uint8_t type, uint8_t user, uint8_t *shost, uint16_t len, const uint8_t *snap, uint16_t vid, uint16_t portindex, uint16_t reserved, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ipsec_esp_hdr (uint32_t spi, uint32_t seq, uint32_t iv, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ipsec_esp_ftr (uint8_t len, uint8_t nh, int8_t *auth, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ipsec_ah (uint8_t nh, uint8_t len, uint16_t res, uint32_t spi, uint32_t seq, uint32_t auth, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
πΈ DNS, RIP & RPC
LIBNET_API libnet_ptag_t libnet_build_dnsv4 (uint16_t h_len, uint16_t id, uint16_t flags, uint16_t num_q, uint16_t num_anws_rr, uint16_t num_auth_rr, uint16_t num_addi_rr, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_rip (uint8_t cmd, uint8_t version, uint16_t rd, uint16_t af, uint16_t rt, uint32_t addr, uint32_t mask, uint32_t next_hop, uint32_t metric, const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_rpc_call (uint32_t rm, uint32_t
bestie not me ending on a cliffhanger π the libnet_build_rpc_call signature keeps going β hold that thought, it picks right back up in the next part π
β¨
...okay so we're BACK and the synopsis is still going, because of course it is π
this is the tail end of that RPC builder that got sliced mid-prototype last time β same vibe, same ptag energy:
xid, uint32_t prog_num, uint32_t prog_vers, uint32_t procedure,
uint32_t cflavor, uint32_t clength, uint8_t *cdata, uint32_t
vflavor, uint32_t vlength, const uint8_t *vdata, const uint8_t
*payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
the STP era β¨
Spanning tree walkin' in like it owns the place π two whole builders, one for the config BPDU, one for the topology-change notification:
LIBNET_API libnet_ptag_t libnet_build_stp_conf(uint16_t id, uint8_t
version, uint8_t bpdu_type, uint8_t flags, const uint8_t *root_id,
uint32_t root_pc, const uint8_t *bridge_id, uint16_t port_id,
uint16_t message_age, uint16_t max_age, uint16_t hello_time,
uint16_t f_delay, const uint8_t *payload, uint32_t payload_s,
libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_stp_tcn(uint16_t id, uint8_t
version, uint8_t bpdu_type, const uint8_t *payload, uint32_t
payload_s, libnet_t *l, libnet_ptag_t ptag)
UDLD said "let me cook" π
UniDirectional Link Detection β and bestie it has NINE separate builders, which is honestly a lot, but every single one is here, no skips:
LIBNET_API libnet_ptag_t libnet_build_udld_hdr(uint8_t version, uint8_t
opcode, uint8_t flags, uint8_t checksum, const uint8_t *payload,
uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_udld_device_id(const uint8_t
*value, const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_udld_port_id(const uint8_t
*value, const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_udld_echo(const uint8_t *value,
const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_udld_message_interval(const
uint8_t *value, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_udld_timeout_interval(const
uint8_t *value, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_udld_device_name(const uint8_t
*value, const uint8_t value_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_udld_sequence_number(const
uint8_t *value, libnet_t *l, libnet_ptag_t ptag)
lowkey obsessed with how message_interval and timeout_interval and sequence_number don't even take a value_s while their friends do. it's giving "we're built different" and honestly? slay.
Token Ring π¦
One manual, one autobuild, both iconic:
LIBNET_API libnet_ptag_t libnet_build_token_ring(uint8_t ac, uint8_t
fc, const uint8_t *dst, const uint8_t *src, uint8_t dsap, uint8_t
ssap, uint8_t cf, const uint8_t *oui, uint16_t type, const uint8_t
*payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_autobuild_token_ring(uint8_t ac,
uint8_t fc, const uint8_t *dst, uint8_t dsap, uint8_t ssap, uint8_t
cf, const uint8_t *oui, uint16_t type, libnet_t *l)
VRRP + MPLS + NTP π
the networking girlies' holy trinity, fr fr:
LIBNET_API libnet_ptag_t libnet_build_vrrp(uint8_t version, uint8_t
type, uint8_t vrouter_id, uint8_t priority, uint8_t ip_count,
uint8_t auth_type, uint8_t advert_int, uint16_t sum, const uint8_t
*payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_mpls(uint32_t label, uint8_t
experimental, uint8_t bos, uint8_t ttl, const uint8_t *payload,
uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ntp(uint8_t leap_indicator,
uint8_t version, uint8_t mode, uint8_t stratum, uint8_t poll,
uint8_t precision, uint16_t delay_int, uint16_t delay_frac, uint16_t
dispersion_int, uint16_t dispersion_frac, uint32_t reference_id,
uint32_t ref_ts_int, uint32_t ref_ts_frac, uint32_t orig_ts_int,
uint32_t orig_ts_frac, uint32_t rec_ts_int, uint32_t rec_ts_frac,
uint32_t xmt_ts_int, uint32_t xmt_ts_frac, const uint8_t *payload,
uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
not the NTP builder having SEVENTEEN timestamp int/frac pairs π okay time-syncing main character, we see you.
OSPFv2 nation π
this is the longest block in the whole synopsis and it is not playing around. fourteen builders. count them. LSA types, hello, neighbor, dbd, lsr, lsu, lsa, rtr, net, sum, as. all of it:
LIBNET_API libnet_ptag_t libnet_build_ospfv2(uint16_t len, uint8_t
type, uint32_t rtr_id, uint32_t area_id, uint16_t sum, uint16_t
autype, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ospfv2_hello(uint32_t netmask,
uint16_t interval, uint8_t opts, uint8_t priority, uint32_t
dead_int, uint32_t des_rtr, uint32_t bkup_rtr, const uint8_t
*payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
libnet_ptag_t libnet_build_ospfv2_hello_neighbor(uint32_t netmask,
uint16_t interval, uint8_t opts, uint8_t priority, uint32_t
dead_int, uint32_t des_rtr, uint32_t bkup_rtr, uint32_t neighbor,
const uint8_t *payload, uint32_t payload_s, libnet_t *l,
libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ospfv2_dbd(uint16_t dgram_len,
uint8_t opts, uint8_t type, uint32_t seqnum, const uint8_t *payload,
uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsr(uint32_t type,
uint32_t lsid, uint32_t advrtr, const uint8_t *payload, uint32_t
payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsu(uint32_t num, const
uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t
ptag)
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa(uint16_t age, uint8_t
opts, uint8_t type, uint32_t lsid, uint32_t advrtr, uint32_t seqnum,
uint16_t sum, uint16_t len, const uint8_t *payload, uint32_t
payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_rtr(uint16_t flags,
uint16_t num, uint32_t id, uint32_t data, uint8_t type, uint8_t tos,
uint16_t metric, const uint8_t *payload, uint32_t payload_s,
libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_net(uint32_t nmask,
uint32_t rtrid, const uint8_t *payload, uint32_t payload_s, libnet_t
*l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_sum(uint32_t nmask,
uint32_t metric, uint32_t tos, const uint8_t *payload, uint32_t
payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_as(uint32_t nmask,
uint32_t metric, uint32_t fwdaddr, uint32_t tag, const uint8_t
*payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
bestie heads up πlibnet_build_ospfv2_hello_neighboris the ONE in this whole list that's missing theLIBNET_APIprefix. that's not me being cute, that's literally what the page says. copy it as-is, iykyk.
the raw data one π
just you, your bytes, and the void:
LIBNET_API libnet_ptag_t libnet_build_data(const uint8_t *payload,
uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
DHCPv4 / BOOTPv4 π
two builders, identical signatures, different names. libnet_build_dhcpv4 and libnet_build_bootpv4 β same twelve-ish args, same dreams:
LIBNET_API libnet_ptag_t libnet_build_dhcpv4(uint8_t opcode, uint8_t
htype, uint8_t hlen, uint8_t hopcount, uint32_t xid, uint16_t secs,
uint16_t flags, uint32_t cip, uint32_t yip, uint32_t sip, uint32_t
gip, const uint8_t *chaddr, const char *sname, const char *file,
const uint8_t *payload, uint32_t payload_s, libnet_t *l,
libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_bootpv4(uint8_t opcode, uint8_t
htype, uint8_t hlen, uint8_t hopcount, uint32_t xid, uint16_t secs,
uint16_t flags, uint32_t cip, uint32_t yip, uint32_t sip, uint32_t
gip, const uint8_t *chaddr, const char *sname, const char *file,
const uint8_t *payload, uint32_t payload_s, libnet_t *l,
libnet_ptag_t ptag)
GRE + eGRE πΈ
plus a length getter, plus SRE (source route entry) builders β the last one of which is literally called last_sre, which is such a mood:
LIBNET_API uint32_t libnet_getgre_length(uint16_t fv)
LIBNET_API libnet_ptag_t libnet_build_gre(uint16_t fv, uint16_t type,
uint16_t sum, uint16_t offset, uint32_t key, uint32_t seq, uint16_t
len, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_egre(uint16_t fv, uint16_t type,
uint16_t sum, uint16_t offset, uint32_t key, uint32_t seq, uint16_t
len, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_gre_sre(uint16_t af, uint8_t
offset, uint8_t length, uint8_t *routing, const uint8_t *payload,
uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_gre_last_sre(libnet_t *l,
libnet_ptag_t ptag)
BGP4 π§
header, open, update, notification β the whole friendship group:
LIBNET_API libnet_ptag_t libnet_build_bgp4_header(uint8_t
marker[LIBNET_BGP4_MARKER_SIZE], uint16_t len, uint8_t type, const
uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t
ptag)
LIBNET_API libnet_ptag_t libnet_build_bgp4_open(uint8_t version,
uint16_t src_as, uint16_t hold_time, uint32_t bgp_id, uint8_t
opt_len, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_bgp4_update(uint16_t
unfeasible_rt_len, const uint8_t *withdrawn_rt, uint16_t
total_path_attr_len, const uint8_t *path_attributes, uint16_t
info_len, uint8_t *reachability_info, const uint8_t *payload,
uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_bgp4_notification(uint8_t
err_code, uint8_t err_subcode, const uint8_t *payload, uint32_t
payload_s, libnet_t *l, libnet_ptag_t ptag)
note thatmarkeris a fixed-size array βLIBNET_BGP4_MARKER_SIZEis baked into the type, no cap. andreachability_infois a non-constuint8_t *while basically all its siblings are const. do not "fix" that. it's what the page says.
Sebek + HSRP π
two absolute legends, and both of them want fixed-size arrays too:
LIBNET_API libnet_ptag_t libnet_build_sebek(uint32_t magic, uint16_t
version, uint16_t type, uint32_t counter, uint32_t time_sec,
uint32_t time_usec, uint32_t pid, uint32_t uid, uint32_t fd, uint8_t
cmd[SEBEK_CMD_LENGTH], uint32_t length, const uint8_t *payload,
uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_build_hsrp(uint8_t version, uint8_t
opcode, uint8_t state, uint8_t hello_time, uint8_t hold_time,
uint8_t priority, uint8_t group, uint8_t reserved, uint8_t
authdata[HSRP_AUTHDATA_LENGTH], uint32_t virtual_ip, const uint8_t
*payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
cmd[SEBEK_CMD_LENGTH]. authdata[HSRP_AUTHDATA_LENGTH]. fixed. sizes. periodt. π
Link layer π«Ά
one manual, one autobuild β the classic duo:
LIBNET_API libnet_ptag_t libnet_build_link(const uint8_t *dst, const
uint8_t *src, const uint8_t *oui, uint16_t type, const uint8_t
*payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
LIBNET_API libnet_ptag_t libnet_autobuild_link(const uint8_t *dst,
const uint8_t *oui, uint16_t type, libnet_t *l)
the actual verbs π
okay so after the wall of builders we finally get to the doing-stuff functions. sending, looking up addresses, hex parsing, version, the advanced cull/write/free set, and the entire connection queue API:
LIBNET_API int libnet_write(libnet_t *l)
LIBNET_API uint32_t libnet_get_ipaddr4(libnet_t *l)
LIBNET_API struct libnet_in6_addr libnet_get_ipaddr6(libnet_t *l)
LIBNET_API struct libnet_ether_addr * libnet_get_hwaddr(libnet_t *l)
LIBNET_API uint8_t * libnet_hex_aton(const char *s, int *len)
LIBNET_API const char * libnet_version(void)
LIBNET_API int libnet_adv_cull_packet(libnet_t *l, uint8_t **packet,
uint32_t *packet_s)
LIBNET_API int libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag,
uint8_t **header, uint32_t *header_s)
LIBNET_API int libnet_adv_write_link(libnet_t *l, const uint8_t
*packet, uint32_t packet_s)
LIBNET_API int libnet_adv_write_raw_ipv4(libnet_t *l, const uint8_t
*packet, uint32_t packet_s)
LIBNET_API void libnet_adv_free_packet(libnet_t *l, uint8_t *packet)
int libnet_cq_add(libnet_t *l, char *label)
LIBNET_API libnet_t * libnet_cq_remove(libnet_t *l)
LIBNET_API libnet_t * libnet_cq_remove_by_label(char *label)
LIBNET_API const char * libnet_cq_getlabel(libnet_t *l)
LIBNET_API libnet_t * libnet_cq_find_by_label(char *label)
LIBNET_API void libnet_cq_destroy(void)
LIBNET_API libnet_t * libnet_cq_head(void)
LIBNET_API int libnet_cq_last(void)
LIBNET_API libnet_t * libnet_cq_next(void)
LIBNET_API uint32_t libnet_cq_size(void)
LIBNET_API uint32_t libnet_cq_end_loop(void)
sneaky detail alert π:libnet_cq_addis the only one in that whole connection-queue lineup withoutLIBNET_APIin front of it. same deal aslibnet_build_ospfv2_hello_neighborearlier. write it exactly like that, no cap.
and yes bestie, libnet_get_hwaddr returns a pointer (struct libnet_ether_addr *) while libnet_get_ipaddr6 returns the struct by value (struct libnet_in6_addr). the API said "consistency? never heard of her" and honestly we respect the chaos π
that's the synopsis, FINALLY done β and there's still more coming, so don't go anywhere πΈ
LIBNET_API void libnet_diag_dump_context (libnet_t *l)
LIBNET_API void libnet_diag_dump_pblock (libnet_t *l)
LIBNET_API char * libnet_diag_dump_pblock_type (uint8_t type)
void libnet_diag_dump_hex (const uint8_t *packet, uint32_t len, int
swap, FILE *stream)
π«Ά DETAILED DESCRIPTION π«Ά
libnet exported function prototypes π
Like, that's the whole vibe of this section, bestie. Every function libnet lets the outside world touch. Slay.
β¨ FUNCTION DOCUMENTATION β¨
okay so here's where it gets GOOD, we're going function by function π
LIBNET_API char * libnet_addr2name4 (uint32_t in, uint8_t use_name)
Takes a network byte ordered IPv4 address and hands you back a pointer to either a canonical DNS name (if it's got one, lucky her) or a string of dotted decimals. Heads up though: this can trigger an actual DNS lookup if the hostname and mode is set to LIBNET_RESOLVE. If mode is LIBNET_DONT_RESOLVE, no DNS lookup happens at all and you just get a pointer to a dotted decimal string.
The way this function cannot fail π«Ά β if there's no canonical name, it just falls back on the dotted decimal string. It's giving safety net energy.
not reentrant, bestie. Don't be calling this from multiple threads and expecting peace. π
Parameters
inβ network byte ordered IPv4 addressuse_nameβLIBNET_RESOLVEorLIBNET_DONT_RESOLVE
Returns
- a pointer to presentation format string
LIBNET_API void libnet_addr2name6_r (struct libnet_in6_addr addr, uint8_t use_name, char * host_name, int host_name_len)
Translates an IPv6 address into a canonical DNS name or a hexadecimal string. Same deal as her sister above: this may incur a DNS lookup if mode is set to LIBNET_RESOLVE. If mode is LIBNET_DONT_RESOLVE, no DNS lookup will be performed.
And fr fr, this function cannot fail β if no canonical name exists, it falls back to the hexadecimal string representation. π
This one IS reentrant. Character development. π
Parameters
addrβ address to convertuse_nameβLIBNET_RESOLVEorLIBNET_DONT_RESOLVEhost_nameβ Buffer to return result inhost_name_lenβ Length ofhost_namebuffer
LIBNET_API int libnet_adv_cull_header (libnet_t * l, libnet_ptag_t ptag, uint8_t ** header, uint32_t * header_s)
[Advanced Interface] Pulls the header from the specified ptag out of the given libnet context. This one is part of the advanced interface and is only available when libnet is initialized in advanced mode. If the function fails, libnet_geterror() can tell you why. π
Parameters
lβ pointer to a libnet contextptagβ the ptag referencing the header to pullheaderβ will contain the headerheader_sβ will contain the header size
Return values
1on success-1on failure
LIBNET_API int libnet_adv_cull_packet (libnet_t * l, uint8_t ** packet, uint32_t * packet_s)
[Advanced Interface] Yanks a prebuilt, wire-ready packet out of the given libnet context. If libnet was configured to do so (and bestie, it is by default) the packet will have all checksums written in. β¨ Again: advanced interface only, only when libnet is initialized in advanced mode. If the function fails, libnet_geterror() can tell you why.
Important, do not skip this: this function performs an implicitmalloc(), so you gotta make a corresponding call tolibnet_adv_free_packet()to free the memory the packet occupies. Not me forgetting to free and leaking memory for the rest of eternity π
Parameters
lβ pointer to a libnet contextpacketβ will contain the wire-ready packetpacket_sβ will contain the packet size
Return values
1on success-1on failure
LIBNET_API void libnet_adv_free_packet (libnet_t * l, uint8_t * packet)
[Advanced Interface] Frees the memory allocated when libnet_adv_cull_packet() is called. That's it. That's the whole job. Cleanup queen. π§
Parameters
lβ pointer to a libnet contextpacketβ a pointer to the packet to free
LIBNET_API int libnet_adv_write_link (libnet_t * l, const uint8_t * packet, uint32_t packet_s)
[Advanced Interface] Writes a packet to the network at the link layer. This is useful for writing a packet that the application programmer constructed by hand, or β more commonly β to write a packet that came back from a call to libnet_adv_cull_packet(). Advanced interface, advanced mode, you know the drill. If it fails, libnet_geterror() can tell you why. π
Parameters
lβ pointer to a libnet contextpacketβ a pointer to the packet to injectpacket_sβ the size of the packet
Returns
- the number of bytes written
Return values
-1on failure
LIBNET_API int libnet_adv_write_raw_ipv4 (libnet_t * l, const uint8_t * packet, uint32_t packet_s)
[Advanced Interface] Same energy as above but writes a packet to the network at the raw socket layer. Useful for hand-constructed packets, or more commonly for packets returned by libnet_adv_cull_packet(). Advanced interface only, only in advanced mode, and libnet_geterror() will spill the tea if it fails. π₯
Parameters
lβ pointer to a libnet contextpacketβ a pointer to the packet to injectpacket_sβ the size of the packet
Returns
- the number of bytes written
Return values
-1on failure
LIBNET_API libnet_ptag_t libnet_autobuild_arp (uint16_t op, const uint8_t * sha, const uint8_t * spa, const uint8_t * tha, const uint8_t * tpa, libnet_t * l)
Autouilds an Address Resolution Protocol (ARP) header. (yes, "Autouilds" β that's the original typo, we respect the lore π«Ά) Depending on the op value, the function builds one of several different types of RFC 826 or RFC 903 RARP packets.
Parameters
opβ ARP operation typeshaβ sender's hardware addressspaβ sender's protocol addressthaβ target hardware addresstpaβ target protocol addresslβ pointer to a libnet context
Returns
- protocol tag value on success
Return values
-1on error
LIBNET_API libnet_ptag_t libnet_autobuild_ethernet (const uint8_t * dst, uint16_t type, libnet_t * l)
Autobuilds an Ethernet header. The RFC 894 Ethernet II header is almost identical to the IEEE 802.3 header, except that the field right after the source address holds the layer 3 protocol instead of the frame's length. Iconic little difference. β¨
You should only use this function when libnet is initialized with the LIBNET_LINK interface.
Parameters
dstβ destination ethernet addresstypeβ upper layer protocol typelβ pointer to a libnet context
Returns
- protocol tag value on success
Return values
-1on error
LIBNET_API libnet_ptag_t libnet_autobuild_fddi (uint8_t fc, const uint8_t * dst, uint8_t dsap, uint8_t ssap, uint8_t cf, const uint8_t * oui, uint16_t type, libnet_t * l)
Autobuilds a Fiber Distributed Data Interface (FDDI) header. Retro tech moment, we love her. πΈ
Parameters
fcβ class format and prioritydstβ destination fddi addressdsapβ destination service access pointssapβ source service access pointcfβ cfouiβ IEEE organizational codetypeβ upper layer protocollβ pointer to a libnet context
Returns
- protocol tag value on success
Return values
-1on error
LIBNET_API libnet_ptag_t libnet_autobuild_ipv4 (uint16_t len, uint8_t prot, uint32_t dst, libnet_t * l)
Autobuilds a version 4 Internet Protocol (IP) header. Super handy when you wanna build an IP header fast and don't need a granular level of control. It takes the same len, prot, and dst arguments as libnet_build_ipv4().
Here's the quirky part: the function does not accept a ptag argument, but it does return a ptag. So basically you can use it to build a brand new IP header, but not to modify an existing one. New phone, who dis. π
Parameters
lenβ total length of the IP packet including all subsequent dataprotβ upper layer protocoldstβ destination IPv4 address (little endian)lβ pointer to a libnet context
Returns
- protocol tag value on success
Return values
-1on error
LIBNET_API libnet_ptag_t libnet_autobuild_ipv6 (uint16_t len, uint8_t nh, struct libnet_in6_addr dst, libnet_t * l, libnet_ptag_t ptag)
Autobuilds a version 6 RFC 2460 Internet Protocol (IP) header. Same quick-and-dirty energy: great when you don't need granular control. It takes the same len, nh, and dst arguments as libnet_build_ipv4().
And yeah, same lil contradiction as above β the function does not accept a ptag argument, but it does return a ptag, so you can build a new IP header but not modify an existing one.
This function requires libnet_get_ipaddr6(), which is not yet implemented for Win32 platforms. π
Parameters
lenβ lengthnhβ next headerdstβ destination IPv6 addresslβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
LIBNET_API libnet_ptag_t libnet_autobuild_link (const uint8_t * dst, const uint8_t * oui, uint16_t type, libnet_t * l)
Automatically builds a link layer header for an initialized l. The function figures out the proper link layer header format from how l was initialized. Currently it supports Ethernet and Token Ring link layers. π
Parameters
dstβ the destination MAC addressouiβ Organizationally Unique Identifier (unused for Ethernet)typeβ the upper layer protocol typelβ pointer to a libnet context
Returns
- protocol tag value on success
Return values
-1on error
LIBNET_API libnet_ptag_t libnet_autobuild_token_ring (uint8_t ac, uint8_t fc, const uint8_t * dst, uint8_t dsap, uint8_t ssap, uint8_t cf, const uint8_t * oui, uint16_t type, libnet_t * l)
Auto-builds a token ring header. Token ring girlies rise up π¦
Parameters
acβ access controlfcβ frame controldstβ destination addressdsapβ destination service access pointssapβ source service access pointcfβ control fieldouiβ Organizationally Unique Identifiertypeβ upper layer protocol typelβ pointer to a libnet context
Returns
- protocol tag value on success
Return values
-1on error
LIBNET_API libnet_ptag_t libnet_build_802_1q (const uint8_t * dst, const uint8_t * src, uint16_t tpi, uint8_t priority, uint8_t cfi, uint16_t vlan_id, uint16_t len_proto, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
and we're gonna stop right there bestie β the details on this one are coming up next, no spoilers π
π οΈ Packet Builder Functions π οΈ
okay so the absolute core of libnet is the platform-independent packet-building functionality. that's the whole vibe. these functions let an application programmer build protocol headers (and data) in a simple, consistent way without having to worry (too much) about low-level network odds and ends. π
every single libnet_build() function builds a piece of a packet β generally a protocol header. and like, sure, it is perfectly possible to build an entire ready-to-transmit packet with a single call to a libnet_build() function. but bestie, generally? you need more than one builder-class function call to construct a full packet. a complete wire-ready packet is basically always made of more than one piece. it's giving β¨collageβ¨.
every function that builds a protocol header takes a series of arguments that roughly correspond to the header values as they appear on the wire. this is super intuitive, but it often makes for functions with huge prototypes and large stack frames π. and here's the one thing you CANNOT skip:
you must call these functions in order, corresponding to how they should appear on the wire (from the highest protocol layer on down). π₯
this building process is intuitive; it approximates what happens in an operating system kernel. in other words, to build a Network Time Protocol (NTP) packet by using the link-layer interface, the application programmer would call the libnet_build() functions in this exact order:
libnet_build_ntp()libnet_build_udp()libnet_build_ipv4()libnet_build_ethernet()
this ordering is essential for libnet 1.1.x to properly link together the packet internally. (previous libnet versions did not have the requirement, so if you're time-travelling, adjust accordingly π°οΈ)
π The Payload Interface π
the payload interface specifies an optional way to include data directly after the protocol header in question. and it is so versatile, bestie. you can use this function for a whole variety of purposes, including:
- including additional or arbitrary protocol header information that is not available from a libnet interface
- including a packet payload (data segment)
- building another protocol header that is not available from a libnet interface
to employ the interface, the application programmer should construct the i payload data and pass a const uint8_t * to this data and its size to the desired libnet_build() function. libnet handles the rest. no cap. π«Ά
it is important to note that some functions (notably the IPv6 builders) do use the payload interface to specify variable length but ostensibly non-optional data. see the individual libnet_build_ipv6*() functions for more information. π
π Protocol Tags and Packet Builder Return Values π
libnet uses the protocol tag (ptag) to identify individual pieces of a packet after they've been created. here's the tea:
a new ptag results every time a libnet_build() function with an empty (0) ptag argument completes successfully. that new ptag now refers to the packet piece just created. and the application programmer's responsibility is to save this value if he or she plans to modify this particular portion later on in the program. write it down, bestie, put it in a variable, do not lose it π.
if the application programmer needs to modify some portion of that particular packet piece again, he or she calls the same libnet_build() function specifying the saved ptag argument. libnet then searches for that packet piece and modifies it rather than creating a new one. iconique. β¨
upon failure for any reason,libnet_build()functions return-1;libnet_geterror()tells you why. π
π libnet_build_802_1q
builds an IEEE 802.1q VLAN tagging header. depending on the value of len_proto, the function wraps the 802.1q header inside either an IEEE 802.3 header or an RFC 894 Ethernet II (DIX) header (both resulting in an 18-byte frame). if len is 1500 or less, most receiving protocol stacks parse the frame as an IEEE 802.3 encapsulated frame. if len is one of the Ethernet type values, most protocol stacks parse the frame as an RFC 894 Ethernet II encapsulated frame. note the length value is calculated without the 802.1q header of 18 bytes. π
Parameters
dstβ pointer to a six byte source ethernet addresssrcβ pointer to a six byte destination ethernet addresstpiβ tag protocol identifierpriorityβ prioritycfiβ canonical format indicatorvlan_idβ vlan identifierlen_protoβ length (802.3) protocol (Ethernet II)payloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success
Return values
-1on error
π¦ libnet_build_802_1x
LIBNET_API libnet_ptag_t libnet_build_802_1x (uint8_t eap_ver, uint8_t eap_type, uint16_t length, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
builds an IEEE 802.1x extended authentication protocol header. auth girlies rise π
Parameters
eap_verβ the EAP versioneap_typeβ the EAP typelengthβ frame lengthpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success
Return values
-1on error
πΈ libnet_build_802_2
LIBNET_API libnet_ptag_t libnet_build_802_2 (uint8_t dsap, uint8_t ssap, uint8_t control, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
builds an IEEE 802.2 LLC header. short, sweet, slays. β¨
Parameters
dsapβ destination service access pointssapβ source service access pointcontrolβ control fieldpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success
Return values
-1on error
π libnet_build_802_2snap
LIBNET_API libnet_ptag_t libnet_build_802_2snap (uint8_t dsap, uint8_t ssap, uint8_t control, uint8_t * oui, uint16_t type, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
builds an IEEE 802.2 LLC SNAP header. the SNAP version of the above, extra crispy π
Parameters
dsapβ destination service access pointssapβ source service access pointcontrolβ control fieldouiβ Organizationally Unique Identifiertypeβ upper layer protocolpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success
Return values
-1on error
π§ libnet_build_802_3
LIBNET_API libnet_ptag_t libnet_build_802_3 (const uint8_t * dst, const uint8_t * src, uint16_t len, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
builds an IEEE 802.3 header. the 802.3 header is almost identical to the RFC 894 Ethernet II header β the exception being that the field immediately following the source address holds the frame's length (as opposed to the layer 3 protocol). tiny difference, huge consequences, main character energy π
you should only use this function when libnet is initialized with the LIBNET_LINK interface.
Parameters
dstβ destination ethernet addresssrcβ source ethernet addresslenβ frame length sans headerpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success
Return values
-1on error
π libnet_build_arp
LIBNET_API libnet_ptag_t libnet_build_arp (uint16_t hrd, uint16_t pro, uint8_t hln, uint8_t pln, uint16_t op, const uint8_t * sha, const uint8_t * spa, const uint8_t * tha, const uint8_t * tpa, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
builds an Address Resolution Protocol (ARP) header. depending on the op value, the function builds one of several different types of RFC 826 or RFC 903 RARP packets. yes bestie, RARP too, we contain multitudes π¦
Parameters
hrdβ hardware address formatproβ protocol address formathlnβ hardware address lengthplnβ protocol address lengthopβ ARP operation typeshaβ sender's hardware addressspaβ sender's protocol addressthaβ target hardware addresstpaβ target protocol addresspayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success
Return values
-1on error
π libnet_build_bgp4_header
LIBNET_API libnet_ptag_t libnet_build_bgp4_header (uint8_t marker[LIBNET_BGP4_MARKER_SIZE], uint16_t len, uint8_t type, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) header. okay so the primary function of a BGP speaking system is to exchange network reachability information with other BGP systems. this network reachability information includes info on the list of Autonomous Systems (ASs) that reachability information traverses. that information is sufficient to construct a graph of AS connectivity from which routing loops may be pruned and some policy decisions at the AS level may be enforced. π
this function builds the base BGP header, which is used as a preamble before any other BGP header. for example, a BGP KEEPALIVE message may be built with only this function, while an error notification requires a subsequent call to libnet_build_bgp4_notification. iykyk π₯
Parameters
markerβ a value the receiver can predict (if the message type is not BGP OPEN, or no authentication is used, these 16 bytes are normally set as all ones)lenβ total length of the BGP message, including the headertypeβ type code of the message (OPEN, UPDATE, NOTIFICATION or KEEPALIVE)payloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success
Return values
-1on error
π libnet_build_bgp4_notification
LIBNET_API libnet_ptag_t libnet_build_bgp4_notification (uint8_t err_code, uint8_t err_subcode, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) notification header. a NOTIFICATION message is sent when an error condition is detected β it's giving π¨something went wrongπ¨. specific error information may be passed through the payload interface. πΈ
Parameters
err_codeβ type of notificationerr_subcodeβ more specific information about the reported error.payloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success
Return values
-1on error
π¦ libnet_build_bgp4_open
LIBNET_API libnet_ptag_t libnet_build_bgp4_open (uint8_t version, uint16_t src_as, uint16_t hold_time, uint32_t bgp_id, uint8_t opt_len, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) OPEN header β¨ This is the very first message each side of a BGP connection sends β like the "hey bestie, let's talk" of routing protocols π And the optional parameters options? You construct those through the payload interface (peep RFC 1771 for the options structures, iykyk).
Parameters
versionβ protocol version (should be set to4)src_asβ Autonomous System of the senderhold_timeβ used to compute the maximum allowed time between the receipt ofKEEPALIVE, and/orUPDATEmessages by the senderbgp_idβ BGP identifier of the senderopt_lenβ total length of the optional parameters field in bytespayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
π¦ libnet_build_bgp4_update
LIBNET_API libnet_ptag_t libnet_build_bgp4_update (uint16_t unfeasible_rt_len, const uint8_t * withdrawn_rt, uint16_t total_path_attr_len, const uint8_t * path_attributes, uint16_t info_len, uint8_t * reachability_info, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) update header π Update messages are literally the ones moving routing information between BGP peers β the gossip girls of the internet, no cap π
Parameters
unfeasible_rt_lenβ indicates the length of the (next) "withdrawn routes" field in byteswithdrawn_rtβ list of IP addresses prefixes for the routes that are being withdrawn; each IP address prefix is built as a 2-tuple<length (1 byte), prefix (variable)>total_path_attr_lenβ indicates the length of the (next) "path attributes" field in bytespath_attributesβ each attribute is a 3-tuple<type (2 bytes), length, value>info_lenβ indicates the length of the (next) "network layer reachability information" field in bytes (needed for internal memory size calculation)reachability_infoβ 2-tuples<length (1 byte), prefix (variable)>.payloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
π¦ libnet_build_bootpv4
LIBNET_API libnet_ptag_t libnet_build_bootpv4 (uint8_t opcode, uint8_t htype, uint8_t hlen, uint8_t hopcount, uint32_t xid, uint16_t secs, uint16_t flags, uint32_t cip, uint32_t yip, uint32_t sip, uint32_t gip, const uint8_t * chaddr, const char * sname, const char * file, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters
opcodehtypehlenhopcountxidsecsflagscipyipsipgipchaddrβ client hardware address, length ishlensnameβ server host name, a null terminated stringfileβ boot file name, a null terminated stringpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
ngl the first eleven params are just listed here with zero description in the source, bestie β we don't invent lore in this house π
Returns
- protocol tag value on success
Return values
-1on error
π¦ libnet_build_cdp
LIBNET_API libnet_ptag_t libnet_build_cdp (uint8_t version, uint8_t ttl, uint16_t sum, uint16_t type, uint16_t value_s, const uint8_t * value, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds a Cisco Discovery Protocol (CDP) header π Cisco Systems designed CDP to aid in the network management of adjacent Cisco devices. CDP specifies data by using a type/length/value (TLV) setup, which is very "structured queen" of it. The first TLV can be specified with the type, length, and value arguments β wait, the args are type, value_s, and value, but you get the vibe π
To specify additional TLVs, the programmer could either use the payload interface or libnet_build_data() to construct them β¨
Parameters
versionβ CDP versionttlβ time to live (time information should be cached by recipient)sumβ checksum (0for libnet to auto-fill)typeβ type of data contained in valuevalue_sβ length of value argumentvalueβ the CDP information stringpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
π¦ libnet_build_data
LIBNET_API libnet_ptag_t libnet_build_data (const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds a generic libnet protocol header πΈ This is lowkey iconic for including an optional payload to a packet that might need to change repeatedly inside of a loop π
Heads up though: this won't work for TCP or IP payload β they have special types (this is probably a bug) π
Parameters
payloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
π¦ libnet_build_dhcpv4
LIBNET_API libnet_ptag_t libnet_build_dhcpv4 (uint8_t opcode, uint8_t htype, uint8_t hlen, uint8_t hopcount, uint32_t xid, uint16_t secs, uint16_t flags, uint32_t cip, uint32_t yip, uint32_t sip, uint32_t gip, const uint8_t * chaddr, const char * sname, const char * file, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters
opcodehtypehlenhopcountxidsecsflagscipyipsipgipchaddrβ client hardware address, length ishlensnameβ server host name, a null terminated stringfileβ boot file name, a null terminated stringpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
π¦ libnet_build_dnsv4
LIBNET_API libnet_ptag_t libnet_build_dnsv4 (uint16_t h_len, uint16_t id, uint16_t flags, uint16_t num_q, uint16_t num_anws_rr, uint16_t num_auth_rr, uint16_t num_addi_rr, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an RFC 1035 version 4 DNS header π¦ Any additional DNS payload information should be specified using the payload interface, bestie β don't try to cram it in here β¨
Parameters
h_lenidβ DNS packet idflagsβ control flagsnum_qβ number of questionsnum_anws_rrβ number of answer resource recordsnum_auth_rrβ number of authority resource recordsnum_addi_rrβ number of additional resource recordspayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
π¦ libnet_build_egre
LIBNET_API libnet_ptag_t libnet_build_egre (uint16_t fv, uint16_t type, uint16_t sum, uint16_t offset, uint32_t key, uint32_t seq, uint16_t len, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Generic Routing Encapsulation (GRE - RFC 1701) is used to encapsulate any protocol β it's giving "I contain multitudes" π Hence, the IP part of the packet is usually referred as "deliveryheader". It is then followed by the GRE header and finally the encapsulated packet (IP or whatever). As GRE is very modular, the first GRE header describes the structure of the header, using bits and flag to specify which fields will be present in the header π§©
Parameters
fvβ the 16 0 to 7: which fields are included in the header (checksum, seq. number, key, ...), bits 8 to 12: flag, bits 13 to 15: version.typeβ which protocol is encapsulated (PPP, IP, ...)sumβ checksum (0for libnet to auto-fill).offsetβ byte offset from the start of the routing field to the first byte of the SREkeyβ inserted by the encapsulator to authenticate the sourceseqβ sequence number used by the receiver to sort the packetslenβ size of the GRE packetpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
π¦ libnet_build_ethernet
LIBNET_API libnet_ptag_t libnet_build_ethernet (const uint8_t * dst, const uint8_t * src, uint16_t type, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an Ethernet header π The RFC 894 Ethernet II header is almost identical to the IEEE 802.3 header, with the exception that the field immediately following the source address holds the layer 3 protocol (as opposed to frame's length). Subtle but make no mistake, it matters π
You should only use this function when libnet is initialized with the LIBNET_LINK interface.
Parameters
dstβ destination ethernet addresssrcβ source ethernet addresstypeβ upper layer protocol typepayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
π¦ libnet_build_fddi
LIBNET_API libnet_ptag_t libnet_build_fddi (uint8_t fc, const uint8_t * dst, const uint8_t * src, uint8_t dsap, uint8_t ssap, uint8_t cf, const uint8_t * oui, uint16_t type, const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds a Fiber Distributed Data Interface (FDDI) header π
Parameters
fcβ class format and prioritydstβ destination fddi addresssrcβ source fddi addressdsapβ destination service access pointssapβ source service access pointcfβ cfouiβ 3 byte IEEE organizational codetypeβ upper layer protocolpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
- protocol tag value on success
Return values
-1on error
πΈ libnet_build_gre
LIBNET_API libnet_ptag_t libnet_build_gre (uint16_t fv, uint16_t type,
uint16_t sum, uint16_t offset, uint32_t key, uint32_t seq, uint16_t len,
const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t
ptag)
Generic Routing Encapsulation β that's GRE, bestie, straight outta RFC 1701 β is the girlboss of encapsulation, she can wrap up literally any protocol π . So the way it goes: the IP part of the packet is usually called the "deliveryheader", then the GRE header comes right after it, and then finally you get the encapsulated packet (IP or whatever else you're stuffing in there) π. And because GRE is so modular β iconic behavior honestly β the first GRE header literally describes the structure of the header itself, using bits and flags to say which fields are gonna show up. iykyk β¨
Parameters
fvβ the 16, where bits0to7say which fields are included in the header (checksum, seq. number, key, ...), bits8to12are the flag, and bits13to15are the version πtypeβ which protocol is encapsulated (PPP, IP, ...)sumβ checksum (0for libnet to auto-fill) β¨offsetβ byte offset from the start of the routing field to the first byte of the SREkeyβ inserted by the encapsulator to authenticate the source πseqβ sequence number used by the receiver to sort the packetslenβ size of the GRE packetpayloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
π¦ libnet_build_gre_last_sre
LIBNET_API libnet_ptag_t libnet_build_gre_last_sre (libnet_t * l,
libnet_ptag_t ptag)
Parameters
lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
β¨ libnet_build_gre_sre
LIBNET_API libnet_ptag_t libnet_build_gre_sre (uint16_t af, uint8_t offset,
uint8_t length, uint8_t * routing, const uint8_t * payload, uint32_t
payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters
afoffsetlengthroutingpayloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
π libnet_build_hsrp
LIBNET_API libnet_ptag_t libnet_build_hsrp (uint8_t version, uint8_t opcode,
uint8_t state, uint8_t hello_time, uint8_t hold_time, uint8_t priority,
uint8_t group, uint8_t reserved, uint8_t authdata[HSRP_AUTHDATA_LENGTH],
uint32_t virtual_ip, const uint8_t * payload, uint32_t payload_s,
libnet_t * l, libnet_ptag_t ptag)
Builds a HSRP header, no biggie π . HSRP is a Cisco proprietary protocol, defined in RFC 2281 β very main character of them honestly π
Parameters
versionβ version of the HSRP messagesopcodeβ type of messagestateβ current state of the routerhello_timeβ period in seconds between hello messages πhold_timeβ seconds that the current hello message is validpriorityβ priority for the election process π³οΈgroupβ standby groupreservedβ reserved fieldauthdataβ password πvirtual_ipβ virtual ip addresspayloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
π libnet_build_icmpv4_echo
LIBNET_API libnet_ptag_t libnet_build_icmpv4_echo (uint8_t type, uint8_t
code, uint16_t sum, uint16_t id, uint16_t seq, const uint8_t * payload,
uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
β οΈ Real talk bestie: at the moment, this function is not implemented. Not me telling you this before you waste your whole afternoon on it π
This stub may be useful in feature to let to the user build the LLDPDU in one function by passing corresponding arguments. Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) echo request/reply header π
Parameters
typeβ type of ICMP packet (should beICMP_ECHOREPLYorICMP_ECHO)codeβ code of ICMP packet (should be0)sumβ checksum (0for libnet to auto-fill) β¨idβ identification numberseqβ packet sequence numberpayloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
π libnet_build_icmpv4_mask
LIBNET_API libnet_ptag_t libnet_build_icmpv4_mask (uint8_t type, uint8_t
code, uint16_t sum, uint16_t id, uint16_t seq, uint32_t mask, const
uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) IP netmask request/reply header. Slay π
Parameters
typeβ type of ICMP packet (should beICMP_MASKREQorICMP_MASKREPLY)codeβ code of ICMP packet (should be0)sumβ checksum (0for libnet to auto-fill) β¨idβ identification numberseqβ packet sequence numbermaskβ subnet maskpayloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
π§ libnet_build_icmpv4_redirect
LIBNET_API libnet_ptag_t libnet_build_icmpv4_redirect (uint8_t type, uint8_t
code, uint16_t sum, uint32_t gateway, const uint8_t * payload, uint32_t
payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an IP version 4 RFC 792 Internet Message Control Protocol (ICMP) redirect header. And heads up β the IP header that caused the error message should be built by a previous call to libnet_build_ipv4() π₯
Parameters
typeβ type of ICMP packet (should beICMP_REDIRECT)codeβ code of ICMP packet (should be one of the four redirect codes)sumβ checksum (0for libnet to auto-fill) β¨gatewaypayloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
β libnet_build_icmpv4_timeexceed
LIBNET_API libnet_ptag_t libnet_build_icmpv4_timeexceed (uint8_t type,
uint8_t code, uint16_t sum, const uint8_t * payload, uint32_t payload_s,
libnet_t * l, libnet_ptag_t ptag)
Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) time exceeded header. Same deal as before β the IP header that caused the error message should be built by a previous call to libnet_build_ipv4() π
Parameters
typeβ type of ICMP packet (should beICMP_TIMXCEED)codeβ code of ICMP packet (ICMP_TIMXCEED_INTRANS/ICMP_TIMXCEED_REASS)sumβ checksum (0for libnet to auto-fill) β¨payloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
πΈ libnet_build_icmpv4_timestamp
LIBNET_API libnet_ptag_t libnet_build_icmpv4_timestamp (uint8_t type,
uint8_t code, uint16_t sum, uint16_t id, uint16_t seq, uint32_t otime,
uint32_t rtime, uint32_t ttime, const uint8_t * payload, uint32_t
payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) timestamp request/reply header. Clock in, bestie β°β¨
Parameters
typeβ type of ICMP packet (should beICMP_TSTAMPorICMP_TSTAMPREPLY)codeβ code of ICMP packet (should be0)sumβ checksum (0for libnet to auto-fill) β¨idβ identification numberseqβ sequence numberotimeβ originate timestamprtimeβ receive timestampttimeβ transmit timestamppayloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
π libnet_build_icmpv4_unreach
LIBNET_API libnet_ptag_t libnet_build_icmpv4_unreach (uint8_t type, uint8_t
code, uint16_t sum, const uint8_t * payload, uint32_t payload_s,
libnet_t * l, libnet_ptag_t ptag)
Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) unreachable header. And yes, once again β the IP header that caused the error message should be built by a previous call to libnet_build_ipv4() π
Parameters
typeβ type of ICMP packet (should beICMP_UNREACH)codeβ code of ICMP packet (should be one of the 16 unreachable codes)sumβ checksum (0for libnet to auto-fill) β¨payloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
π libnet_build_icmpv6_echo
LIBNET_API libnet_ptag_t libnet_build_icmpv6_echo (uint8_t type, uint8_t
code, uint16_t sum, uint16_t id, uint16_t seq, uint8_t * payload,
uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an IP version 6 RFC 4443 Internet Control Message Protocol (ICMP) echo or echo reply header. v6 girlies rise π¦
Parameters
typeβ type of ICMP packet (should beICMP6_ECHO_REQUESTorICMP6_ECHO_REPLY)codeβ code of ICMP packet (should be zero)sumβ checksum (0for libnet to auto-fill) β¨idβ echo id numberseqβ echo sequence numberpayloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
π
libnet_build_icmpv6_ndp_nadv
LIBNET_API libnet_ptag_t libnet_build_icmpv6_ndp_nadv (uint8_t type, uint8_t
code, uint16_t sum, uint32_t flags, struct libnet_in6_addr target,
uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an IP version 6 RFC 2461 Internet Control Message Protocol (ICMP) NDP neighbour advertisement header. Could be used with libnet_build_icmpv6_ndp_opt() and ND_OPT_TARGET_LINKADDR β they're like a little duo, obsessed with them fr fr π
Parameters
typeβ type of ICMP packet (should beND_NEIGHBOR_ADVERT)codeβ code of ICMP packet (should be zero)sumβ checksum (0for libnet to auto-fill) β¨flagsβ should be a bitwise or of any applicableND_NA_FLAG_*flagstargetβ target ipv6 addresspayloadβ optional payload or NULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success π«Ά
Return values
-1 on error π
libnet_build_icmpv6_ndp_nsol()</p> π
okay so bestie, this one builds an IP version 6 RFC 2461 Internet Control Message Protocol (ICMP) NDP neighbour solicitation header. Could be used with libnet_build_icmpv6_ndp_opt() and ICMPV6_NDP_OPT_SLLA. it's giving "hi, are you there?" but in packet form π¦
Parameters
typeβ type of ICMP packet (should beND_NEIGHBOR_SOLICIT)codeβ code of ICMP packet (should be zero)sumβ checksum (0 for libnet to auto-fill)targetβ target ipv6 addresspayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_icmpv6_ndp_opt() β¨
Builds ICMPv6 NDP options. little extra seasoning for your NDP packets, we love to see it π
Parameters
typeβ one ofND_OPT_*typesoptionβ option dataoption_sβ size of option data (will be padded out to an 8-byte boundary)lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_icmpv6_unreach() π
Builds an IP version 6 RFC 4443 Internet Control Message Protocol (ICMP) unreachable header. heads up: the IP header that caused the error message should be built by a previous call to libnet_build_ipv6(). like, don't skip that step, it's part of the lore π«Ά
Parameters
typeβ type of ICMP packet (should beICMP6_DST_UNREACH)codeβ code of ICMP packet (should be one of the 5ICMP6_DST_UNREACH_*codes)sumβ checksum (0 for libnet to auto-fill)payloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_igmp() π
Builds an RFC 1112 Internet Group Membership Protocol (IGMP) header. yes it's a whole protocol about joining the group chat, I'm obsessed actually π
Parameters
typeβ packet typereservedβ (should be 0 for IGMPv1)sumβ checksum (0 for libnet to auto-fill)ipβ IPv4 address (in standard/network byte order)payloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
Note
literally just the word "Note" on the original page, bestie. no follow-up, no tea, nothing. the silence is the note. π
libnet_build_ipsec_ah() π
Builds an Internet Protocol Security Authentication header. security girlies rise π«Ά
Parameters
nhβ next headerlenβ payload lengthresβ reservedspiβ security parameter indexseqβ sequence numberauthβ authentication datapayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_ipsec_esp_ftr() πΈ
Builds an Internet Protocol Security Encapsulating Security Payload footer. the lil outro of your ESP situation π
Parameters
lenβ padding lengthnhβ next headerauthβ authentication datapayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_ipsec_esp_hdr() π¦
Builds an Internet Protocol Security Encapsulating Security Payload header. the main character counterpart to that footer above β¨
Parameters
spiβ security parameter indexseqβ ESP sequence numberivβ initialization vectorpayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_ipv4() π
Builds a version 4 RFC 791 Internet Protocol (IP) header. the classic. the blueprint. the blueprint that ate, fr fr π₯
Parameters
ip_lenβ total length of the IP packet including all subsequent data (subsequent data includes any IP options and IP options padding)tosβ type of service bitsidβ IP identification numberfragβ fragmentation bits and offsetttlβ time to live in the networkprotβ upper layer protocolsumβ checksum (0 for libnet to auto-fill)srcβ source IPv4 address (little endian)dstβ destination IPv4 address (little endian)payloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_ipv4_options() π
Builds an version 4 Internet Protocol (IP) options header. The function expects options to be a valid IP options string of size options_s, no larger than 40 bytes (the maximum size of an options string). so like, 40 bytes is the hard ceiling bestie, don't test it π
When building a chain, the options must be built, then the IPv4 header.
When updating a chain, if the block following the options is an IPv4 header, it's total length and header length will be updated if the options block size changes.
Parameters
optionsβ byte string of IP options (it will be padded up to be an integral multiple of 32-bit words).options_sβ length of options stringlβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_ipv6() π
Builds a version 6 RFC 2460 Internet Protocol (IP) header. the glow-up edition, we love her π
Parameters
tcβ traffic classflβ flow labellenβ total length of the IP packetnhβ next headerhlβ hop limitsrcβ source IPv6 addressdstβ destination IPv6 addresspayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_ipv6_destopts() β¨
Builds a version 6 RFC 2460 Internet Protocol (IP) destination options header. This function is special in that it uses the payload interface to include the options data. The application programmer will build an IPv6 options byte string and pass it to the function using the payload interface. so yes, you're smuggling your options in through the payload door, that's just how she works π«Ά
Parameters
nhβ next headerlenβ length of the header in 8-byte octets not including the first 8 octetspayloadβ options payloadpayload_sβ payload lengthlβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_ipv6_frag() π
Builds a version 6 RFC 2460 Internet Protocol (IP) fragmentation header. chopping the packet into pieces, it's giving "break it down now" πΆ
Parameters
nhβ next headerreservedβ unused value... OR IS IT!fragβ fragmentation bits (ala ipv4)idβ packet identificationpayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_ipv6_hbhopts() π¦
Builds a version 6 RFC 2460 Internet Protocol (IP) hop by hop options header. This function is special in that it uses the payload interface to include the options data. The application programmer will build an IPv6 hop by hop options byte string and pass it to the function using the payload interface. same payload-interface trick as her sister above, iykyk π
Parameters
nhβ next headerlenβ length of the header in 8-byte octets not including the first 8 octetspayloadβ options payloadpayload_sβ payload lengthlβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns
- protocol tag value on success
Return values
-1on error
libnet_build_ipv6_routing() π§
Builds a version 6 RFC 2460 Internet Protocol (IP) routing header. This function is special in that it uses the payload interface to include the "type-specific data"; that is the routing information. Most often this will be a number of 128-bit IPv6 addresses. The application programmer will build a byte string of IPv6 address and pass them to the function using the payload interface.
Parameters (for the one that got cut off) π«Ά
nhβ next headerlenβ length of the header in 8-byte octets not including the first 8 octetsrtypeβ routing header typesegmentsβ number of routing segments that followpayloadβ optional payload of routing informationpayload_sβ payload lengthlβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_isl π
LIBNET_API libnet_ptag_t libnet_build_isl (uint8_t * dhost, uint8_t type,
uint8_t user, uint8_t * shost, uint16_t len, const uint8_t * snap,
uint16_t vid, uint16_t portindex, uint16_t reserved, const uint8_t *
payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds a Cisco Inter-Switch Link (ISL) header. periodt
Parameters
dhostβ destination address (should be 01:00:0c:00:00)typeβ type of frameuserβ user defined datashostβ source mac addresslenβ total length of the encapsulated packet less 18 bytessnapβ SNAP information (0xaaaa03 + vendor code)vidβ 15 bit VLAN ID, 1 bit BPDU or CDP indicatorportindexβ port indexreservedβ used for FDDI and token ringpayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_link π¦
LIBNET_API libnet_ptag_t libnet_build_link (const uint8_t * dst, const
uint8_t * src, const uint8_t * oui, uint16_t type, const uint8_t *
payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds a link layer header for an initialized l. The function determines the proper link layer header format from how l was initialized. The function current supports Ethernet and Token Ring link layers. (yes, it says βcurrentβ β we donβt make the rules π)
Parameters
dstβ the destination MAC addresssrcβ the source MAC addressouiβ Organizationally Unique Identifier (unused for Ethernet)typeβ the upper layer protocol typepayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_lldp_chassis πΈ
LIBNET_API libnet_ptag_t libnet_build_lldp_chassis (const uint8_t subtype,
const uint8_t * value, const uint8_t value_s, libnet_t * l,
libnet_ptag_t ptag)
Builds a LLDP Chassis ID TLV. The Chassis ID TLV is the first mandatory TLV in the LLDPDU. iconic
Parameters
subtypeβ Chassis ID Subtypevalueβ the Chassis ID stringvalue_sβ length ofvalueargumentlβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_lldp_end π
LIBNET_API libnet_ptag_t libnet_build_lldp_end (libnet_t * l, libnet_ptag_t
ptag)
Builds a LLDP End of LLDPDU TLV. The End of LLDPDU TLV used to mark the end of the TLV sequence in LLDPDU. Is a 2 octet all-zero TLV. fr fr
Parameters
lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_lldp_org_spec β¨
LIBNET_API libnet_ptag_t libnet_build_lldp_org_spec (const uint8_t * value,
const uint16_t value_s, libnet_t * l, libnet_ptag_t ptag)
Builds a LLDP Organization Specific TLV. slay
Parameters
valueβ the TLV information stringvalue_sβ length ofvalueargumentlβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_lldp_port π
LIBNET_API libnet_ptag_t libnet_build_lldp_port (const uint8_t subtype,
const uint8_t * value, const uint8_t value_s, libnet_t * l,
libnet_ptag_t ptag)
Builds a LLDP Port ID TLV. The Port ID TLV is the second mandatory TLV in the LLDPDU. bestie
Parameters
subtypeβ Port ID Subtypevalueβ the Port ID stringvalue_sβ length ofvalueargumentlβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_lldp_ttl π°οΈ
LIBNET_API libnet_ptag_t libnet_build_lldp_ttl (const uint16_t ttl, libnet_t
* l, libnet_ptag_t ptag)
Builds a LLDP TTL TLV. The TTL TLV is the third mandatory TLV in the LLDPDU. periodt
Parameters
ttlβ number of secondslβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_mpls π
LIBNET_API libnet_ptag_t libnet_build_mpls (uint32_t label, uint8_t
experimental, uint8_t bos, uint8_t ttl, const uint8_t * payload,
uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an RFC 3032 Multi-Protocol Label Switching (MPLS) header. obsessed
Parameters
labelβ 20-bit label valueexperimentalβ 3-bit reserved fieldbosβ 1-bit bottom of stack identifierttlβ time to livepayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_ntp β°
LIBNET_API libnet_ptag_t libnet_build_ntp (uint8_t leap_indicator, uint8_t
version, uint8_t mode, uint8_t stratum, uint8_t poll, uint8_t precision,
uint16_t delay_int, uint16_t delay_frac, uint16_t dispersion_int,
uint16_t dispersion_frac, uint32_t reference_id, uint32_t ref_ts_int,
uint32_t ref_ts_frac, uint32_t orig_ts_int, uint32_t orig_ts_frac,
uint32_t rec_ts_int, uint32_t rec_ts_frac, uint32_t xmt_ts_int, uint32_t
xmt_ts_frac, const uint8_t * payload, uint32_t payload_s, libnet_t * l,
libnet_ptag_t ptag)
Builds an RFC 958 Network Time Protocol (NTP) header. time is fake anyway
Parameters
leap_indicatorβ the leap indicatorversionβ NTP protocol versionmodeβ NTP modestratumβ stratumpollβ polling intervalprecisionβ precisiondelay_intβ delay intervaldelay_fracβ delay fractiondispersion_intβ dispersion intervaldispersion_fracβ dispersion fractionreference_idβ reference idref_ts_intβ reference timestamp integerref_ts_fracβ reference timestamp fractionorig_ts_intβ original timestamp integerorig_ts_fracβ original timestamp fractionrec_ts_intβ receiver timestamp integerrec_ts_fracβ receiver timestamp fractionxmt_ts_intβ transmit timestamp integerxmt_ts_fracβ transmit timestamp integerpayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_ospfv2 π¦
LIBNET_API libnet_ptag_t libnet_build_ospfv2 (uint16_t len, uint8_t type,
uint32_t rtr_id, uint32_t area_id, uint16_t sum, uint16_t autype, const
uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters
lentypertr_idarea_idsumautypepayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_ospfv2_dbd π«Ά
LIBNET_API libnet_ptag_t libnet_build_ospfv2_dbd (uint16_t dgram_len,
uint8_t opts, uint8_t type, uint32_t seqnum, const uint8_t * payload,
uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters
dgram_lenoptstypeseqnumpayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_ospfv2_hello π
LIBNET_API libnet_ptag_t libnet_build_ospfv2_hello (uint32_t netmask,
uint16_t interval, uint8_t opts, uint8_t priority, uint32_t dead_int,
uint32_t des_rtr, uint32_t bkup_rtr, const uint8_t * payload, uint32_t
payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters
netmaskintervaloptsprioritydead_intdes_rtrbkup_rtrpayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_ospfv2_hello_neighbor π
Note: this oneβs signature doesnβt have LIBNET_API in front β we keep it exactly as the page says, bestie. π
libnet_ptag_t libnet_build_ospfv2_hello_neighbor (uint32_t netmask, uint16_t
interval, uint8_t opts, uint8_t priority, uint32_t dead_int, uint32_t
des_rtr, uint32_t bkup_rtr, uint32_t neighbor, const uint8_t * payload,
uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters
netmaskintervaloptsprioritydead_intdes_rtrbkup_rtrneighborpayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_ospfv2_lsa π
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa (uint16_t age, uint8_t
opts, uint8_t type, uint32_t lsid, uint32_t advrtr, uint32_t seqnum,
uint16_t sum, uint16_t len, const uint8_t * payload, uint32_t payload_s,
libnet_t * l, libnet_ptag_t ptag)
Parameters
ageoptstypelsidadvrtrseqnumsumlenpayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values -1 on error
libnet_build_ospfv2_lsa_as π
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_as (uint32_t nmask,
uint32_t metric, uint32_t fwdaddr, uint32_t tag, const uint8_t *
payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters
nmaskmetricfwdaddrtagpayloadβ optional payload or NULLpayload_sβ payload length or 0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header, 0 to build a new one
Returns protocol tag value on success
Return values: -1 on error π
libnet_build_ospfv2_lsa_net
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_net (uint32_t nmask,
uint32_t rtrid, const uint8_t * payload, uint32_t payload_s, libnet_t *
l, libnet_ptag_t ptag)
Parameters:
nmaskβ thenmaskvalue, periodtrtridβ thertridvaluepayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_ospfv2_lsa_rtr
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_rtr (uint16_t flags,
uint16_t num, uint32_t id, uint32_t data, uint8_t type, uint8_t tos,
uint16_t metric, const uint8_t * payload, uint32_t payload_s, libnet_t *
l, libnet_ptag_t ptag)
Parameters:
flagsβ literallyflags, bestie πnumβnumidβiddataβdatatypeβtypetosβtosmetricβmetricpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_ospfv2_lsa_sum
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsa_sum (uint32_t nmask,
uint32_t metric, uint32_t tos, const uint8_t * payload, uint32_t
payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters:
nmaskβnmaskmetricβmetrictosβtospayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_ospfv2_lsr
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsr (uint32_t type, uint32_t
lsid, uint32_t advrtr, const uint8_t * payload, uint32_t payload_s,
libnet_t * l, libnet_ptag_t ptag)
Parameters:
typeβtypelsidβlsidadvrtrβadvrtrpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_ospfv2_lsu
LIBNET_API libnet_ptag_t libnet_build_ospfv2_lsu (uint32_t num, const
uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Parameters:
numβnumpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_rip
LIBNET_API libnet_ptag_t libnet_build_rip (uint8_t cmd, uint8_t version,
uint16_t rd, uint16_t af, uint16_t rt, uint32_t addr, uint32_t mask,
uint32_t next_hop, uint32_t metric, const uint8_t * payload, uint32_t
payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds a Routing Information Protocol header (RFCs 1058 and 2453). π¦
Parameters:
cmdβ commandversionβ protocol versionrdβ version one:0, version two: routing domainafβ address familyrtβ version one:0, version two: route tagaddrβ IPv4 addressmaskβ version one:0, version two: subnet masknext_hopβ version one:0, version two: next hop addressmetricβ routing metricpayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_rpc_call
LIBNET_API libnet_ptag_t libnet_build_rpc_call (uint32_t rm, uint32_t xid,
uint32_t prog_num, uint32_t prog_vers, uint32_t procedure, uint32_t
cflavor, uint32_t clength, uint8_t * cdata, uint32_t vflavor, uint32_t
vlength, const uint8_t * vdata, const uint8_t * payload, uint32_t
payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an Remote Procedure Call (Version 2) Call message header as specified in RFC 1831. This builder provides the option for specifying the record marking which is required when used with streaming protocols (TCP). π
Parameters:
rmβ record marking indicating the position in a stream,0otherwisexidβ transaction identifier used to link calls and repliesprog_numβ remote program specification typically between0-1fffffffprog_versβ remote program version specificationprocedureβ procedure to be performed by remote programcflavorβ authentication credential typeclengthβ credential length (should be0)cdataβ opaque credential data (currently unused)vflavorβ authentication verifier typevlengthβ verifier length (should be0)vdataβ opaque verifier data (currently unused)payloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_sebek
LIBNET_API libnet_ptag_t libnet_build_sebek (uint32_t magic, uint16_t
version, uint16_t type, uint32_t counter, uint32_t time_sec, uint32_t
time_usec, uint32_t pid, uint32_t uid, uint32_t fd, uint8_t
cmd[SEBEK_CMD_LENGTH], uint32_t length, const uint8_t * payload,
uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds a Sebek header. The Sebek protocol was designed by the Honeynet Project as a transport mechanism for post-intrusion forensic data. More information may be found here: http://www.honeynet.org/papers/sebek.pdf. π΅οΈββοΈ
Parameters:
magicβ identify packets that should be hiddenversionβ protocol version, currently1typeβ type of record (read data is type0, write data is type1)counterβ PDU counter used to identify when packet are losttime_secβ seconds since EPOCH according to the honeypottime_usecβ residual microsecondspidβ PIDuidβ UIDfdβ FDcmdβ 12 first characters of the commandlengthβ length in bytes of the PDU's bodypayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_stp_conf
LIBNET_API libnet_ptag_t libnet_build_stp_conf (uint16_t id, uint8_t
version, uint8_t bpdu_type, uint8_t flags, const uint8_t * root_id,
uint32_t root_pc, const uint8_t * bridge_id, uint16_t port_id, uint16_t
message_age, uint16_t max_age, uint16_t hello_time, uint16_t f_delay,
const uint8_t * payload, uint32_t payload_s, libnet_t * l, libnet_ptag_t
ptag)
Builds an IEEE 802.1d Spanning Tree Protocol (STP) configuration header. STP frames are usually encapsulated inside of an 802.2 + 802.3 frame combination. π³
Parameters:
idβ protocol idversionβ protocol versionbpdu_typeβ bridge protocol data unit typeflagsβ flagsroot_idβ root idroot_pcβ root path costbridge_idβ bridge idport_idβ port idmessage_ageβ message agemax_ageβ max agehello_timeβ hello timef_delayβ forward delaypayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_stp_tcn
LIBNET_API libnet_ptag_t libnet_build_stp_tcn (uint16_t id, uint8_t version,
uint8_t bpdu_type, const uint8_t * payload, uint32_t payload_s, libnet_t
* l, libnet_ptag_t ptag)
Builds an IEEE 802.1d Spanning Tree Protocol (STP) topology change notification header. STP frames are usually encapsulated inside of an 802.2 + 802.3 frame combination. π³
Parameters:
idβ protocol idversionβ protocol versionbpdu_typeβ bridge protocol data unit typepayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_tcp
LIBNET_API libnet_ptag_t libnet_build_tcp (uint16_t sp, uint16_t dp,
uint32_t seq, uint32_t ack, uint8_t control, uint16_t win, uint16_t sum,
uint16_t urg, uint16_t len, const uint8_t * payload, uint32_t payload_s,
libnet_t * l, libnet_ptag_t ptag)
Builds an RFC 793 Transmission Control Protocol (TCP) header. π₯
Parameters:
spβ source portdpβ destination portseqβ sequence numberackβ acknowledgement numbercontrolβ control flagswinβ window sizesumβ checksum (0for libnet to auto-fill)urgβ urgent pointerlenβ total length of the TCP packet (for checksum calculation)payloadβpayloadpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_tcp_options
LIBNET_API libnet_ptag_t libnet_build_tcp_options (const uint8_t * options,
uint32_t options_s, libnet_t * l, libnet_ptag_t ptag)
Builds an RFC 793 Transmission Control Protocol (TCP) options header. The function expects options to be a valid TCP options string of size options_s, which is no larger than 40 bytes (the maximum size of an options string). The function checks to ensure that the packet consists of a TCP header preceded by an IPv4 header, and that the addition of the options string would not result in a packet larger than 65,535 bytes (IPMAXPACKET). The function counts up the number of 32-bit words in the options string and adjusts the TCP header length value as necessary. π
Parameters:
optionsβ byte string of TCP optionsoptions_sβ length of options stringlβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns: protocol tag value on success β¨
Return values: -1 on error π
libnet_build_token_ring
LIBNET_API libnet_ptag_t libnet_build_token_ring (uint8_t ac, uint8_t fc,
const uint8_t * dst, const uint8_t * src, uint8_t dsap, uint8_t ssap,
uint8_t cf, const uint8_t * oui, uint16_t type, const uint8_t * payload,
uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds a token ring header. π«
Parameters πΈ
okay so here's everything you can hand this builder, bestie β every single one, no skips:
acβ access controlfcβ frame controldstβ destination addresssrcβ source addressdsapβ destination service access pointssapβ source service access pointcfβ control fieldouiβ Organizationally Unique Identifiertypeβ upper layer protocol typepayloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_udld_device_id() π¦
LIBNET_API libnet_ptag_t libnet_build_udld_device_id (const uint8_t * value,
const uint8_t value_s, libnet_t * l, libnet_ptag_t ptag)
Builds an UniDirectional Link Detection (UDLD) Device ID TLV. yes, a whole TLV just for saying "hi, this is my device id" π
Parameters
valueβ device id (ASCII character string)value_sβ device id (ASCII character string) lengthlβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_udld_device_name() π
LIBNET_API libnet_ptag_t libnet_build_udld_device_name (const uint8_t *
value, const uint8_t value_s, libnet_t * l, libnet_ptag_t ptag)
Builds an UniDirectional Link Detection (UDLD) Device Name TLV β like the device id's glow-up, it's the name name.
Parameters
valueβ device name (ASCII character string)value_sβ device name lengthlβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_udld_echo() π
LIBNET_API libnet_ptag_t libnet_build_udld_echo (const uint8_t * value,
const uint8_t value_s, libnet_t * l, libnet_ptag_t ptag)
Builds an UniDirectional Link Detection (UDLD) Echo TLV. it's giving "hey, you still there??" energy fr fr.
Parameters
valueβ list of ID pairsvalue_sβ ID pairs lengthlβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_udld_hdr() π
LIBNET_API libnet_ptag_t libnet_build_udld_hdr (uint8_t version, uint8_t
opcode, uint8_t flags, uint8_t checksum, const uint8_t * payload,
uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an UniDirectional Link Detection (UDLD) header. UDLD frames are usually encapsulated inside of an 802.2 + 802.3 frame combination. so like, nesting dolls but for packets πͺ
Parameters
versionβ UDLD PDU version numberopcodeβ operation codeflagsβ flagschecksumβ checksum (0for libnet to auto-fill)payloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_udld_message_interval() β
LIBNET_API libnet_ptag_t libnet_build_udld_message_interval (const uint8_t *
value, libnet_t * l, libnet_ptag_t ptag)
Builds an UniDirectional Link Detection (UDLD) Message Interval TLV.
Parameters
valueβ time interval (8-bit unsigned integer)lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_udld_port_id() π
LIBNET_API libnet_ptag_t libnet_build_udld_port_id (const uint8_t * value,
const uint8_t value_s, libnet_t * l, libnet_ptag_t ptag)
Builds an UniDirectional Link Detection (UDLD) Port ID TLV.
Parameters
valueβ port id (ASCII character string)value_sβ port id (ASCII character string) lengthlβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_udld_sequence_number() π§
LIBNET_API libnet_ptag_t libnet_build_udld_sequence_number (const uint8_t *
value, libnet_t * l, libnet_ptag_t ptag)
Builds an UniDirectional Link Detection (UDLD) Sequence Number TLV.
Parameters
valueβ sequence number (32-bit unsigned integer)lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_udld_timeout_interval() π
LIBNET_API libnet_ptag_t libnet_build_udld_timeout_interval (const uint8_t *
value, libnet_t * l, libnet_ptag_t ptag)
Builds an UniDirectional Link Detection (UDLD) Timeout Interval TLV.
Parameters
valueβ timeout interval (8-bit unsigned integer)lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_udp() π
LIBNET_API libnet_ptag_t libnet_build_udp (uint16_t sp, uint16_t dp,
uint16_t len, uint16_t sum, const uint8_t * payload, uint32_t payload_s,
libnet_t * l, libnet_ptag_t ptag)
Builds an RFC 768 User Datagram Protocol (UDP) header. the classic. the moment. the icon π«Ά
Parameters
spβ source portdpβ destination portlenβ total length of the UDP packetsumβ checksum (0for libnet to auto-fill)payloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_build_vrrp() π₯
LIBNET_API libnet_ptag_t libnet_build_vrrp (uint8_t version, uint8_t type,
uint8_t vrouter_id, uint8_t priority, uint8_t ip_count, uint8_t
auth_type, uint8_t advert_int, uint16_t sum, const uint8_t * payload,
uint32_t payload_s, libnet_t * l, libnet_ptag_t ptag)
Builds an RFC 2338 Virtual Router Redundacy Protool (VRRP) header. (yes, the manpage really spells it "Protool" β we keep the lore exactly as it is π)
Use the payload interface to specify address and authentication information.
And listen, if you want your packet to be "legal", the vibes have to be exactly this: the destination IPv4 address should be the multicast address 224.0.0.18, the IP TTL should be set to 255, and the IP protocol should be set to 112. no cap, those three are the assignment π
Parameters
versionβ VRRP version (should be2)typeβ VRRP packet type (should be1-- ADVERTISEMENT)vrouter_idβ virtual router identificationpriorityβ priority (higher numbers indicate higher priority)ip_countβ number of IPv4 addresses contained in this advertisementauth_typeβ type of authentication (0,1,2-- see RFC)advert_intβ interval between advertisementssumβ checksum (0for libnet to autofill)payloadβ optional payload orNULLpayload_sβ payload length or0lβ pointer to a libnet contextptagβ protocol tag to modify an existing header,0to build a new one
Returns
protocol tag value on success β¨
Return values
-1 on error π
libnet_clear_packet() πΈ
LIBNET_API void libnet_clear_packet (libnet_t * l)
Clears the current packet referenced and frees all pblocks. You should call this whenever you wanna send a completely new packet of a different type using the same context. it's the "new year, new me" function bestie π
Parameters
lβ pointer to a libnet context
libnet_cq_add() π
int libnet_cq_add (libnet_t * l, char * label)
[Context Queue] Adds a new context to the libnet context queue. If no queue exists, this function will create the queue and add the specified libnet context as the first entry on the list.
The functions checks to ensure niether l nor label are NULL, and that label doesn't refer to an existing context already in the queue. (and yes, "niether" is a typo in the source and we are preserving it, icon behaviour π)
Additionally, l should refer to a libnet context previously initialized with a call to libnet_init(). If the context queue in write locked, this function will fail.
Parameters
lβ pointer to a libnet contextlabelβ a canonical name given to recognize the new context, no longer thanLIBNET_LABEL_SIZE
Return values
1on success β¨-1on failure π
libnet_cq_destroy() π¦
LIBNET_API void libnet_cq_destroy (void )
[Context Queue] Destroys the entire context queue, calling libnet_destroy() on each member context. it's the group-chat delete-everything move.
libnet_cq_end_loop() β
LIBNET_API uint32_t libnet_cq_end_loop (void )
[Context Queue] Cleanup from iterating through the context queue.
Return values
1β Cleanup completed OK β0β failed clearing the write lock π
libnet_cq_find_by_label() π
LIBNET_API libnet_t * libnet_cq_find_by_label (char * label)
[Context Queue] Locates a libnet context from the queue, indexed by a canonical label.
Parameters
labelβ canonical label of the libnet context to retrieve
Returns
the expected libnet context β¨
Return values
NULL on failure π
libnet_cq_getlabel() π
LIBNET_API const char * libnet_cq_getlabel (libnet_t * l)
[Context Queue] Returns the canonical label associated with the context.
Parameters
lβ pointer to a libnet context
Returns
pointer to the libnet context's label β¨
libnet_cq_head() π
LIBNET_API libnet_t * libnet_cq_head (void )
[Context Queue] Intiailizes the interator interface and set a write lock on the entire queue. (another source typo, another preservation moment, we love consistency π )
This function is intended to be called just prior to interating through the entire list of contexts (with the probable intent of inject a series of packets in rapid succession). This function is often used as per the following:
for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next()) { ...
}
Much of the time, the application programmer will use the iterator as it is written above; as such, libnet provides a macro to do exactly that, for_each_context_in_cq(l).
β οΈ Warning: do not call the iterator more than once in a single loop. fr fr, once. not twice. π ββοΈ
Returns
the head of the context queue β¨
libnet_cq_last() π
LIBNET_API int libnet_cq_last (void )
[Context Queue] Check whether the iterator is at the last context in the queue.
Return values
1if at the end of the context queue0otherwise
libnet_cq_next() π§
LIBNET_API libnet_t * libnet_cq_next (void )
[Context Queue] Get next context from the context queue.
Returns
the next context from the context queue β¨
libnet_cq_remove() π
LIBNET_API libnet_t * libnet_cq_remove (libnet_t * l)
[Context Queue] Removes a specified context from the libnet context queue by specifying the libnet context pointer.
Note the function will remove the specified context from the context queue and cleanup internal memory from the queue, it is up to the application programmer to free the returned libnet context with a call to libnet_destroy(). yeah bestie, cleanup is on YOU, this function just unhooks it π«Ά
Also, as it is not necessary to keep the libnet context pointer when initially adding it to the context queue, most application programmers will prefer to refer to entries on the context queue by canonical name and would use libnet_cq_remove_by_label(). If the context queue is write locked, this function will fail.
Parameters
lβ pointer to a libnet context
Returns
the pointer to the removed libnet context β¨
Return values
NULL on failure π
libnet_cq_remove_by_label
LIBNET_API libnet_t * libnet_cq_remove_by_label (char * label)
[Context Queue] okay bestie, this one yeets a specific context out of the libnet context queue, and you pick which one by its canonical name. Real talk tho: it pulls the context out of the queue and cleans up the queue's internal memory, but the returned libnet context is still yours to free β you have to call libnet_destroy() yourself. Not optional, not a vibe, just do it. And if the context queue is write locked? This function will fail. Periodt. π
Parameters
labelβ the canonical name of the context to remove
Returns
- a pointer to the removed libnet context β¨
Return values
NULLon failure
libnet_cq_size
LIBNET_API uint32_t libnet_cq_size (void )
[Context Queue] returns the number of libnet contexts chillin' in the queue. That's it, that's the function. Headcount time π
Returns
- the number of libnet contexts currently in the queue
libnet_destroy
LIBNET_API void libnet_destroy (libnet_t * l)
shuts down the libnet session referenced by l. It closes the network interface and frees all the internal memory structures associated with l. The final goodbye, the clean exit, the "okay we're done here" π¦
Parameters
lβ pointer to a libnet context
libnet_diag_dump_context
LIBNET_API void libnet_diag_dump_context (libnet_t * l)
[Diagnostic] prints the contents of the given context. Peek behind the curtain, bestie πΈ
Parameters
lβ pointer to a libnet context
libnet_diag_dump_hex
void libnet_diag_dump_hex (const uint8_t * packet, uint32_t len, int swap,
FILE * stream)
[Diagnostic] prints the contents of the supplied buffer to the supplied stream pointer. It'll swap endianness based on the disposition of the mode variable. Super useful when you're rolling with the advanced interface and a culled packet. π₯
Parameters
packetβ the packet to printlenβ length of the packet in bytesswapβ1to swap byte order,0to not. Counter-intuitively, it is necessary to swap in order to see the byte order as it is on the wire (this may be a bug). πstreamβ a stream pointer to print to
libnet_diag_dump_pblock
LIBNET_API void libnet_diag_dump_pblock (libnet_t * l)
[Diagnostic] prints the contents of every single pblock. All of them. No skips. π
Parameters
lβ pointer to a libnet context
libnet_diag_dump_pblock_type
LIBNET_API char * libnet_diag_dump_pblock_type (uint8_t type)
[Diagnostic] hands you the canonical name of the pblock type. Name-drop szn β¨
Parameters
typeβ pblock type
Returns
- a string representing the pblock type
type
Return values
unknownfor an unknown value
libnet_get_hwaddr
LIBNET_API struct libnet_ether_addr * libnet_get_hwaddr (libnet_t * l)
returns the MAC address for the device libnet was initialized with. If libnet was initialized without a device, this function will attempt to find one for you. And if it fails and returns NULL? A call to libnet_geterror() will tell you why, bestie π«Ά
Parameters
lβ pointer to a libnet context
Returns
- a pointer to the MAC address or
NULL
libnet_get_ipaddr4
LIBNET_API uint32_t libnet_get_ipaddr4 (libnet_t * l)
returns the IP address for the device libnet was initialized with. If libnet was initialized without a device (in raw socket mode) the function will attempt to find one. If it fails and returns -1, a call to libnet_geterrror() will tell you why. (yes, that spelling is straight from the docs β don't @ me π)
Parameters
lβ pointer to a libnet context
Returns
- a big endian IP address suitable for use in a
libnet_buildfunction
Return values
-1
libnet_get_ipaddr6
LIBNET_API struct libnet_in6_addr libnet_get_ipaddr6 (libnet_t * l)
returns the IPv6 address for the device libnet was initialized with. If libnet was initialized without a device (in raw socket mode) the function will attempt to find one. If it fails and returns in6addr_error, a call to libnet_geterrror() will tell you why. Heads up: this function is not yet implemented for Win32 platforms. π
Parameters
lβ pointer to a libnet context
Return values
in6addr_erroron failure
References libnet_get_ipaddr6().
Referenced by libnet_get_ipaddr6().
libnet_get_prand
LIBNET_API uint32_t libnet_get_prand (int mod)
generates an unsigned pseudo-random value within the range specified by mod. Here's the tea on the ranges, bestie: π
LIBNET_PR2β 0 - 1LIBNET_PR8β 0 - 255LIBNET_PR16β 0 - 32767LIBNET_PRu16β 0 - 65535LIBNET_PR32β 0 - 2147483647LIBNET_PRu32β 0 - 4294967295
Parameters
modβ one the ofLIBNET_PR*constants
Return values
1on success-1on failure
libnet_getdevice
LIBNET_API const char * libnet_getdevice (libnet_t * l)
returns the canonical name of the device used for packet injection. π
Parameters
lβ pointer to a libnet context
Returns
- the canonical name of the device used for packet injection. Note it can be
NULLwithout being an error. π
libnet_geterror
LIBNET_API char * libnet_geterror (libnet_t * l)
returns the last error set inside of the referenced libnet context. Bestie, call this anytime a function fails or an error condition is detected inside of libnet. It's your little detective π΅οΈβοΈ
Parameters
lβ pointer to a libnet context
Returns
- an error string or
NULLif no error has occurred
libnet_getfd
LIBNET_API int libnet_getfd (libnet_t * l)
returns the FILENO of the file descriptor used for packet injection. Main character fd energy π
Parameters
lβ pointer to a libnet context
Returns
- the file number of the file descriptor used for packet injection
libnet_getgre_length
LIBNET_API uint32_t libnet_getgre_length (uint16_t fv)
Parameters
fvβ seelibnet_build_gre().
Returns
size
See also
libnet_build_gre().
libnet_getpacket_size
LIBNET_API uint32_t libnet_getpacket_size (libnet_t * l)
returns the sum of the size of all of the pblocks inside of l β which should be the resulting packet size. Math but make it slay β¨
Parameters
lβ pointer to a libnet context
Returns
- the size of the packet in
l
libnet_getpbuf
LIBNET_API uint8_t * libnet_getpbuf (libnet_t * l, libnet_ptag_t ptag)
returns the pblock buffer contents for the specified ptag. Lowkey important: you should make a subsequent call to libnet_getpbuf_size() to figure out how big that buffer actually is. Don't skip that step π«Ά
Parameters
lβ pointer to a libnet contextptagβ the ptag reference number
Returns
- a pointer to the pblock buffer or
NULLon error
libnet_getpbuf_size
LIBNET_API uint32_t libnet_getpbuf_size (libnet_t * l, libnet_ptag_t ptag)
returns the pblock buffer size for the specified ptag. And yes bestie, you should've already made a previous call to libnet_getpbuf() to actually pull the buffer contents. They're a duo, they come together π
Parameters
lβ pointer to a libnet contextptagβ the ptag reference number
Returns
- the size of the pblock buffer
libnet_hex_aton
LIBNET_API uint8_t * libnet_hex_aton (const char * s, int * len)
takes a colon separated hexidecimal address (like straight off the command line) and returns a bytestring suitable for use in a libnet_build function. Real talk tho: this function performs an implicit malloc, so the return value should be freed after you're done with it. Free your memory, free your soul π¦
Parameters
sβ the string to be parsedlenβ the resulting size of the returned byte string
Returns
- a byte string or
NULLon failure
libnet_in6_is_error
LIBNET_API int libnet_in6_is_error (struct libnet_in6_addr addr)
checks a libnet_in6_addr structure for identity with in6addr_error. Is it the error boi or not, we're finding out π
Parameters
addrβ address to check
Return values
1ifaddrisin6addr_error0if it is not
libnet_init
LIBNET_API libnet_t * libnet_init (int injection_type, const char * device,
char * err_buf)
creates the libnet environment. It initializes the library and returns a libnet context β the whole origin story of your packet journey, bestie π
If the injection_type is LIBNET_LINK or LIBNET_LINK_ADV, the function initializes the injection primitives for the link-layer interface, enabling the application programmer to build packets starting at the data-link layer (which also provides more granular control over the IP layer). If libnet uses the link-layer and the device argument is non-NULL, the function attempts to use the specified network device for packet injection. That can be either a canonical string that references the device (such as "eth0" for a 100MB Ethernet card on Linux or "fxp0" for a 100MB Ethernet card on OpenBSD) or the dots and decimals representation of the device's IP address (192.168.0.1). If device is NULL, libnet attempts to find a suitable device to use on its own.
If the injection_type is LIBNET_RAW4 or LIBNET_RAW4_ADV, the function initializes the injection primitives for the IPv4 raw socket interface.
The final argument, err_buf, should be a buffer of size LIBNET_ERRBUF_SIZE and holds an error message if the function fails.
This function requires root privileges to execute successfully. No root, no vibes, no packets.
Upon success, the function returns a valid libnet context for use in later function calls; upon failure, the function returns NULL.
Parameters
injection_typeβ packet injection type (LIBNET_LINK,LIBNET_LINK_ADV,LIBNET_RAW4,LIBNET_RAW4_ADV,LIBNET_RAW6,LIBNET_RAW6_ADV)deviceβ the interface to use (NULLand libnet will choose one)err_bufβ will contain an error message on failure
Returns
- libnet context ready for use or
NULLon error.
libnet_name2addr4
LIBNET_API uint32_t libnet_name2addr4 (libnet_t * l, const char * host_name,
uint8_t use_name)
takes a dotted decimal string or a canonical DNS name and returns a network byte ordered IPv4 address. This may incur a DNS lookup if mode is set to LIBNET_RESOLVE and host_name refers to a canonical DNS name. If mode is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The function can fail if DNS lookup fails, or if mode is set to LIBNET_DONT_RESOLVE and host_name refers to a canonical DNS name. π
Parameters
lβ pointer to a libnet contexthost_nameβ pointer to a string containing a presentation format host nameuse_nameβLIBNET_RESOLVEorLIBNET_DONT_RESOLVE
Returns
- address in network byte order
Return values
-1(2^32 - 1) on error
libnet_name2addr6
LIBNET_API struct libnet_in6_addr libnet_name2addr6 (libnet_t * l, const
char * host_name, uint8_t use_name)
takes a dotted decimal string or a canonical DNS name and returns a network byte ordered IPv6 address. This may incur a DNS lookup if mode is set to LIBNET_RESOLVE and host_name refers to a canonical DNS name. If mode is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The function can fail if DNS lookup fails, or if mode is set to LIBNET_DONT_RESOLVE and host_name refers to a canonical DNS name. Same energy as the v4 one, but make it six πΈ
Parameters
lβ pointer to a libnet contexthost_nameβ pointer to a string containing a presentation format host nameuse_nameβLIBNET_RESOLVEorLIBNET_DONT_RESOLVE
Returns
- network byte ordered IPv6 address structure
References libnet_name2addr6().
Referenced by libnet_name2addr6().
libnet_plist_chain_dump
LIBNET_API int libnet_plist_chain_dump (libnet_plist_t * plist)
runs through the port list and prints the contents of the port list chain list to stdout. A little port list show-and-tell π
Parameters
plistβ previously created portlist
Return values
1on success-1on failure
π libnet_plist_chain_dump_string
LIBNET_API char * libnet_plist_chain_dump_string (libnet_plist_t * plist)
Okay bestie, so this one runs through your port list and prints the whole contents of the port list chain list into a string. Cute, right? NOT SO FAST. This function uses strdup and is not re-entrant. It also has a memory leak and should not really be used. Like, the manpage itself is telling you to not use it. That's the loudest red flag in the whole doc, periodt. π©
Parameters
plistβ previously created portlist
Returns
- a printable string containing the port list contents on success, or
NULLon error
π libnet_plist_chain_free
LIBNET_API int libnet_plist_chain_free (libnet_plist_t * plist)
Frees all memory associated with the port list chain. Cleanup era, we love to see it π§Ήβ¨
Parameters
plistβ previously created portlist
Return values
1on success-1on failure
π libnet_plist_chain_new
LIBNET_API int libnet_plist_chain_new (libnet_t * l, libnet_plist_t ** plist, char * token_list)
Creates a new port list. Port list chains are so useful for TCP and UDP-based applications that need to send packets to a range of ports (contiguous or otherwise). The port list chain that token_list points to should contain a series of int8_tacters β yes, that's a typo in the original and we're keeping it, no notes π β from the following list:
"0123456789,-"
of the general format "x - y, z", where "xyz" are port numbers between 0 and 65,535. plist points to the front of the port list chain list, for use in further libnet_plist_chain() functions. Upon success, the function returns 1. Upon failure, the function returns -1 and libnet_geterror() can tell you why. π
Parameters
lβ pointer to a libnet contextplistβ if successful, will refer to the portlist; if not,NULLtoken_listβ string containing the port list primitive
Return values
1on success-1on failure
π libnet_plist_chain_next_pair
LIBNET_API int libnet_plist_chain_next_pair (libnet_plist_t * plist, uint16_t * bport, uint16_t * eport)
Returns the next port list chain pair from the port list chain plist. bport and eport contain the starting port number and ending port number, respectively. Upon success, the function returns 1 and fills in the port variables. However β plot twist β if the list is empty, the function returns 0 and sets both port variables to 0. Upon failure, the function returns -1. Three whole outcomes, she's versatile π
Parameters
plistβ previously created portlistbportβ will contain the beginning port number, or0eportβ will contain the ending port number, or0
Return values
1on success0if empty-1on failure
π libnet_seed_prand
LIBNET_API int libnet_seed_prand (libnet_t * l)
Seeds the pseudo-random number generator. That's it. That's the whole function. Chaos, but make it deliberate π²
Parameters
lβ pointer to a libnet context
Return values
1on success-1on failure
π libnet_stats
LIBNET_API void libnet_stats (libnet_t * l, struct libnet_stats * ls)
Fills in a libnet_stats structure with packet injection statistics: packets written, bytes written, and packet sending errors. Receipts, basically. π§Ύ
Parameters
lβ pointer to a libnet contextlsβ pointer to a libnet statistics structure
References libnet_stats().
Referenced by libnet_stats().
Yes bestie, she references herself and is referenced by herself. Main character energy fr fr. π
π libnet_toggle_checksum
LIBNET_API int libnet_toggle_checksum (libnet_t * l, libnet_ptag_t ptag, int mode)
Okay so this is the checksum vibe check. Here's the lore: if a given protocol header is built with the checksum field set to "0", by default libnet will calculate the header checksum prior to injection. If the header is set to any other value, by default libnet will not calculate the header checksum. To over-ride this behavior, use libnet_toggle_checksum().
It switches auto-checksumming on or off for the specified ptag. If mode is set to LIBNET_ON, libnet will mark the specified ptag to calculate a checksum for the ptag prior to injection. This assumes that the ptag refers to a protocol that has a checksum field. If mode is set to LIBNET_OFF, libnet will clear the checksum flag and no checksum will be computed prior to injection. This assumes that the programmer will assign a value (zero or otherwise) to the checksum field. Often times this is useful if a precomputed checksum or some other predefined value is going to be used.
β οΈ Note that when libnet is initialized with LIBNET_RAW4, the IPv4 header checksum will always be computed by the kernel prior to injection, regardless of what the programmer sets. No take-backs, the kernel decides. π
Parameters
lβ pointer to a libnet contextptagβ the ptag reference numbermodeβLIBNET_ONorLIBNET_OFF
Return values
1on success-1on failure
π libnet_version
LIBNET_API const char * libnet_version (void )
Returns the version of libnet. Short, sweet, iconic. π
Returns
- the libnet version
π libnet_write
LIBNET_API int libnet_write (libnet_t * l)
Writes a prebuilt packet to the network. βοΈ This function assumes that l was previously initialized (via a call to libnet_init()) and that a previously constructed packet has been built inside this context (via one or more calls to the libnet_build* family of functions) and is ready to go.
Depending on how libnet was initialized, the function will write the packet to the wire either via the raw or link layer interface. The function will also bump up the internal libnet stat counters, which are retrievable via libnet_stats().
Parameters
lβ pointer to a libnet context
Returns
- the number of bytes written
Return values
-1on error
π SEE ALSO
π«Ά AUTHORS
The original author of libnet is Mike D. Schiffman.
libnet has been maintained and extensively enhanced since 2009 by Sam Roberts.
It is maintained by the Libnet Developer Community at GitHub.
<https://github.com/libnet/libnet>
π BUGS
Suggestions, bug reports/fixes, and pull requests, see:
<https://github.com/libnet/libnet/issues>
βοΈ COPYRIGHT
libnet is licensed under the 2-Clause BSD License.
π SEE ALSO
π«Ά AUTHORS
The original author of libnet is Mike D. Schiffman.
libnet has been maintained and extensively enhanced since 2009 by Sam Roberts.
It is maintained by the Libnet Developer Community at GitHub.
<https://github.com/libnet/libnet>
π BUGS
Suggestions, bug reports/fixes, and pull requests, see:
<https://github.com/libnet/libnet/issues>
βοΈ COPYRIGHT
libnet is licensed under the 2-Clause BSD License.
Not me noticing the page says SEE ALSO, AUTHORS, BUGS and COPYRIGHT twice β and bestie, we keep every detail around here, so you get both rounds. Double the credit, double the love. π
And that's a wrap on the whole page, fr fr β this came from the libnet Programmers Guide, version libnet-1.3, and the page itself is libnet-functions.h(3). Thank you for reading all 13 parts with me, you're literally the bestie of all time πβ¨π
π¦ where this page comes from
- fedora 43: libnet-devel 1.3-6.fc43 Β· BSD-2-Clause AND BSD-3-Clause
- fedora 43: libnet-devel 1.3-6.fc43 Β· BSD-2-Clause AND BSD-3-Clause
- fedora 44: libnet-devel 1.3-7.fc44 Β· BSD-2-Clause AND BSD-3-Clause
- fedora 44: libnet-devel 1.3-7.fc44 Β· BSD-2-Clause AND BSD-3-Clause
- opensuse-leap 16.0: libnet-devel 1.3-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libnet-devel 1.3-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libnet-devel 1.3-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libnet-devel 1.3-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libnet-doc 1.3-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libnet-doc 1.3-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libnet-doc 1.3-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libnet-doc 1.3-160000.3.2 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms