ENDNETENT(3POSIX)

🌸 ENDNETENT(3POSIX) β€” POSIX Programmer's Manual 🌸

okay bestie, we're doing the network database functions today and honestly? they're giving vintage but they're still lowkey useful. this is from the POSIX Programmer's Manual, periodt. πŸ’…


✨ PROLOG ✨

so like, heads up before we go any further: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (fr fr, go consult the corresponding Linux manual page for the deets on Linux behavior), or the interface might not even be implemented on Linux at all. 😭 not every platform showed up to the party.


πŸŽ€ NAME πŸŽ€

endnetent, getnetbyaddr, getnetbyname, getnetent, setnetent β€” network database functions. that's the whole squad. 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <netdb.h>

void endnetent(void);
struct netent *getnetbyaddr(uint32_t net, int type);
struct netnet *getnetbyname(const char *name);
struct netent *getnetent(void);
void setnetent(int stayopen);

wait no. let me try that again, that was NOT it. πŸ™ˆ

#include <netdb.h>

void endnetent(void);
struct netent *getnetbyaddr(uint32_t net, int type);
struct netent *getnetbyname(const char *name);
struct netent *getnetent(void);
void setnetent(int stayopen);

there we go. slay. ✨


πŸ’– DESCRIPTION πŸ’–

so these functions shall retrieve information about networks. this info is considered to be stored in a database that you can hit up either sequentially or randomly β€” the implementation of that database is unspecified, so don't come for it, it's mysterious on purpose. πŸ‘‘

  • setnetent() β€” opens and rewinds the database. if the stayopen argument is non-zero, the connection to the net database shall not be closed after each call to getnetent() (whether that's directly, or indirectly through one of the other getnet*() functions), and the implementation may keep an open file descriptor to the database just vibing in the background.
  • getnetent() β€” reads the next entry of the database, opening and closing a connection to the database as necessary.
  • getnetbyaddr() β€” searches the database from the very beginning and finds the first entry where the address family specified by type matches the n_addrtype member and the network number net matches the n_net member, opening and closing a connection to the database as necessary. the net argument shall be the network number in host byte order. no cap.
  • getnetbyname() β€” searches the database from the beginning and finds the first entry where the network name specified by name matches the n_name member, opening and closing a connection to the database as necessary.
  • getnetbyaddr(), getnetbyname(), and getnetent() β€” each of these shall return a pointer to a netent structure, and the members of that structure shall contain the fields of an entry in the network database. it's giving struct reveal. πŸ’…
  • endnetent() β€” closes the database, releasing any open file descriptor. clean exit, we love to see it.
bestie, important: these functions need not be thread-safe. so don't be out here assuming they'll play nice across threads, okay? 😭

⭐ RETURN VALUE ⭐

upon successful completion, getnetbyaddr(), getnetbyname(), and getnetent() shall return a pointer to a netent structure if the requested entry was found β€” and a null pointer if the end of the database was reached or the requested entry was not found. otherwise, a null pointer shall be returned. that's the whole story. 🫢

and now the part everyone skips and then gets burned by:

the application shall not modify the structure to which the return value points, nor any storage areas pointed to by pointers within the structure. the returned pointer, and pointers within the structure, might be invalidated β€” or the structure or the storage areas might be overwritten β€” by a subsequent call to getnetbyaddr(), getnetbyname(), or getnetent(). the returned pointer, and pointers within the structure, might also be invalidated if the calling thread is terminated. 😭 so like, copy what you need while you can. main character energy does not apply to this pointer.

🌈 ERRORS 🌈

no errors are defined. iconic, honestly. nothing to report. πŸ’€

the following sections are informative.


πŸ“ EXAMPLES πŸ“

none. moving on bestie, nothing to see here. πŸ™ˆ


🧚 APPLICATION USAGE 🧚

none. ✨


πŸ’œ RATIONALE πŸ’œ

none. πŸŽ€


🌸 FUTURE DIRECTIONS 🌸

none. πŸ¦‹


πŸ‘‘ SEE ALSO πŸ‘‘

the Base Definitions volume of POSIX.1‐2017, <netdb.h>


portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie. IEEE/The Open Group, 2017 β€” mwah, go read your headers, drink some water, and remember: the returned pointer is temporary but you are forever. πŸ«Άβœ¨πŸ’–