Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
#define _XOPEN_SOURCE_EXTENDED 1
#include <netdb.h>
struct servent *getservbyport(int port, const char *proto);
#define _OE_SOCKETS
#include <netdb.h>
struct servent *getservbyport(int port, char *proto);
The getservbyport() call returns a pointer to a servent structure for the port number specified on the call. getservbyname(), getservbyport(), and getservent() all use the same static area to return the servent structure. This static area is only valid until the next one of these functions is called on the same thread.
Special behavior for C++: To use this function with C++, you must use the _XOPEN_SOURCE_EXTENDED 1 feature test macro.
The return value points to data that is overwritten by subsequent calls returning the same data structure.
If successful, getservbyport() returns a pointer to a servent structure.
If unsuccessful or End Of File (EOF), getservbyport() returns a NULL pointer.