---
name: "nfq_open"
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_open"
---

# nfq\_open(3)

Library setup \[DEPRECATED\]

## NAME

LibrarySetup - Library setup \[DEPRECATED\]

## SYNOPSIS

### Functions

struct nfq\_handle \* **nfq\_open** (void)\
 int **nfq\_close** (struct nfq\_handle \*h)\
 int **nfq\_bind\_pf** (struct nfq\_handle \*h, uint16\_t pf)\
 int **nfq\_unbind\_pf** (struct nfq\_handle \*h, uint16\_t pf)\

## Detailed Description

Library initialisation is made in two steps.

First step is to call **nfq\_open()** to open a NFQUEUE handler.

Second step is to tell the kernel that userspace queueing is handle by NFQUEUE for the selected protocol. This is made by calling **nfq\_unbind\_pf()** and **nfq\_bind\_pf()** with protocol information. The idea behind this is to enable simultaneously loaded modules to be used for queuing.

Here's a little code snippet that bind with AF\_INET:

```
        h = nfq_open();
        if (!h) {
                fprintf(stderr, 'error during nfq_open()\n');
                exit(1);
        }
        printf('unbinding existing nf_queue handler for AF_INET (if any)\n');
        if (nfq_unbind_pf(h, AF_INET) < 0) {
                fprintf(stderr, 'error during nfq_unbind_pf()\n');
                exit(1);
        }
        printf('binding nfnetlink_queue as nf_queue handler for AF_INET\n');
        if (nfq_bind_pf(h, AF_INET) < 0) {
                fprintf(stderr, 'error during nfq_bind_pf()\n');
                exit(1);
        }
```

 Once this is done, you can setup and use a **Queue**.

When the program has finished with libnetfilter\_queue, it has to call the **nfq\_close()** function to free all associated resources.

## Function Documentation

### int nfq\_bind\_pf (struct nfq\_handle \* h, uint16\_t pf)

nfq\_bind\_pf - bind a nfqueue handler to a given protocol family

**Parameters**

*h* Netfilter queue connection handle obtained via call to **nfq\_open()** \
 *pf* protocol family to bind to nfqueue handler obtained from **nfq\_open()**

Binds the given queue connection handle to process packets belonging to the given protocol family (ie. PF\_INET, PF\_INET6, etc). This call is obsolete, Linux kernels from 3.8 onwards ignore it.

**Returns**

integer inferior to 0 in case of failure

Definition at line **474** of file **libnetfilter\_queue.c**.

### int nfq\_close (struct nfq\_handle \* h)

nfq\_close - close a nfqueue handler

**Parameters**

*h* Netfilter queue connection handle obtained via call to **nfq\_open()**

This function closes the nfqueue handler and free associated resources.

**Returns**

0 on success, non-zero on failure.

Definition at line **452** of file **libnetfilter\_queue.c**.

### struct nfq\_handle \* nfq\_open (void)

nfq\_open - open a nfqueue handler

This function obtains a netfilter queue connection handle. When you are finished with the handle returned by this function, you should destroy it by calling **nfq\_close()**. A new netlink connection is obtained internally and associated with the queue connection handle returned.

**Returns**

a pointer to a new queue handle or NULL on failure.

Definition at line **363** of file **libnetfilter\_queue.c**.

### int nfq\_unbind\_pf (struct nfq\_handle \* h, uint16\_t pf)

nfq\_unbind\_pf - unbind nfqueue handler from a protocol family

**Parameters**

*h* Netfilter queue connection handle obtained via call to **nfq\_open()** \
 *pf* protocol family to unbind family from

Unbinds the given queue connection handle from processing packets belonging to the given protocol family.

This call is obsolete, Linux kernels from 3.8 onwards ignore it.

Definition at line **490** of file **libnetfilter\_queue.c**.

## Author

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