#include "ace/INET_Addr.h"
#include "ace/Log_Msg.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_errno.h"
#include "ace/OS_NS_stdlib.h"
#include "ace/OS_Memory.h"
#include "ace/OS_NS_arpa_inet.h"
#include "ace/OS_NS_netdb.h"
#include "ace/OS_NS_unistd.h"
#include "ace/OS_NS_sys_socket.h"
Include dependency graph for INET_Addr.cpp:
Go to the source code of this file.
Functions | |
int | get_port_number_from_name (const char port_name[], const char protocol[]) |
|
Definition at line 413 of file INET_Addr.cpp. References ACE_HTONS, ACE_SERVENT_DATA, ACE_OS::getservbyname_r(), and ACE_OS::strtol(). Referenced by ACE_INET_Addr::set().
00415 { 00416 int port_number = 0; 00417 00418 // Maybe port_name is directly a port number? 00419 char *endp = 0; 00420 port_number = static_cast<int> (ACE_OS::strtol (port_name, &endp, 10)); 00421 00422 if (port_number >= 0 && *endp == '\0') 00423 { 00424 // Ok, port_name was really a number, and nothing else. We 00425 // store that value as the port number. NOTE: this number must 00426 // be returned in network byte order! 00427 u_short n = static_cast<u_short> (port_number); 00428 n = ACE_HTONS (n); 00429 return n; 00430 } 00431 00432 // We try to resolve port number from its name. 00433 00434 #if defined (ACE_LACKS_GETSERVBYNAME) 00435 port_number = 0; 00436 ACE_UNUSED_ARG (port_name); 00437 ACE_UNUSED_ARG (protocol); 00438 #else 00439 port_number = -1; 00440 servent sentry; 00441 ACE_SERVENT_DATA buf; 00442 servent *sp = ACE_OS::getservbyname_r (port_name, 00443 protocol, 00444 &sentry, 00445 buf); 00446 if (sp != 0) 00447 port_number = sp->s_port; 00448 #endif /* ACE_LACKS_GETSERVBYNAME */ 00449 00450 return port_number; 00451 } |