---
name: "nfq_tcp_get_hdr"
section: "3"
platform: "linux"
package: "libnetfilter-queue-doc"
version: "1.0.5-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/nfq_tcp_get_hdr"
---

# nfq\_tcp\_get\_hdr(3)

TCP helper functions

## NAME

tcp - TCP helper functions

## SYNOPSIS

### Modules

**Internal TCP functions**\

### Functions

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)\

## Detailed Description

## Function Documentation

### struct tcphdr \* nfq\_tcp\_get\_hdr (struct pkt\_buff \* pktb)

nfq\_tcp\_get\_hdr - get the TCP header

**Parameters**

*pktb* pointer to user-space network packet buffer

**Returns**

validated pointer to the TCP header or NULL if the TCP header was not set or if a minimal length check fails.

**Note**

You have to call **nfq\_ip\_set\_transport\_header()** or **nfq\_ip6\_set\_transport\_header()** first to set the TCP header.

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

**Parameters**

*tcph* pointer to the TCP header \
 *pktb* pointer to user-space network packet buffer

**Returns**

Pointer to the TCP payload, or NULL if malformed TCP packet.

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

**Parameters**

*tcph* pointer to the TCP header \
 *pktb* pointer to user-space network packet buffer

**Returns**

Length of TCP payload (user data)

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

**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. See **pktb\_mangle()** for failure case

**Note**

This function updates the IPv4 length and recalculates the IPv4 & TCP checksums for you.

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

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

**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. See **pktb\_mangle()** for failure case

**Note**

This function updates the IPv6 length and recalculates the TCP checksum for you.

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

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

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

**See also**

[**snprintf**(3)](/snprintf/3.md)

Definition at line **160** of file **tcp.c**.

## Author

Generated automatically by Doxygen for libnetfilter\_queue from the source code.
