servent structure stuct servent char Far为 s name, /official service name */ char Far* far* s aliases /*other aliases short s_port, /port for this service */ char Far s_proto, /*protocol to use 哈工大计算机学院李全龙 Network Application Development Client Software Desi
哈工大计算机学院 李全龙 Network Application Development Client Software Design 11 servent structure stuct servent { char FAR* s_name; /*official service name */ char FAR* FAR* s_aliases; /*other aliases */ short s_port; /*port for this service */ char FAR* s_proto; /*protocol to use */ };
Example stuct servent“sptr; if(ptr= getservbyname(“smtp”,“tcp”) port number is now in sptr->s_port 了else /*error occurred- handle it*/ 哈工大计算机学院李全龙 Network Application Development Client Software Desi
哈工大计算机学院 李全龙 Network Application Development Client Software Design 12 Example stuct servent *sptr; if (sptr=getservbyname(“smtp”, “tcp”)){ /* port number is now in sptr->s_port*/ }else { /*error occurred-handle it*/ }
Port numbers and network byte order getservbyname returns the protocol port for the service in network byte order It is sufficient to understand that getservbyname returns the port value in exactly the form needed for use in the sockaddr in structure a But the representation may not agree with the local machine's usual representation 哈工大计算机学院李全龙 Network Application Development Client Software Desi 13
哈工大计算机学院 李全龙 Network Application Development Client Software Design 13 Port numbers and network byte order getservbyname returns the protocol port for the service in network byte order. It is sufficient to understand that getservbyname returns the port value in exactly the form needed for use in the sockaddr_in structure. But, the representation may not agree with the local machine’s usual representation
Looking up a protocol by name getprotobyname returns the address of a structure of type protoent Contained in winsock.h stuct protoent i char Far为 p_name, official protocol name char Far FAR p_aliases /list of aliases allowed*/ short p_proto, /*official protocol number/ 哈工大计算机学院李全龙 Network Application Development Client Software Desi 14
哈工大计算机学院 李全龙 Network Application Development Client Software Design 14 Looking up a protocol by name getprotobyname returns the address of a structure of type protoent. Contained in winsock.h. stuct protoent { char FAR* p_name; /*official protocol name */ char FAR* FAR* p_aliases; /*list of aliases allowed*/ short p_proto; /*official protocol number*/ };
Example stuct protoent * pptr, if(φptr= getprotobyname(udp”) /* official protocol number is now in pptr->p_proto*/ 了else /*error occurred- handle it*/ 哈工大计算机学院李全龙 Network Application Development Client Software Desi
哈工大计算机学院 李全龙 Network Application Development Client Software Design 15 Example stuct protoent *pptr; if (pptr=getprotobyname(“udp”)){ /* official protocol number is now in pptr->p_proto*/ }else { /*error occurred-handle it*/ }