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

# nflog\_get\_prefix(3)

Message parsing functions

## NAME

nflog\_get\_msg\_packet\_hdr, nflog\_get\_hwtype, nflog\_get\_msg\_packet\_hwhdrlen, nflog\_get\_msg\_packet\_hwhdr, nflog\_get\_nfmark, nflog\_get\_timestamp, nflog\_get\_indev, nflog\_get\_physindev, nflog\_get\_outdev, nflog\_get\_physoutdev, nflog\_get\_packet\_hw, nflog\_get\_payload, nflog\_get\_prefix, nflog\_get\_uid, nflog\_get\_gid, nflog\_get\_seq, nflog\_get\_seq\_global, nflog\_get\_ctid - Message parsing functions

## SYNOPSIS

```
#include <stddef.h>
#include <libnetfilter_log/libnetfilter_log.h>
struct nfulnl_msg_packet_hdr * nflog_get_msg_packet_hdr (struct nflog_data *nfad)
uint16_t nflog_get_hwtype (struct nflog_data *nfad)
uint16_t nflog_get_msg_packet_hwhdrlen (struct nflog_data *nfad)
char * nflog_get_msg_packet_hwhdr (struct nflog_data *nfad)
uint32_t nflog_get_nfmark (struct nflog_data *nfad)
int nflog_get_timestamp (struct nflog_data *nfad, struct timeval *tv)
uint32_t nflog_get_indev (struct nflog_data *nfad)
uint32_t nflog_get_physindev (struct nflog_data *nfad)
uint32_t nflog_get_outdev (struct nflog_data *nfad)
uint32_t nflog_get_physoutdev (struct nflog_data *nfad)
struct nfulnl_msg_packet_hw * nflog_get_packet_hw (struct nflog_data *nfad)
int nflog_get_payload (struct nflog_data *nfad, char **data)
char * nflog_get_prefix (struct nflog_data *nfad)
int nflog_get_uid (struct nflog_data *nfad, uint32_t *uid)
int nflog_get_gid (struct nflog_data *nfad, uint32_t *gid)
int nflog_get_seq (struct nflog_data *nfad, uint32_t *seq)
int nflog_get_seq_global (struct nflog_data *nfad, uint32_t *seq)
int nflog_get_ctid (struct nflog_data *nfad, uint32_t *id)
```

## Function Documentation

### int nflog\_get\_ctid (struct nflog\_data \* nfad, uint32\_t \* id)

**nflog\_get\_ct\_id - get the conntrack id**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function** \
 *id* **conntrack id, if the function returns zero**

**You must enable this via nflog\_set\_flags().**

**Returns**

**0 on success or -1 if conntrack itself or its id was unavailable**

**Definition at line 990 of file libnetfilter\_log.c.**

### int nflog\_get\_gid (struct nflog\_data \* nfad, uint32\_t \* gid)

**nflog\_get\_gid - get the GID of the user that has generated the packet**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function** \
 *gid* **GID of the user that generated the packet, if the function returns zero**

**Returns**

**0 on success or -1 if GID was unavailable (gid is then invalid)**

**Definition at line 932 of file libnetfilter\_log.c.**

### uint16\_t nflog\_get\_hwtype (struct nflog\_data \* nfad)

**nflog\_get\_hwtype - get the hardware link layer type from logging data**

**Parameters**

*nfad* **pointer to logging data**

**Returns**

**the hardware link layer type.**

**Definition at line 724 of file libnetfilter\_log.c.**

### uint32\_t nflog\_get\_indev (struct nflog\_data \* nfad)

**nflog\_get\_indev - get the interface that the packet was received through**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function**

**Returns**

**The index of the device the packet was received via. If the returned index is 0, the packet was locally generated or the input interface is not known (ie. POSTROUTING?).**

**Warning**

**all nflog\_get\_dev() functions return 0 if not set, since Linux only allows ifindex \>= 1, see net/core/dev.c:9819 (in 5.14.3)**

**Definition at line 799 of file libnetfilter\_log.c.**

### struct nfulnl\_msg\_packet\_hdr \* nflog\_get\_msg\_packet\_hdr (struct nflog\_data \* nfad)

**nflog\_get\_msg\_packet\_hdr - return the metaheader that wraps the packet**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function**

**Returns**

**the netfilter log netlink packet header for the given nflog\_data argument. Typically, the nflog\_data value is passed as the 3rd parameter to the callback function set by a call to nflog\_callback\_register().**

**The nfulnl\_msg\_packet\_hdr structure is defined in libnetfilter\_log.h as:**

```
        struct nfulnl_msg_packet_hdr {
                uint16_t       hw_protocol;    // hw protocol (network order)
                uint8_t        hook;           // netfilter hook
                uint8_t        _pad;
        } __attribute__ ((packed));
```

**Definition at line 712 of file libnetfilter\_log.c.**

### char \* nflog\_get\_msg\_packet\_hwhdr (struct nflog\_data \* nfad)

**nflog\_get\_msg\_packet\_hwhdr - get the hardware link layer header**

**Parameters**

*nfad* **pointer to logging data**

**Returns**

**the hardware link layer header**

**Definition at line 746 of file libnetfilter\_log.c.**

### uint16\_t nflog\_get\_msg\_packet\_hwhdrlen (struct nflog\_data \* nfad)

