ENDSERVENT(3POSIX)
π ENDSERVENT(3POSIX) π
okay bestie so this is the ENDSERVENT page from the POSIX Programmer's Manual (yes, that's the manual name, it's giving official β¨). Buckle up, we're talking network services database functions and honestly? It's a whole vibe.
π«§ PROLOG π«§
Real talk first, because the lawyers said so: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so if you're on Linux, go read the corresponding Linux manual page for the actual tea on Linux behavior. Orrr it might just not be implemented on Linux at all. π No cap.
β¨ NAME β¨
endservent, getservbyname, getservbyport, getservent, setservent β network services database functions. That's the whole squad. π
πΈ SYNOPSIS πΈ
#include <netdb.h>
void endservent(void);
struct servent *getservbyname(const char *name, const char *proto);
struct servent *getservbyport(int port, const char *proto);
struct servent *getservent(void);
void setservent(int stayopen);
Look at them. Iconic. π
π¦ DESCRIPTION π¦
So these functions retrieve information about network services. This info is considered to be stored in a database that you can access either sequentially or randomly β like a playlist you can shuffle or just play straight through. The implementation of this database is unspecified, meaning nobody's telling you how it actually works inside. Mystery. Main character energy. π₯
The setservent() function shall open a connection to the database, and set the next entry to the first entry. If the stayopen argument is non-zero, the net database shall not be closed after each call to the getservent() function (whether you call it directly, or indirectly through one of the other getserv*() functions) β and the implementation may maintain an open file descriptor for the database. Basically: "keep the tab open, we're not done here." β
The getservent() function shall read the next entry of the database, opening and closing a connection to the database as necessary.
The getservbyname() function shall search the database from the beginning and find the first entry where the service name specified by name matches the s_name member and the protocol name specified by proto matches the s_proto member, opening and closing a connection to the database as necessary. And if proto is a null pointer, any value of the s_proto member shall be matched. (Translation: proto said "idc, surprise me." π)
The getservbyport() function shall search the database from the beginning and find the first entry where the port specified by port matches the s_port member and the protocol name specified by proto matches the s_proto member, opening and closing a connection to the database as necessary. If proto is a null pointer, any value of the s_proto member shall be matched. And listen β the port argument shall be a value obtained by converting a uint16_t in network byte order to int. Not vibes-based, actual bytes. π§
The getservbyname(), getservbyport(), and getservent() functions shall each return a pointer to a servent structure, and the members of that structure shall contain the fields of an entry in the network services database.
The endservent() function shall close the database, releasing any open file descriptor. Cleanup era. π§Ή
β οΈ These functions need not be thread-safe. So like, don't just hand them around to every thread at the party, okay? π
β RETURN VALUE β
Upon successful completion, getservbyname(), getservbyport(), and getservent() return a pointer to a servent 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 is returned.
Now the important part, bestie, read it twice: 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 getservbyname(), getservbyport(), or getservent(). The returned pointer, and pointers within the structure, might also be invalidated if the calling thread is terminated.
π«Ά So: look, screenshot, do not redecorate. The pointer is on loan, not a gift.
π ERRORS π
No errors are defined.
The following sections are informative. (Yes, all of them. Cute of them to say.) β¨
π EXAMPLES π
None. Literally nothing. Moving on. π
π APPLICATION USAGE π
The port argument of getservbyport() need not be compatible with the port values of all address families. Just so you know. Not all families speak the same port language, and that's fine. π¦
π RATIONALE π
None.
π§ FUTURE DIRECTIONS π§
None.
π SEE ALSO π
endhostent()endprotoent()htonl()inet_addr()
Also: The Base Definitions volume of POSIX.1β2017, <netdb.h>.
π COPYRIGHT π
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 .
okay that's the whole page bestie, mwah π β¨
This one came from IEEE/The Open Group, dated 2017 β so credit where credit's due, and now you know the whole thing. Go forth and getservbyport() responsibly. π«Άπ
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms