The getprotobyname, and getprotobynumber functions each return a pointer to an object with the following structure from the network protocol database.
struct protoent {
char *p_name; /* official name of protocol */
char **p_aliases; /* alias list */
int p_proto; /* 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.
Following is the code snippet which shows the usage of getprotobyname:
#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;
}
Following is the code snippet which shows the usage of getprotobynumber:
#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;
}
No related wiki articles found