The getservbyport_r() function is a reentrant version of the getservbyport() function.
The getservbyport_r() function shall search the network services database for an entry with the port port. The proto parameter shall restrict the search to entries with the specified protocol. If proto is NULL, getservbyport_r() may return entries with any protocol.
If a matching entry is found in the database, this function shall copy the relevant information to the application-supplied servent structure referenced by result_buf, and return a pointer to this structure in *result. If no matching entry is found, *result shall be set to a null pointer.
The array buf shall contain the string fields referenced by the servent structure that was returned. The parameter buflen shall specify the array's size. 1024 bytes should be enough for most uses.
On success, the getservbyport_r() function shall return zero. If the return value was ERANGE, the size of the buffer buf, indicated by buflen, was too small.