Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to get protocol entry

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: polaka_sr (16 Jun 2008)
Last edited: hamishwillee (08 Feb 2012)

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;
}


Wiki Links

Generic functions for system database functions

This page was last modified on 8 February 2012, at 02:33.
24 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×