getprotoent(3)
๐ getprotoent(3) โ the protocol tea, bestie ๐
okay so this is a page from the Library Functions Manual (section 3, the libc girlies section ๐), and it's all about looking up protocols โ like, the IPPROTO_TCP kind of protocols, not the social kind (though honestly both are giving drama). Let's get into it โจ
๐ธ NAME ๐ธ
getprotoent, getprotobyname, getprotobynumber, setprotoent, endprotoent โ get protocol entry ๐ฆ
๐ LIBRARY ๐
Standard C library (libc, -lc). yes bestie, you just link -lc and you're slaying ๐
โจ SYNOPSIS โจ
#include <netdb.h>
struct protoent *getprotoent(void);
struct protoent *getprotobyname(const char *name);
struct protoent *getprotobynumber(int proto);
void setprotoent(int stayopen);
void endprotoent(void);
๐ DESCRIPTION ๐
okay so picture this: there's a whole protocols database (catch it over at protocols(5) ๐ซถ) and these functions are your little backstage pass to it.
getprotoent()โ reads the next entry from the protocols database and hands you back aprotoentstructure stuffed with all the broken-out fields from that entry. If a connection to the database doesn't exist yet, it opens one. no biggie ๐getprotobyname()โ give it a protocol name innameand it returns aprotoentstructure for the entry from the database that matches that name. connection opened if necessary, obviously โจgetprotobynumber()โ same energy but for a protocol number. it returns aprotoentstructure for the entry matching that protocol number, which the docs callnumber(and the synopsis callsprotoโ the docs said what they said ๐). also opens a connection if necessary.setprotoent()โ opens a connection to the database and rewinds you back to the first entry. ifstayopenis nonzero, that connection to the database will not be closed between calls to one of thegetproto*()functions. it's giving commitment ๐endprotoent()โ closes the connection to the database. bye bestie, the vibe check is over ๐ฆ
๐ the protoent structure ๐
it's defined in <netdb.h> like this, no cap:
struct protoent {
char *p_name; /* official protocol name */
char **p_aliases; /* alias list */
int p_proto; /* protocol number */
}
and the members are:
p_nameโ the official name of the protocol. the main character ๐p_aliasesโ aNULL-terminated list of alternative names for the protocol. the entourage โจp_protoโ the protocol number. the digits, the receipts ๐ข
๐ฅ RETURN VALUE ๐ฅ
getprotoent(), getprotobyname(), and getprotobynumber() all return a pointer to a statically allocated protoent structure. and if something goes wrong, or if you've hit the end of the file? you get a null pointer. that's it, that's the whole mood ๐ญ
careful bestie โ statically allocated means it's the library's one shared little structure, not a fresh one you own. it's not yours, it's communal property ๐
๐ FILES ๐
/etc/protocolsโ protocol database file. this is the source of truth, the group chat everyone's reading from ๐
๐ ATTRIBUTES ๐
for an explanation of the terms used in this section, go see attributes(7). the goods:
getprotoent()โ Thread safety โMT-Unsafe race:protoent race:protoentbuf localegetprotobyname()โ Thread safety โMT-Unsafe race:protobyname localegetprotobynumber()โ Thread safety โMT-Unsafe race:protobynumber localesetprotoent(),endprotoent()โ Thread safety โMT-Unsafe race:protoent locale
and here's the lore: in that list up there, protoent inside race:protoent means that if any of the functions setprotoent(), getprotoent(), or endprotoent() are used in parallel in different threads of a program, then data races could occur. ๐ yes bestie, actual races. threads fighting over the shared static struct. be careful fr fr.
โญ STANDARDS โญ
POSIX.1-2008. certified, iconic, official ๐ซถ
๐ฆ HISTORY ๐ฆ
POSIX.1-2001, 4.3BSD. it's been around since forever, a true legend ๐
๐ SEE ALSO ๐
and that's the whole page, bestie!! this little gem is from Linux man-pages 6.20, dated 2026-02-08 ๐ go forth and getprotobyname("tcp") responsibly, ily, mwah ๐โจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms