Name

getprotobynumber, getprotobyname
- get protocol entry

Library

libc.lib

Synopsis

  #include <netdb.h>
  struct protoent * getprotobyname (const char *name);
  struct protoent * getprotobynumber (int proto);

Return values

Null pointer (0) returned on error.

Detailed description

The getprotobyname, and getprotobynumber functions each return a pointer to an object with the following structure from the network protocol data base

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,


Examples

#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 .

Bugs

These functions use a thread-specific data space; if the data is needed for future use, it should be copied before any subsequent calls overwrite it. Only the Internet protocols are currently understood.

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top