×
Namespaces

Variants
Actions

How to get protocol entry

From Nokia Developer 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 05:33.
38 page views in the last 30 days.
×