Skip to content

qgetservbyname_r.3

Manvendra Bhangui edited this page Feb 25, 2024 · 3 revisions

NAME

qgetservent_r, qgetservbyname_r, qgetservbyport_r - get service entry (reentrant)

SYNOPSIS

#include <netdb.h>

int qgetservent_r(struct servent *result_buf, char *buf,
 size_t buflen, struct servent **result);

int qgetservbyname_r(const char *name, const char *proto,
 struct servent *result_buf, char *buf,
 size_t buflen, struct servent **result);

int qgetservbyport_r(int port, const char *proto,
 struct servent *result_buf, char *buf,
 size_t buflen, struct servent **result);

DESCRIPTION

The qgetservent_r(), qgetservbyname_r(), and qgetservbyport_r() functions are the reentrant equivalents of, respectively, qgetservent(3), qgetservbyname(3), and qgetservbyport(3). They differ in the way that the servent structure is returned, and in the function calling signature and return value. This manual page describes just the differences from the nonreentrant functions.

Instead of returning a pointer to a statically allocated servent structure as the function result, these functions copy the structure into the location pointed to by result_buf.

The buf array is used to store the string fields pointed to by the returned servent structure. (The nonreentrant functions allocate these strings in static storage.) The size of this array is specified in buflen. If buf is too small, the call fails with the error ERANGE, and the caller must try again with a larger buffer. (A buffer of length 1024 bytes should be sufficient for most applications.)

If the function call successfully obtains a service record, then *result is set pointing to result_buf; otherwise, *result is set to NULL.

RETURN VALUE

On success, these functions return 0. On error, they return one of the positive error numbers listed in errors.

On error, record not found (qgetservbyname_r(), qgetservbyport_r()), or end of input (qgetservent_r()) result is set to NULL.

ERRORS

ENOENT
(qgetservent_r()) No more records in database.

ERANGE
buf is too small. Try again with a larger buffer (and increased buflen).

SEE ALSO

qgetservent(3), services(5)

Clone this wiki locally