gtpc1m3u | Transmission Control Protocol/Internet Protocol |
The getservbyport function returns the server application name based on a specified server port number.
Format
#include <netdb.h> struct servent *getservbyport(int port, const char *proto);
Normal Return
This function returns a pointer to a servent structure for the server application specified on the call. The netdb.h header file defines the servent structure, which contains the following elements:
Error Return
A NULL pointer indicates an error.
Programming Considerations
Examples
The following example obtains the port associated with a specified server application name.
#include <types.h> #include <socket.h> #include <netdb.h>
·
·
·
struct servent *appl_name; int port; char proto[4] = "TCP"; char *name; port = 21; appl_name = getservbyport(port, proto); if (!appl_name) printf("unknown application %s\n", name); else { name = appl_name->s_name; printf("getservbyport was successful\n"); }
Related Information