#include <netdb.h>
|
struct protoent *
getprotobyname (const char *name); |
struct protoent *
getprotobynumber (int proto); |
struct protoent { char *p_name; /* official name of protocol */ char **p_aliases; /* alias list */ int p_proto; /* protocol number */ };
The members of this structure are:
p_name | The official name of the protocol. |
p_aliases | |
A zero terminated list of alternate names for the protocol. | |
p_proto | The protocol number. |
The getprotobyname function and getprotobynumber sequentially search from the beginning of the database until a matching protocol name or protocol number is found,
#include<netinet/in.h> #include<arpa/inet.h> #include<stdio.h> #include<string.h> #include<netdb.h> Int main() { struct protoent *p =0; char *protoname=”tcp”; p=getprotobyname(protoname); if(p!=NULL) printf(“protocol not supported:); else printf(“protocol supported”); return 0; }
Output
Protocol supported/not supported based on the support for protocol
#include<netinet/in.h> #include<arpa/inet.h> #include<stdio.h> #include<string.h> #include<netdb.h> int main() { struct protoent *p =0; int protonum=6; p=getprotobynumber(protonum); if(p!=NULL) printf(“protocol not supported:); else printf(“protocol supported”); return 0; }
Output
Protocol supported/not supported based on the support for protocol
The getprotobynumber, getprotobyname, functions appeared in BSD 4.2 .
© 2005-2007 Nokia |