#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 | |
static int | get_port_number_from_name (const char port_name[], const char protocol[]) |
static int get_port_number_from_name | ( | const char | port_name[], | |
const char | protocol[] | |||
) | [static] |
Definition at line 431 of file INET_Addr.cpp.
References ACE_HTONS, ACE_MAX_DEFAULT_PORT, ACE_OS::getservbyname_r(), and ACE_OS::strtol().
Referenced by ACE_INET_Addr::set().
00433 { 00434 // Maybe port_name is directly a port number? 00435 char *endp = 0; 00436 long port_number = ACE_OS::strtol (port_name, &endp, 10); 00437 00438 if (*endp == '\0') 00439 { 00440 // port_name was really a number, and nothing else. 00441 00442 // Check for overflow. 00443 if (port_number < 0 || port_number > ACE_MAX_DEFAULT_PORT) 00444 return -1; 00445 00446 // Return the port number. NOTE: this number must 00447 // be returned in network byte order! 00448 u_short n = static_cast<u_short> (port_number); 00449 n = ACE_HTONS (n); 00450 return n; 00451 } 00452 00453 // We try to resolve port number from its name. 00454 00455 #if defined (ACE_LACKS_GETSERVBYNAME) 00456 port_number = 0; 00457 ACE_UNUSED_ARG (port_name); 00458 ACE_UNUSED_ARG (protocol); 00459 #else 00460 port_number = -1; 00461 servent sentry; 00462 ACE_SERVENT_DATA buf; 00463 servent *sp = ACE_OS::getservbyname_r (port_name, 00464 protocol, 00465 &sentry, 00466 buf); 00467 if (sp != 0) 00468 port_number = sp->s_port; 00469 #endif /* ACE_LACKS_GETSERVBYNAME */ 00470 00471 return port_number; 00472 }