getprotobyname | |
Prototype: |
#include <netdb.h> struct protoent *getprotobyname(const char *pname); |
General Description: | This function reads the /etc/protocol file to get the protocol that matches pname. You use this call to translate names like UDP, ICMP, and TCP into the protocol values. |
Return Value: | The call returns a pointer to protoent (defined below) if successful. Otherwise, it returns a NULL.
struct protoent { char *p_name; /* official protocol name */ char **p_aliases; /* alias list */ int p_proto; /* protocol number */ };The field p_proto is the port number. |
Parameters | |
pname | Protocol name. This may be any of the recognized protocol names or aliases. |
Possible Errors | |
(errno not set) | |
Examples | |
#include <netdb.h> ... int i; struct protoent *proto = getprotobyname("icmp"); if ( proto != NULL ) { printf("Official name: %s\n", proto->name); printf("Port#: %d\n", proto->p_proto); for ( i = 0; proto->p_aliases[i] != 0; i++ ) printf("Alias[%d]: %s\n", i+1, proto->p_aliases[i]); } else perror("'icmp' not found"); |