---
name: "nfq_ip_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_ip_get_hdr"
---

# nfq\_ip\_get\_hdr(3)

IPv4 helper functions

## NAME

ipv4 - IPv4 helper functions

## SYNOPSIS

### Modules

**Internal IP functions**\

### Functions

struct iphdr \* **nfq\_ip\_get\_hdr** (struct pkt\_buff \*pktb)\
 int **nfq\_ip\_set\_transport\_header** (struct pkt\_buff \*pktb, struct iphdr \*iph)\
 int **nfq\_ip\_mangle** (struct pkt\_buff \*pktb, unsigned int dataoff, unsigned int match\_offset, unsigned int match\_len, const char \*rep\_buffer, unsigned int rep\_len)\
 int **nfq\_ip\_snprintf** (char \*buf, size\_t size, const struct iphdr \*iph)\

## Detailed Description

## Function Documentation

### struct iphdr \* nfq\_ip\_get\_hdr (struct pkt\_buff \* pktb)

nfq\_ip\_get\_hdr - get the IPv4 header

**Parameters**

*pktb* Pointer to user-space network packet buffer

**Returns**

validated pointer to the IPv4 header or NULL if IP is malformed or not version 4

Many programs will not need to call this function. A possible use is to determine the layer 4 protocol. The validation is that the buffer is big enough for the declared lengths in the header, i.e. an extra check for packet truncation.

Definition at line **40** of file **ipv4.c**.

### int nfq\_ip\_mangle (struct pkt\_buff \* pktb, unsigned int dataoff, unsigned int match\_offset, unsigned int match\_len, const char \* rep\_buffer, unsigned int rep\_len)

nfq\_ip\_mangle - mangle IPv4 packet buffer

**Parameters**

*pktb* Pointer to user-space network packet buffer \
 *dataoff* Offset to layer 4 header, or zero to mangle IP header \
 *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 if necessary and recalculates the IPv4 checksum.

Definition at line **127** of file **ipv4.c**.

### int nfq\_ip\_set\_transport\_header (struct pkt\_buff \* pktb, struct iphdr \* iph)

nfq\_ip\_set\_transport\_header - set the **transport\_header** field in **pktb**

**Parameters**

*pktb* Pointer to user-space network packet buffer \
 *iph* Pointer to the IPv4 header

**Returns**

0 on success or -1 if a minimal validation check fails

**Note**

Most programs should call **nfq\_ip\_set\_transport\_header** as soon as possible, since most layer 4 helper functions assume the **transport\_header** field is valid.

Definition at line **73** of file **ipv4.c**.

### int nfq\_ip\_snprintf (char \* buf, size\_t size, const struct iphdr \* iph)

nfq\_pkt\_snprintf\_ip - print IPv4 header into buffer in iptables LOG format

**Parameters**

*buf* Pointer to buffer that will be used to print the header \
 *size* Size of the buffer (or remaining room in it) \
 *iph* Pointer to a valid IPv4 header

**Returns**

same as snprintf

**See also**

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

Definition at line **153** of file **ipv4.c**.

## Author

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