#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 355 of file INET_Addr.cpp. References ACE_SERVENT_DATA, ACE_OS::getservbyname_r(), and ACE_OS::strtol(). Referenced by ACE_INET_Addr::set().
00357 {
00358 int port_number = 0;
00359
00360 // Maybe port_name is directly a port number?
00361 char *endp = 0;
00362 port_number = static_cast<int> (ACE_OS::strtol (port_name, &endp, 10));
00363
00364 if (port_number >= 0 && *endp == '\0')
00365 {
00366 // Ok, port_name was really a number, and nothing else. We
00367 // store that value as the port number. NOTE: this number must
00368 // be returned in network byte order!
00369 u_short n = static_cast<u_short> (port_number);
00370 n = htons (n);
00371 return n;
00372 }
00373
00374 // We try to resolve port number from its name.
00375
00376 #if defined (ACE_LACKS_GETSERVBYNAME)
00377 port_number = 0;
00378 ACE_UNUSED_ARG (port_name);
00379 ACE_UNUSED_ARG (protocol);
00380 #else
00381 port_number = -1;
00382 servent sentry;
00383 ACE_SERVENT_DATA buf;
00384 servent *sp = ACE_OS::getservbyname_r (port_name,
00385 protocol,
00386 &sentry,
00387 buf);
00388 if (sp != 0)
00389 port_number = sp->s_port;
00390 #endif /* ACE_LACKS_GETSERVBYNAME */
00391
00392 return port_number;
00393 }
|
1.3.6