tcp(3)

πŸ’– tcp(3) β€” Library Functions Manual πŸ’–

okay bestie, sit down, hydrate, because we're about to talk about tcp β€” the TCP helper functions from libnetfilter_queue, and yes this is the section 3 manual page, so it's a library thing, not a command you type. 🧚✨

🌸 NAME 🌸

tcp β€” TCP helper functions. that's it, that's the whole name section, she's concise, she's iconic, she ate. πŸ’…


✨ SYNOPSIS ✨

πŸŽ€ Modules

Internal TCP functions β€” yes ma'am, that's the module vibe. πŸ¦‹

πŸŽ€ Functions

okay so here's the whole squad, exactly as declared, don't touch a single character, i'm watching πŸ‘€:

struct tcphdr * nfq_tcp_get_hdr (struct pkt_buff *pktb)
void * nfq_tcp_get_payload (struct tcphdr *tcph, struct pkt_buff *pktb)
unsigned int nfq_tcp_get_payload_len (struct tcphdr *tcph, struct
    pkt_buff *pktb)
int nfq_tcp_snprintf (char *buf, size_t size, const struct tcphdr *tcph)
int nfq_tcp_mangle_ipv4 (struct pkt_buff *pktb, unsigned int
    match_offset, unsigned int match_len, const char *rep_buffer,
    unsigned int rep_len)
int nfq_tcp_mangle_ipv6 (struct pkt_buff *pktb, unsigned int
    match_offset, unsigned int match_len, const char *rep_buffer,
    unsigned int rep_len)

six functions, all TCP, all yours. slay. πŸ”₯


🌈 Detailed Description 🌈

Internal TCP functions β€” that's the whole detailed description bestie, the Doxygen just said "go read the function docs" and honestly? valid. no cap. πŸ’€


πŸ‘‘ Function Documentation πŸ‘‘

🌟 struct tcphdr * nfq_tcp_get_hdr (struct pkt_buff * pktb)

nfq_tcp_get_hdr β€” get the TCP header. it's giving "hand me the header, please and thank you." 🫢

Parameters

  • pktb β€” pointer to user-space network packet buffer

Returns

a validated pointer to the TCP header, or NULL if the TCP header was not set, or if a minimal length check fails. so like, it checks before it ships. queen behavior. πŸ‘‘

Note

bestie you HAVE to call nfq_ip_set_transport_header() or nfq_ip6_set_transport_header() first to set the TCP header. no skipping steps, iykyk. ⚠️

Definition at line 43 of file tcp.c.


🌟 void * nfq_tcp_get_payload (struct tcphdr * tcph, struct pkt_buff * pktb)

nfq_tcp_get_payload β€” get the TCP packet payload. the goods. the actual content. the main character. ✨

Parameters

  • tcph β€” pointer to the TCP header
  • pktb β€” pointer to user-space network packet buffer

Returns

pointer to the TCP payload, or NULL if the packet is malformed. if it's malformed we simply do not engage. πŸ™ˆ

Definition at line 62 of file tcp.c.


🌟 unsigned int nfq_tcp_get_payload_len (struct tcphdr * tcph, struct pkt_buff * pktb)

nfq_tcp_get_payload_len β€” get the tcp packet payload length. the how much of it all. πŸŽ€

Parameters

  • tcph β€” pointer to the TCP header
  • pktb β€” pointer to user-space network packet buffer

Returns

length of TCP payload (user data). that's the number, go off. πŸ”’

Definition at line 84 of file tcp.c.


🌟 int nfq_tcp_mangle_ipv4 (struct pkt_buff * pktb, unsigned int match_offset, unsigned int match_len, const char * rep_buffer, unsigned int rep_len)

nfq_tcp_mangle_ipv4 β€” mangle TCP/IPv4 packet buffer. yes bestie, mangle, as in mess with it on purpose. this is the glow-up function. πŸ’…βœ¨

Parameters

  • pktb β€” pointer to network packet buffer
  • match_offset β€” offset to content that you want to mangle
  • match_len β€” length of the existing content you want to mangle
  • rep_buffer β€” pointer to data you want to use to replace current content
  • rep_len β€” length of data you want to use to replace current content

Returns

1 for success and 0 for failure. for the failure case, go see pktb_mangle(). πŸ‘€

Note

this function updates the IPv4 length and recalculates the IPv4 & TCP checksums for you. it's doing the math so you don't have to. angel behavior fr fr. πŸ˜­πŸ’–

Warning

after changing the length of a TCP message, the application will need to mangle sequence numbers in both directions until another change puts them in sync again. like, BOTH directions, until they're synced again. do not forget this part, it WILL humble you. πŸ’€βš οΈ

Definition at line 219 of file tcp.c.


🌟 int nfq_tcp_mangle_ipv6 (struct pkt_buff * pktb, unsigned int match_offset, unsigned int match_len, const char * rep_buffer, unsigned int rep_len)

nfq_tcp_mangle_ipv6 β€” Mangle TCP/IPv6 packet buffer. capital M Mangle, she's fancy like that. 🌸

Parameters

  • pktb β€” Pointer to network packet buffer
  • match_offset β€” Offset from start of TCP data of content that you want to mangle
  • match_len β€” Length of the existing content you want to mangle
  • rep_buffer β€” Pointer to data you want to use to replace current content
  • rep_len β€” Length of data you want to use to replace current content

Returns

1 for success and 0 for failure. failure case lives in pktb_mangle(), go check her out. πŸ¦‹

Note

this function updates the IPv6 length and recalculates the TCP checksum for you. note: TCP checksum only this time, not IPv4, because IPv6 said "i got this." ✨

Warning

after changing the length of a TCP message, the application will need to mangle sequence numbers in both directions until another change puts them in sync again. same warning, same energy, do not skip it. ⚠️😀

Definition at line 254 of file tcp.c.


🌟 int nfq_tcp_snprintf (char * buf, size_t size, const struct tcphdr * tcph)

nfq_pkt_snprintf_tcp_hdr β€” print tcp header into one buffer in a humnan readable way. (yes, "humnan", that's literally what the original says, i am not fixing her typo, she's perfect as she is. πŸ’€πŸ’–)

Parameters

  • buf β€” pointer to buffer that is used to print the object
  • size β€” size of the buffer (or remaining room in it).
  • tcph β€” pointer to a valid tcp header.

Returns

same as snprintf. that's the whole return value, she's consistent, she's loyal. 🫢

See also

snprintf(3) β€” go read that one too bestie, it's the blueprint. πŸ“–

Definition at line 160 of file tcp.c.


πŸ¦‹ Author πŸ¦‹

Generated automatically by Doxygen for libnetfilter_queue from the source code. so like, no human author to thank, just Doxygen doing her little automated thing. still iconic. πŸ€–πŸ’…


libnetfilter_queue, Version 1.0.5, tcp(3) β€” and that's the whole page bestie!! πŸŽ€ you read every single option, every parameter, every warning, every "Definition at line" β€” i'm so proud of you. go mangle some packets responsibly, and remember: mangle sequence numbers in BOTH directions until they're in sync again. no cap. πŸ’–βœ¨πŸ¦‹πŸŒΈπŸŽ€πŸ‘‘πŸŒˆβ­πŸ”₯πŸ’œ

πŸ“¦ where this page comes from