GETNETPATH(3)
π getnetpath(3) β the girlies' guide to NETPATH filtering
ok so this is GETNETPATH(3) from the Library Functions Manual, aka your new fave trio of functions for reading network config π
β¨ NAME β¨
getnetpath, setnetpath, endnetpath β get the /etc/netconfig entry that corresponds to a NETPATH component π
π LIBRARY
Standard C Library (libc, -lc) β link it and go, bestie π«Ά
πΈ SYNOPSIS πΈ
#include <netconfig.h>
struct netconfig *
getnetpath(void *handlep);
void *
setnetpath(void);
int
endnetpath(void *handlep);
π¦ DESCRIPTION π¦
Okay so picture this: the routines on this page give your app access to the system network configuration database, /etc/netconfig, but as it's βfilteredβ by the NETPATH environment variable (peep environ(7) for that one). If you want the other routines that hit the network configuration database directly, no filtering, go see getnetconfig(3) π. And btw, NETPATH is a list of colon-separated network identifiers. Colon-separated. Iconic.
getnetpath()returns a pointer to the netconfig database entry corresponding to the first validNETPATHcomponent β¨. That netconfig entry is formatted as astruct netconfig. Then, on each subsequent call,getnetpath()returns a pointer to the netconfig entry for the next validNETPATHcomponent. So basically you can loopgetnetpath()to search the netconfig database for all the networks chillin' inNETPATHβ and whenNETPATHhas been exhausted,getnetpath()returnsNULL. That's your signal to stop looping, periodt π
setnetpath()βbindsβ to or βrewindsβNETPATHπ. You must call it before your first call togetnetpath(), and honestly you can call it any other time too. It returns a handle, which is the thinggetnetpath()uses. Keep it safe π
getnetpath()silently ignores invalidNETPATHcomponents, no cap. A component is invalid if there's no corresponding entry in the netconfig database. It justβ¦ doesn't see them π
If theNETPATHvariable is unset,getnetpath()behaves as ifNETPATHwere set to the sequence of βdefaultβ or βvisibleβ networks in the netconfig database, in the order in which they are listed. So like, it's not gonna leave you hanging π«Ά
endnetpath()may be called to βunbindβ fromNETPATHwhen you're done processing, releasing resources for reuse πΈ. But β and this is the important one, bestie β programmers should be aware thatendnetpath()frees all memory allocated bygetnetpath()for thestruct netconfigdata structure. Like, all of it. So don't go touching those pointers afterwards, or that's on you π
β RETURN VALUES β
setnetpath()returns a handle that is used bygetnetpath(). In case of an error,setnetpath()returnsNULL. πendnetpath()returns0on success and-1on failure (for example, ifsetnetpath()was not called previously). You can use thenc_perror()ornc_sperror()function to print out the reason for failure β seegetnetconfig(3)for the deets π₯getnetpath(), when first called, returns a pointer to the netconfig database entry corresponding to the first validNETPATHcomponent. WhenNETPATHhas been exhausted,getnetpath()returnsNULL. π
π SEE ALSO π
ok that's the whole page, you ate that π this was Debian's GETNETPATH(3) from April 22, 2000 β yeah she's vintage, we stan an elder icon ππ mwah, go call setnetpath() first fr fr π§
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright 1989 AT&T
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms