GETRPCENT(3)

πŸ’– GETRPCENT πŸ’–

okay bestie, gather round, because we're diving into the Library Functions Manual and honestly? this one's a little vintage gem πŸŽ€


✨ NAME ✨

getrpcent, getrpcbyname, getrpcbynumber, endrpcent, setrpcent β€” get an RPC entry, fr fr πŸ‘‘


🌸 SYNOPSIS 🌸

#include <rpc/rpc.h>

struct rpcent *
getrpcent(void);

struct rpcent *
getrpcbyname(char *name);

struct rpcent *
getrpcbynumber(int number);

void
setrpcent(int stayopen);

void
endrpcent(void);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜• β€” getrpcent(), getrpcbyname(), and getrpcbynumber() all hand you back a pointer to an object. that object has the structure below, and it's literally just the broken-out fields of one line from the rpc program number data base, which lives at /etc/rpc πŸ—‚οΈ

struct rpcent {
        char    *r_name;        /* name of server for this rpc program */
        char    **r_aliases;    /* alias list */
        long    r_number;       /* rpc program number */
};

and the members of that struct? let me break it down for you πŸ’…

  • r_name β€” the name of the server for this rpc program. that's it, that's the name 🏷️
  • r_aliases β€” a zero terminated list of alternate names for the rpc program. so like, the government names, plural 🌈
  • r_number β€” the rpc program number for this service. the digits, the ID, the whole vibe πŸ”’

getrpcent() reads the next line of the file, and it'll open the file for you if it needs to. no prep required, she's self-sufficient πŸ’…βœ¨

setrpcent() opens and rewinds the file. and here's the key part: if the stayopen flag is non-zero, the net data base will not be closed after each call to getrpcent() β€” whether you call it directly or sneakily indirectly through one of the other β€œgetrpc” calls πŸ‘€ keep that file held open, queen.

endrpcent() closes the file. that's the whole job, and she does it flawlessly 🫢

getrpcbyname() and getrpcbynumber() do a sequential search from the beginning of the file β€” just walking it down, line by line β€” until they hit a matching rpc program name or program number, or until they smash into end-of-file. no shortcuts, no index, just vibes and determination 😭


πŸ“ FILES πŸ“

  • /etc/rpc

🌟 AVAILABILITY 🌟

these functions are part of libtirpc. that's the home, that's where they live 🏑


πŸ‘€ SEE ALSO πŸ‘€

go read those too, i'm not asking πŸ’œ


🩺 DIAGNOSTICS 🩺

a NULL pointer is returned on EOF or error. so if you get NULL, that's the universe telling you something went sideways or you just ran out of file πŸ“‰


πŸ’€ BUGS πŸ’€

okay so this is the important one, bestie, listen up:

all information is contained in a static area, so it must be copied if it is to be saved. do not, i repeat, do not just hold onto that pointer and assume it'll still say the same thing later. she will change on you. copy it. periodt. πŸ’…

πŸŽ€ the cute sign-off πŸŽ€

this page is from Debian, and it's been serving looks since December 14, 1987 β€” an absolute icon, aging like fine wine, still relevant, still slaying πŸŒˆπŸ‘‘βœ¨

πŸ“¦ where this page comes from