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 a struct 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 given libnet_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 by mod 🎲
  • libnet_toggle_checksum β€” flip checksums on/off for a ptag 🧚

🌐 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 into host_name (max host_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 from token_list 🌸
  • libnet_plist_chain_next_pair β€” iterate the next bport/eport pair πŸ”
  • 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.

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_neighbor is the ONE in this whole list that's missing the LIBNET_API prefix. 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 that marker is a fixed-size array β€” LIBNET_BGP4_MARKER_SIZE is baked into the type, no cap. and reachability_info is a non-const uint8_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. 🌈

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_add is the only one in that whole connection-queue lineup without LIBNET_API in front of it. same deal as libnet_build_ospfv2_hello_neighbor earlier. 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 address
  • use_name β€” LIBNET_RESOLVE or LIBNET_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 convert
  • use_name β€” LIBNET_RESOLVE or LIBNET_DONT_RESOLVE
  • host_name β€” Buffer to return result in
  • host_name_len β€” Length of host_name buffer

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 context
  • ptag β€” the ptag referencing the header to pull
  • header β€” will contain the header
  • header_s β€” will contain the header size

Return values

  • 1 on success
  • -1 on 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 implicit malloc(), so you gotta make a corresponding call to libnet_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 context
  • packet β€” will contain the wire-ready packet
  • packet_s β€” will contain the packet size

Return values

  • 1 on success
  • -1 on 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 context
  • packet β€” a pointer to the packet to free

[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 context
  • packet β€” a pointer to the packet to inject
  • packet_s β€” the size of the packet

Returns

  • the number of bytes written

Return values

  • -1 on 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 context
  • packet β€” a pointer to the packet to inject
  • packet_s β€” the size of the packet

Returns

  • the number of bytes written

Return values

  • -1 on 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 type
  • sha β€” sender's hardware address
  • spa β€” sender's protocol address
  • tha β€” target hardware address
  • tpa β€” target protocol address
  • l β€” pointer to a libnet context

Returns

  • protocol tag value on success

Return values

  • -1 on 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 address
  • type β€” upper layer protocol type
  • l β€” pointer to a libnet context

Returns

  • protocol tag value on success

Return values

  • -1 on 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 priority
  • dst β€” destination fddi address
  • dsap β€” destination service access point
  • ssap β€” source service access point
  • cf β€” cf
  • oui β€” IEEE organizational code
  • type β€” upper layer protocol
  • l β€” pointer to a libnet context

Returns

  • protocol tag value on success

Return values

  • -1 on 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 data
  • prot β€” upper layer protocol
  • dst β€” destination IPv4 address (little endian)
  • l β€” pointer to a libnet context

Returns

  • protocol tag value on success

Return values

  • -1 on 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 β€” length
  • nh β€” next header
  • dst β€” destination IPv6 address
  • l β€” pointer to a libnet context
  • ptag β€” protocol tag to modify an existing header, 0 to build a new one

Returns

  • protocol tag value on success

Return values

  • -1 on error

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 address
  • oui β€” Organizationally Unique Identifier (unused for Ethernet)
  • type β€” the upper layer protocol type
  • l β€” pointer to a libnet context

Returns

  • protocol tag value on success

Return values

  • -1 on 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 control
  • fc β€” frame control
  • dst β€” destination address
  • dsap β€” destination service access point
  • ssap β€” source service access point
  • cf β€” control field
  • oui β€” Organizationally Unique Identifier
  • type β€” upper layer protocol type
  • l β€” pointer to a libnet context

Returns

  • protocol tag value on success

Return values

  • -1 on 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:

  1. libnet_build_ntp()
  2. libnet_build_udp()
  3. libnet_build_ipv4()
  4. 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 address
  • src β€” pointer to a six byte destination ethernet address
  • tpi β€” tag protocol identifier
  • priority β€” priority
  • cfi β€” canonical format indicator
  • vlan_id β€” vlan identifier
  • len_proto β€” length (802.3) protocol (Ethernet II)
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 version
  • eap_type β€” the EAP type
  • length β€” frame length
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 point
  • ssap β€” source service access point
  • control β€” control field
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 point
  • ssap β€” source service access point
  • control β€” control field
  • oui β€” Organizationally Unique Identifier
  • type β€” upper layer protocol
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 address
  • src β€” source ethernet address
  • len β€” frame length sans header
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 format
  • pro β€” protocol address format
  • hln β€” hardware address length
  • pln β€” protocol address length
  • op β€” ARP operation type
  • sha β€” sender's hardware address
  • spa β€” sender's protocol address
  • tha β€” target hardware address
  • tpa β€” target protocol address
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 header
  • type β€” type code of the message (OPEN, UPDATE, NOTIFICATION or KEEPALIVE)
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 notification
  • err_subcode β€” more specific information about the reported error.
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 to 4)
  • src_as β€” Autonomous System of the sender
  • hold_time β€” used to compute the maximum allowed time between the receipt of KEEPALIVE, and/or UPDATE messages by the sender
  • bgp_id β€” BGP identifier of the sender
  • opt_len β€” total length of the optional parameters field in bytes
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 bytes
  • withdrawn_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 bytes
  • path_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 or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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

  • opcode
  • htype
  • hlen
  • hopcount
  • xid
  • secs
  • flags
  • cip
  • yip
  • sip
  • gip
  • chaddr β€” client hardware address, length is hlen
  • sname β€” server host name, a null terminated string
  • file β€” boot file name, a null terminated string
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” protocol tag to modify an existing header, 0 to 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

  • -1 on 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 version
  • ttl β€” time to live (time information should be cached by recipient)
  • sum β€” checksum (0 for libnet to auto-fill)
  • type β€” type of data contained in value
  • value_s β€” length of value argument
  • value β€” the CDP information string
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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

  • opcode
  • htype
  • hlen
  • hopcount
  • xid
  • secs
  • flags
  • cip
  • yip
  • sip
  • gip
  • chaddr β€” client hardware address, length is hlen
  • sname β€” server host name, a null terminated string
  • file β€” boot file name, a null terminated string
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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_len
  • id β€” DNS packet id
  • flags β€” control flags
  • num_q β€” number of questions
  • num_anws_rr β€” number of answer resource records
  • num_auth_rr β€” number of authority resource records
  • num_addi_rr β€” number of additional resource records
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 (0 for libnet to auto-fill).
  • offset β€” byte offset from the start of the routing field to the first byte of the SRE
  • key β€” inserted by the encapsulator to authenticate the source
  • seq β€” sequence number used by the receiver to sort the packets
  • len β€” size of the GRE packet
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 address
  • src β€” source ethernet address
  • type β€” upper layer protocol type
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 priority
  • dst β€” destination fddi address
  • src β€” source fddi address
  • dsap β€” destination service access point
  • ssap β€” source service access point
  • cf β€” cf
  • oui β€” 3 byte IEEE organizational code
  • type β€” upper layer protocol
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 bits 0 to 7 say which fields are included in the header (checksum, seq. number, key, ...), bits 8 to 12 are the flag, and bits 13 to 15 are the version πŸ‘‘
  • type β€” which protocol is encapsulated (PPP, IP, ...)
  • sum β€” checksum (0 for libnet to auto-fill) ✨
  • offset β€” byte offset from the start of the routing field to the first byte of the SRE
  • key β€” inserted by the encapsulator to authenticate the source πŸ”
  • seq β€” sequence number used by the receiver to sort the packets
  • len β€” size of the GRE packet
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 context
  • ptag β€” 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_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

  • af
  • offset
  • length
  • routing
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 messages
  • opcode β€” type of message
  • state β€” current state of the router
  • hello_time β€” period in seconds between hello messages πŸ‘‹
  • hold_time β€” seconds that the current hello message is valid
  • priority β€” priority for the election process πŸ—³οΈ
  • group β€” standby group
  • reserved β€” reserved field
  • authdata β€” password πŸ”
  • virtual_ip β€” virtual ip address
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ICMP_ECHOREPLY or ICMP_ECHO)
  • code β€” code of ICMP packet (should be 0)
  • sum β€” checksum (0 for libnet to auto-fill) ✨
  • id β€” identification number
  • seq β€” packet sequence number
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ICMP_MASKREQ or ICMP_MASKREPLY)
  • code β€” code of ICMP packet (should be 0)
  • sum β€” checksum (0 for libnet to auto-fill) ✨
  • id β€” identification number
  • seq β€” packet sequence number
  • mask β€” subnet mask
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ICMP_REDIRECT)
  • code β€” code of ICMP packet (should be one of the four redirect codes)
  • sum β€” checksum (0 for libnet to auto-fill) ✨
  • gateway
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ICMP_TIMXCEED)
  • code β€” code of ICMP packet (ICMP_TIMXCEED_INTRANS / ICMP_TIMXCEED_REASS)
  • sum β€” checksum (0 for libnet to auto-fill) ✨
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ICMP_TSTAMP or ICMP_TSTAMPREPLY)
  • code β€” code of ICMP packet (should be 0)
  • sum β€” checksum (0 for libnet to auto-fill) ✨
  • id β€” identification number
  • seq β€” sequence number
  • otime β€” originate timestamp
  • rtime β€” receive timestamp
  • ttime β€” transmit timestamp
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ICMP_UNREACH)
  • code β€” code of ICMP packet (should be one of the 16 unreachable codes)
  • sum β€” checksum (0 for libnet to auto-fill) ✨
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ICMP6_ECHO_REQUEST or ICMP6_ECHO_REPLY)
  • code β€” code of ICMP packet (should be zero)
  • sum β€” checksum (0 for libnet to auto-fill) ✨
  • id β€” echo id number
  • seq β€” echo sequence number
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ND_NEIGHBOR_ADVERT)
  • code β€” code of ICMP packet (should be zero)
  • sum β€” checksum (0 for libnet to auto-fill) ✨
  • flags β€” should be a bitwise or of any applicable ND_NA_FLAG_* flags
  • target β€” target ipv6 address
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ND_NEIGHBOR_SOLICIT)
  • code β€” code of ICMP packet (should be zero)
  • sum β€” checksum (0 for libnet to auto-fill)
  • target β€” target ipv6 address
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_icmpv6_ndp_opt() ✨

Builds ICMPv6 NDP options. little extra seasoning for your NDP packets, we love to see it πŸŽ€

Parameters

  • type β€” one of ND_OPT_* types
  • option β€” option data
  • option_s β€” size of option data (will be padded out to an 8-byte boundary)
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be ICMP6_DST_UNREACH)
  • code β€” code of ICMP packet (should be one of the 5 ICMP6_DST_UNREACH_* codes)
  • sum β€” checksum (0 for libnet to auto-fill)
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 type
  • reserved β€” (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 NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” protocol tag to modify an existing header, 0 to build a new one

Returns

  • protocol tag value on success

Return values

  • -1 on 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 header
  • len β€” payload length
  • res β€” reserved
  • spi β€” security parameter index
  • seq β€” sequence number
  • auth β€” authentication data
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_ipsec_esp_ftr() 🌸

Builds an Internet Protocol Security Encapsulating Security Payload footer. the lil outro of your ESP situation πŸ’œ

Parameters

  • len β€” padding length
  • nh β€” next header
  • auth β€” authentication data
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_ipsec_esp_hdr() πŸ¦‹

Builds an Internet Protocol Security Encapsulating Security Payload header. the main character counterpart to that footer above ✨

Parameters

  • spi β€” security parameter index
  • seq β€” ESP sequence number
  • iv β€” initialization vector
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 bits
  • id β€” IP identification number
  • frag β€” fragmentation bits and offset
  • ttl β€” time to live in the network
  • prot β€” upper layer protocol
  • sum β€” checksum (0 for libnet to auto-fill)
  • src β€” source IPv4 address (little endian)
  • dst β€” destination IPv4 address (little endian)
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 string
  • l β€” pointer to a libnet context
  • ptag β€” 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_ipv6() πŸ’–

Builds a version 6 RFC 2460 Internet Protocol (IP) header. the glow-up edition, we love her 🌈

Parameters

  • tc β€” traffic class
  • fl β€” flow label
  • len β€” total length of the IP packet
  • nh β€” next header
  • hl β€” hop limit
  • src β€” source IPv6 address
  • dst β€” destination IPv6 address
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 header
  • len β€” length of the header in 8-byte octets not including the first 8 octets
  • payload β€” options payload
  • payload_s β€” payload length
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 header
  • reserved β€” unused value... OR IS IT!
  • frag β€” fragmentation bits (ala ipv4)
  • id β€” packet identification
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 header
  • len β€” length of the header in 8-byte octets not including the first 8 octets
  • payload β€” options payload
  • payload_s β€” payload length
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 header
  • len β€” length of the header in 8-byte octets not including the first 8 octets
  • rtype β€” routing header type
  • segments β€” number of routing segments that follow
  • payload β€” optional payload of routing information
  • payload_s β€” payload length
  • l β€” pointer to a libnet context
  • ptag β€” 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 frame
  • user β€” user defined data
  • shost β€” source mac address
  • len β€” total length of the encapsulated packet less 18 bytes
  • snap β€” SNAP information (0xaaaa03 + vendor code)
  • vid β€” 15 bit VLAN ID, 1 bit BPDU or CDP indicator
  • portindex β€” port index
  • reserved β€” used for FDDI and token ring
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 address
  • src β€” the source MAC address
  • oui β€” Organizationally Unique Identifier (unused for Ethernet)
  • type β€” the upper layer protocol type
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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 Subtype
  • value β€” the Chassis ID string
  • value_s β€” length of value argument
  • l β€” pointer to a libnet context
  • ptag β€” 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 context
  • ptag β€” 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 string
  • value_s β€” length of value argument
  • l β€” pointer to a libnet context
  • ptag β€” 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 Subtype
  • value β€” the Port ID string
  • value_s β€” length of value argument
  • l β€” pointer to a libnet context
  • ptag β€” 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 seconds
  • l β€” pointer to a libnet context
  • ptag β€” 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 value
  • experimental β€” 3-bit reserved field
  • bos β€” 1-bit bottom of stack identifier
  • ttl β€” time to live
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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 indicator
  • version β€” NTP protocol version
  • mode β€” NTP mode
  • stratum β€” stratum
  • poll β€” polling interval
  • precision β€” precision
  • delay_int β€” delay interval
  • delay_frac β€” delay fraction
  • dispersion_int β€” dispersion interval
  • dispersion_frac β€” dispersion fraction
  • reference_id β€” reference id
  • ref_ts_int β€” reference timestamp integer
  • ref_ts_frac β€” reference timestamp fraction
  • orig_ts_int β€” original timestamp integer
  • orig_ts_frac β€” original timestamp fraction
  • rec_ts_int β€” receiver timestamp integer
  • rec_ts_frac β€” receiver timestamp fraction
  • xmt_ts_int β€” transmit timestamp integer
  • xmt_ts_frac β€” transmit timestamp integer
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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

  • len
  • type
  • rtr_id
  • area_id
  • sum
  • autype
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_len
  • opts
  • type
  • seqnum
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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

  • netmask
  • interval
  • opts
  • priority
  • dead_int
  • des_rtr
  • bkup_rtr
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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

  • netmask
  • interval
  • opts
  • priority
  • dead_int
  • des_rtr
  • bkup_rtr
  • neighbor
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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

  • age
  • opts
  • type
  • lsid
  • advrtr
  • seqnum
  • sum
  • len
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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

  • nmask
  • metric
  • fwdaddr
  • tag
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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 β€” the nmask value, periodt
  • rtrid β€” the rtrid value
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 β€” literally flags, bestie πŸ’…
  • num β€” num
  • id β€” id
  • data β€” data
  • type β€” type
  • tos β€” tos
  • metric β€” metric
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 β€” nmask
  • metric β€” metric
  • tos β€” tos
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 β€” type
  • lsid β€” lsid
  • advrtr β€” advrtr
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 β€” num
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 β€” command
  • version β€” protocol version
  • rd β€” version one: 0, version two: routing domain
  • af β€” address family
  • rt β€” version one: 0, version two: route tag
  • addr β€” IPv4 address
  • mask β€” version one: 0, version two: subnet mask
  • next_hop β€” version one: 0, version two: next hop address
  • metric β€” routing metric
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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, 0 otherwise
  • xid β€” transaction identifier used to link calls and replies
  • prog_num β€” remote program specification typically between 0 - 1fffffff
  • prog_vers β€” remote program version specification
  • procedure β€” procedure to be performed by remote program
  • cflavor β€” authentication credential type
  • clength β€” credential length (should be 0)
  • cdata β€” opaque credential data (currently unused)
  • vflavor β€” authentication verifier type
  • vlength β€” verifier length (should be 0)
  • vdata β€” opaque verifier data (currently unused)
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 hidden
  • version β€” protocol version, currently 1
  • type β€” type of record (read data is type 0, write data is type 1)
  • counter β€” PDU counter used to identify when packet are lost
  • time_sec β€” seconds since EPOCH according to the honeypot
  • time_usec β€” residual microseconds
  • pid β€” PID
  • uid β€” UID
  • fd β€” FD
  • cmd β€” 12 first characters of the command
  • length β€” length in bytes of the PDU's body
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 id
  • version β€” protocol version
  • bpdu_type β€” bridge protocol data unit type
  • flags β€” flags
  • root_id β€” root id
  • root_pc β€” root path cost
  • bridge_id β€” bridge id
  • port_id β€” port id
  • message_age β€” message age
  • max_age β€” max age
  • hello_time β€” hello time
  • f_delay β€” forward delay
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 id
  • version β€” protocol version
  • bpdu_type β€” bridge protocol data unit type
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 port
  • dp β€” destination port
  • seq β€” sequence number
  • ack β€” acknowledgement number
  • control β€” control flags
  • win β€” window size
  • sum β€” checksum (0 for libnet to auto-fill)
  • urg β€” urgent pointer
  • len β€” total length of the TCP packet (for checksum calculation)
  • payload β€” payload
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 options
  • options_s β€” length of options string
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 control
  • fc β€” frame control
  • dst β€” destination address
  • src β€” source address
  • dsap β€” destination service access point
  • ssap β€” source service access point
  • cf β€” control field
  • oui β€” Organizationally Unique Identifier
  • type β€” upper layer protocol type
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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) length
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 length
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 pairs
  • value_s β€” ID pairs length
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 number
  • opcode β€” operation code
  • flags β€” flags
  • checksum β€” checksum (0 for libnet to auto-fill)
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 context
  • ptag β€” 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_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) length
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 context
  • ptag β€” 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_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 context
  • ptag β€” 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_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 port
  • dp β€” destination port
  • len β€” total length of the UDP packet
  • sum β€” checksum (0 for libnet to auto-fill)
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 be 2)
  • type β€” VRRP packet type (should be 1 -- ADVERTISEMENT)
  • vrouter_id β€” virtual router identification
  • priority β€” priority (higher numbers indicate higher priority)
  • ip_count β€” number of IPv4 addresses contained in this advertisement
  • auth_type β€” type of authentication (0, 1, 2 -- see RFC)
  • advert_int β€” interval between advertisements
  • sum β€” checksum (0 for libnet to autofill)
  • payload β€” optional payload or NULL
  • payload_s β€” payload length or 0
  • l β€” pointer to a libnet context
  • ptag β€” 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_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 context
  • label β€” a canonical name given to recognize the new context, no longer than LIBNET_LABEL_SIZE

Return values

  • 1 on success ✨
  • -1 on 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

  • 1 if at the end of the context queue
  • 0 otherwise

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

  • NULL on 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 print
  • len β€” length of the packet in bytes
  • swap β€” 1 to swap byte order, 0 to 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

  • unknown for 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_build function

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_error on 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 - 1
  • LIBNET_PR8 β€” 0 - 255
  • LIBNET_PR16 β€” 0 - 32767
  • LIBNET_PRu16 β€” 0 - 65535
  • LIBNET_PR32 β€” 0 - 2147483647
  • LIBNET_PRu32 β€” 0 - 4294967295

Parameters

  • mod β€” one the of LIBNET_PR* constants

Return values

  • 1 on success
  • -1 on 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 NULL without 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 NULL if 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 β€” see libnet_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 context
  • ptag β€” the ptag reference number

Returns

  • a pointer to the pblock buffer or NULL on 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 context
  • ptag β€” 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 parsed
  • len β€” the resulting size of the returned byte string

Returns

  • a byte string or NULL on 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

  • 1 if addr is in6addr_error
  • 0 if 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 (NULL and libnet will choose one)
  • err_buf β€” will contain an error message on failure

Returns

  • libnet context ready for use or NULL on 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 context
  • host_name β€” pointer to a string containing a presentation format host name
  • use_name β€” LIBNET_RESOLVE or LIBNET_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 context
  • host_name β€” pointer to a string containing a presentation format host name
  • use_name β€” LIBNET_RESOLVE or LIBNET_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

  • 1 on success
  • -1 on 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 NULL on 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

  • 1 on success
  • -1 on 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 context
  • plist β€” if successful, will refer to the portlist; if not, NULL
  • token_list β€” string containing the port list primitive

Return values

  • 1 on success
  • -1 on 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 portlist
  • bport β€” will contain the beginning port number, or 0
  • eport β€” will contain the ending port number, or 0

Return values

  • 1 on success
  • 0 if empty
  • -1 on 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

  • 1 on success
  • -1 on 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 context
  • ls β€” 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 context
  • ptag β€” the ptag reference number
  • mode β€” LIBNET_ON or LIBNET_OFF

Return values

  • 1 on success
  • -1 on 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

  • -1 on error

πŸ‘€ SEE ALSO

libnet(3)


🫢 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>


libnet is licensed under the 2-Clause BSD License.


πŸ‘€ SEE ALSO

libnet(3)


🫢 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>


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 πŸŒˆβœ¨πŸ‘‘