PCAP_ACTIVATE(3)
β¨ NAME β¨
pcap_activate β activate a capture handle π¬
ok so real quick, bestie: this whole page lives in the Library Functions Manual, section 3. that's the vibe. let's get into it π
πΈ SYNOPSIS πΈ
#include <pcap/pcap.h>
int pcap_activate(pcap_t *p);
π¦ DESCRIPTION π¦
So like. pcap_activate() is the function you call to activate a packet capture handle β as in, make it actually go look at packets on the network. πβ¨
And here's the key thing: the options you already set on the handle? yeah, those are in effect when it activates. everything you queued up beforehand, that's what you're getting. no take-backs, no surprises. periodt. π
π₯ RETURN VALUE π₯
ok this is the part where you gotta pay attention, because the return value has three whole moods:
0β slay, success, no warnings, immaculate. β¨- a non-zero positive value β success with warnings. it worked, but it's got notes. π
- a negative value β error. not it. π
And a non-zero return value tells you which warning or error condition happened, so you can actually figure out what's going on.
π the possible warning values (positive, remember!)
PCAP_WARNING_PROMISC_NOTSUPβ you asked for promiscuous mode, but the capture source doesn't support promiscuous mode. it said no. πPCAP_WARNING_TSTAMP_TYPE_NOTSUPβ the time stamp type you specified in a previouspcap_set_tstamp_type(3)call isn't supported by the capture source (and the time stamp type is left as the default).PCAP_WARNINGβ some other warning condition occurred. in that case you can callpcap_geterr(3)orpcap_perror(3)withpas an argument to fetch or display a message describing the warning condition. π«Ά
π the possible error values (negative, oof)
PCAP_ERROR_ACTIVATEDβ the handle has already been activated. girl it's already on. πPCAP_ERROR_NO_SUCH_DEVICEβ the capture source specified when the handle was created doesn't exist. ghosted. π»PCAP_ERROR_PERM_DENIEDβ the process doesn't have permission to open the capture source.PCAP_ERROR_PROMISC_PERM_DENIEDβ the process has permission to open the capture source, but doesn't have permission to put it into promiscuous mode. so close yet so far. πPCAP_ERROR_RFMON_NOTSUPβ monitor mode was specified but the capture source doesn't support monitor mode.PCAP_ERROR_IFACE_NOT_UPβ the capture source device is not up. get it together bestie. π§PCAP_ERROR_CAPTURE_NOTSUPβ packet capture is not supported on the capture source.PCAP_ERRORβ another error occurred.pcap_geterr()orpcap_perror()may be called withpas an argument to fetch or display a message describing the error.
π‘ extra detail drop: ifPCAP_WARNING_PROMISC_NOTSUP,PCAP_ERROR_NO_SUCH_DEVICE,PCAP_ERROR_PERM_DENIED, orPCAP_ERROR_CAPTURE_NOTSUPis returned,pcap_geterr()orpcap_perror()may be called withpas an argument to fetch or display a message giving additional details about the problem β which might be useful for debugging the problem if it's unexpected. π
π future-proofing, iykyk
Additional warning and error codes may be added in the future. so your program should check for positive, negative, and zero return codes, and treat all positive return codes as warnings and all negative return codes as errors. don't hardcode the specific ones, that's not the move. π
Also: pcap_statustostr(3) can be called, with a warning or error code as an argument, to fetch a message describing the warning or error code. very handy, 10/10. β
β οΈ important cleanup note
Ifpcap_activate()fails, thepcap_t *is not closed and freed. you gotta close it yourself usingpcap_close(3). don't leave it hanging, that's rude and also a leak. π
π«Ά SEE ALSO π«Ά
and that's the whole page, bestie β go forth and activate responsibly π¦π
signing off from PCAP_ACTIVATE(3) in the Library Functions Manual, dated 3 June 2024 β¨π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 1994, 1996, 1997 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms