---
name: "pcap_lookupnet"
section: "3pcap"
platform: "linux"
package: "libpcap"
version: "1.11.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "macos"]
url: "https://new.carta.tech/pcap_lookupnet/3pcap"
---

# pcap\_lookupnet(3pcap)

find the IPv4 network number and netmask for a device

## NAME

pcap\_lookupnet - find the IPv4 network number and netmask for a device

## SYNOPSIS

```
#include <pcap/pcap.h>
```

```
char errbuf[PCAP_ERRBUF_SIZE];
```

**int pcap\_lookupnet(const char \*device, bpf\_u\_int32 \*netp,**\
     **bpf\_u\_int32 \*maskp, char \*errbuf);**

## DESCRIPTION

**pcap\_lookupnet**() is used to determine the IPv4 network number and mask associated with the network device *device*. Both *netp* and *maskp* are **bpf\_u\_int32** pointers, on success both values will be set in network byte order. *errbuf* is a buffer large enough to hold at least **PCAP\_ERRBUF\_SIZE** chars.

This function is not available on Windows.  It supports neither IPv6 nor multiple IPv4 addresses per interface, which obviously is not practical in modern networks.  See **pcap\_findalldevs**(3PCAP) for a more elaborate solution to the problem.

## RETURN VALUE

**pcap\_lookupnet**() returns **0** on success and **PCAP\_ERROR** on failure.  If **PCAP\_ERROR** is returned, *errbuf* is filled in with an appropriate error message.

## SEE ALSO

**pcap**(3PCAP)
