GETNETPATH(3)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’… 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 valid NETPATH component ✨. That netconfig entry is formatted as a struct netconfig. Then, on each subsequent call, getnetpath() returns a pointer to the netconfig entry for the next valid NETPATH component. So basically you can loop getnetpath() to search the netconfig database for all the networks chillin' in NETPATH β€” and when NETPATH has been exhausted, getnetpath() returns NULL. That's your signal to stop looping, periodt πŸ’…
setnetpath() β€œbinds” to or β€œrewinds” NETPATH 🌈. You must call it before your first call to getnetpath(), and honestly you can call it any other time too. It returns a handle, which is the thing getnetpath() uses. Keep it safe πŸŽ€
getnetpath() silently ignores invalid NETPATH components, no cap. A component is invalid if there's no corresponding entry in the netconfig database. It just… doesn't see them πŸ™ˆ
If the NETPATH variable is unset, getnetpath() behaves as if NETPATH were 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” from NETPATH when you're done processing, releasing resources for reuse 🌸. But β€” and this is the important one, bestie β€” programmers should be aware that endnetpath() frees all memory allocated by getnetpath() for the struct netconfig data 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 by getnetpath(). In case of an error, setnetpath() returns NULL. 😭
  • endnetpath() returns 0 on success and -1 on failure (for example, if setnetpath() was not called previously). You can use the nc_perror() or nc_sperror() function to print out the reason for failure β€” see getnetconfig(3) for the deets πŸ”₯
  • getnetpath(), when first called, returns a pointer to the netconfig database entry corresponding to the first valid NETPATH component. When NETPATH has been exhausted, getnetpath() returns NULL. πŸ‘‘

🌈 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms