Struct protoent structure, getprotobyname and related functions

Source: Internet
Author: User

I wrote a packet capture program in my embedded device to get the information of the Protocol number. When the getprotobynumber is called, The protoent structure pointer returned by an error is always null, the debugging information [cpp] src_addr: 192.168.5.155, dst_addr: 180.153.201.235 ip_p = 6 ------- protoent is NULL !!!! Src_addr: 180.153.201.235, dst_addr: 192.168.5.155 ip_p = 6 ------- protoent is NULL !!!! Src_addr: 192.168.5.155, dst_addr: 180.153.201.235 ip_p = 6 ------- protoent is NULL !!!! Src_addr: 180.153.201.235, dst_addr: 192.168.5.155 ip_p = 6 ------- protoent is NULL !!!! Find a blog on the Internet about this function, the http://yadang418.blog.163.com/blog/static/2684365620096101121612/ contains a sentence "this function will find the Qualified Data from/etc/protocols and return by the structure protoent", I just thought that my device/etc does not have this file to copy the file in linux. Try again, run again, OK !! [Cpp] src_addr: 192.168.5.152, dst_addr: 238.8.8.8 ip_p = 17 ------- pro_name: udp src_port: 60597, dst_port: 11111 src_addr: 192.168.5.30, priority: 255.255.255.255 ip_p = 17 ------- pro_name: udp src_port: 3601, dst_port: 3600 src_addr: 192.168.5.152, Protocol: 238.8.8.8 ip_p = 17 ------- pro_name: udp src_port: 60597, dst_port: 11111 src_addr: 192.168.5.152, dst_addr: 238.8.8.8 ip_p = 17 ------- pro_name: udp sr C_port: 60597, dst_port: 11111 related functions: getprotobyname, getprotoent, setprotoent, endprotoent header file: # include <netdb. h> Function Definition: struct protoent * getprotobynumber (int proto) Description: getprotobynumber () returns a protoent structure. The proto parameter is the network protocol number to be queried. This function searches for qualified data from/etc/protocols and returns it by the schema protoent. Structure protoent definition parameter getprotoent () returned value: if the result is successful, the protoent structure fingerprint is returned, if an error occurs or the corresponding data cannot be found, the NULL pointer struct protoent structure [cpp]/* Description of data base entry for a single service is returned. */struct protoent {char * p_name;/* Official protocol name. */char ** p_aliases;/* Alias list. */int p_proto;/* Protocol number. */}; getprotobyname (): obtains other information about the protocol according to the name of the protocol. Format: struct protoent * getprotobyname (const char * name); parameter: name communication protocol name return value: Success-1 pointer to struct protoent failed-NULL description: the name of the communication agreement is used to obtain the alias and serial number of the communication agreement. Getprotobynumber (): obtains other information about the protocol according to the number of the Protocol. Format: struct protoent * getprotobynumber (int number); parameter number: The value returned by the communication protocol number in host arrangement: Success-a pointer to struct protoent failure-NULL description: the name and alias of the communication agreement are known by the number of the communication agreement. ================ 2.6.31 kernel ====================== [cpp]/* Open protocol data base files and mark them as staying open even after a later search if STAY_OPEN is non-zero. this function is a possible cancellation point and therefore not marked with _ THROW. */extern void setprotoent (int _ stay_open);/* Close protocol data base files and clear 'stay open' flag. this function is a possible cancellation point and therefore not marked with _ THROW. */extern void endprotoent (void);/* Get next entry from protocol data base file. open data base if necessary. this function is a possible cancellation point and therefore not marked with _ THROW. */extern struct protoent * getprotoent (void);/* Return entry from protocol data base for network with NAME. this function is a possible cancellation point and therefore not marked with _ THROW. */extern struct protoent * getprotobyname (_ const char * _ name);/* Return entry from protocol data base which number is PROTO. this function is a possible cancellation point and therefore not marked with _ THROW. */extern struct protoent * getprotobynumber (int _ proto );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.