**nflog\_get\_hwhdrlen - get the length of the hardware link layer header**

**Parameters**

*nfad* **pointer to logging data**

**Returns**

**the size of the hardware link layer header**

**Definition at line 735 of file libnetfilter\_log.c.**

### uint32\_t nflog\_get\_nfmark (struct nflog\_data \* nfad)

**nflog\_get\_nfmark - get the packet mark**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function**

**Returns**

**the netfilter mark currently assigned to the logged packet.**

**Definition at line 757 of file libnetfilter\_log.c.**

### uint32\_t nflog\_get\_outdev (struct nflog\_data \* nfad)

**nflog\_get\_outdev - gets the interface that the packet will be routed to**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function**

**Returns**

**The index of the device the packet will be sent to. If the returned index is 0, the packet is destined for localhost or the output interface is not yet known (ie. PREROUTING?).**

**Definition at line 826 of file libnetfilter\_log.c.**

### struct nfulnl\_msg\_packet\_hw \* nflog\_get\_packet\_hw (struct nflog\_data \* nfad)

**nflog\_get\_packet\_hw - get hardware address**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function**

**Retrieves the hardware address associated with the given packet. For ethernet packets, the hardware address returned (if any) will be the MAC address of the packet source host. The destination MAC address is not known until after POSTROUTING and a successful ARP request, so cannot currently be retrieved.**

**The nfulnl\_msg\_packet\_hw structure is defined in libnetfilter\_log.h as:**

```
        struct nfulnl_msg_packet_hw {
                uint16_t       hw_addrlen; // Network Byte Order
                uint16_t       _pad;
                uint8_t        hw_addr[8];
        } __attribute__ ((packed));
```

**Returns**

**Pointer to struct nfulnl\_msg\_packet\_hw from originating host or NULL if none available (e.g. locally-originated packet not for lo interface).**

**Definition at line 867 of file libnetfilter\_log.c.**

### int nflog\_get\_payload (struct nflog\_data \* nfad, char \*\* data)

**nflog\_get\_payload - get payload of the logged packet**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function** \
 *data* **Pointer of pointer that will be pointed to the payload**

**Retrieve the payload for a logged packet. The actual amount and type of data retrieved by this function will depend on the mode set with the nflog\_set\_mode() function.**

**Returns**

**payload length, or -1 if this is not available**

**Definition at line 884 of file libnetfilter\_log.c.**

### uint32\_t nflog\_get\_physindev (struct nflog\_data \* nfad)

**nflog\_get\_physindev - get the physical interface that the packet was received through**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function**

**Returns**

**The index of the physical device the packet was received via. If the returned index is 0, the packet was locally generated or the physical input interface is no longer known (ie. POSTROUTING?).**

**Definition at line 813 of file libnetfilter\_log.c.**

### uint32\_t nflog\_get\_physoutdev (struct nflog\_data \* nfad)

**nflog\_get\_physoutdev - get the physical interface for packet output**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function**

**Returns**

**Index of physical device the packet will be routed to. If the returned index is 0, the packet is destined for localhost or the physical output interface is not yet known (ie. PREROUTING?).**

**Definition at line 839 of file libnetfilter\_log.c.**

### char \* nflog\_get\_prefix (struct nflog\_data \* nfad)

**nflog\_get\_prefix - get the logging string prefix**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function**

**Returns**

**the string prefix that is specified as argument to the iptables' NFLOG target or NULL if this is not available.**

**Definition at line 900 of file libnetfilter\_log.c.**

### int nflog\_get\_seq (struct nflog\_data \* nfad, uint32\_t \* seq)

**nflog\_get\_seq - get the local nflog sequence number**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function** \
 *seq* **local nflog sequence number, if the function returns zero**

**You must enable this via nflog\_set\_flags().**

**Returns**

**0 on success or -1 if sequence number was unavailable (seq is then invalid)**

**Definition at line 952 of file libnetfilter\_log.c.**

### int nflog\_get\_seq\_global (struct nflog\_data \* nfad, uint32\_t \* seq)

**nflog\_get\_seq\_global - get the global nflog sequence number**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function** \
 *seq* **global nflog sequence number, if the function returns zero**

**You must enable this via nflog\_set\_flags().**

**Returns**

**0 on success or -1 if sequence number was unavailable (seq is then invalid)**

**Definition at line 972 of file libnetfilter\_log.c.**

### int nflog\_get\_timestamp (struct nflog\_data \* nfad, struct timeval \* tv)

**nflog\_get\_timestamp - get the packet timestamp**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function** \
 *tv* **structure to fill with timestamp info**

**Retrieves the received timestamp from the given logged packet.**

**Returns**

**0 on success, -1 on failure with errno set.**

**Errors**

**from underlying calls, in exceptional circumstances**

**Definition at line 773 of file libnetfilter\_log.c.**

### int nflog\_get\_uid (struct nflog\_data \* nfad, uint32\_t \* uid)

**nflog\_get\_uid - get the UID of the user that generated the packet**

**Parameters**

*nfad* **Netlink packet data handle passed to callback function** \
 *uid* **UID of the user that generated the packet, if the function returns zero**

**Returns**

**0 on success or -1 if UID was unavailable (uid is then invalid)**

**Definition at line 914 of file libnetfilter\_log.c.**

## Author

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