找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 4207|回复: 1

如何将字符串转换为地址?

[复制链接]
发表于 2008-4-18 22:23:24 | 显示全部楼层 |阅读模式
怎样将字符串192.168.1.233:21转换为ace_inet_addr的对象?说详细点,谢谢拉
发表于 2008-4-22 17:30:47 | 显示全部楼层
ACE_INET_Addr有一个构造函数满足你的要求:

/**
   * Initializes an ACE_INET_Addr from the <address>, which can be
   * "ip-number:port-number" (e.g., "tango.cs.wustl.edu:1234" or
   * "128.252.166.57:1234").  If there is no ':' in the <address> it
   * is assumed to be a port number, with the IP address being
   * INADDR_ANY.
   */
  explicit ACE_INET_Addr (const char address[],
                          int address_family = AF_UNSPEC);



调用方式就很简单了三,
ACE_INET_Addr addr("192.168.1.233:21", AF_INET);


同时,还有一个set()函数也可以做同样的操作:

  /**
   * Initializes an ACE_INET_Addr from the @a addr, which can be
   * "ip-number:port-number" (e.g., "tango.cs.wustl.edu:1234" or
   * "128.252.166.57:1234").  If there is no ':' in the <address> it
   * is assumed to be a port number, with the IP address being
   * INADDR_ANY.
   */
  int set (const char addr[], int address_family = AF_UNSPEC);

调用方式如下:
ACE_INET_Addr addr;
addr.set("192.168.1.233:21", AF_INET);

[ 本帖最后由 earthdog 于 2008-4-22 17:32 编辑 ]
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-12-23 13:49 , Processed in 0.040875 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表