【问题标题】:inet_ntoa for ipv6 in perlperl 中用于 ipv6 的 inet_ntoa
【发布时间】:2015-09-02 10:07:31
【问题描述】:

我是 perl 新手,我正在尝试将网络格式的 ipv6 地址转换为 ascii 字符串格式。我可以使用“Socket”模块中的“inet_ntoa”函数为 ipv4 地址执行此操作。如何在不安装任何新模块的情况下为 ipv6 地址执行此操作?

【问题讨论】:

    标签: perl ipv6 inet-aton


    【解决方案1】:

    按照perldoc Socket的建议使用inet_ntop

    $string = inet_ntoa $ip_address

       Takes a packed binary address structure such as returned by
       unpack_sockaddr_in() (or a v-string representing the four octets of the
       IPv4 address in network order) and translates it into a string of the form
       "d.d.d.d" where the "d"s are numbers less than 256 (the normal
       human-readable four dotted number notation for Internet addresses).
    
       This IPv4-only function is provided largely for legacy reasons.
       Newly-written code should use getnameinfo() or inet_ntop() instead for
       IPv6 support.
    

    $string = inet_ntop $family, $address

       Takes an address family and a packed binary address structure and
       translates it into a human-readable textual representation of the address;
       typically in "d.d.d.d" form for "AF_INET" or "hhhh:hhhh::hhhh" form for
       "AF_INET6".
       See also getnameinfo() for a more powerful and flexible function to turn
       socket addresses into human-readable textual representations.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-06
      • 1970-01-01
      • 2014-08-25
      • 2011-02-14
      • 2012-02-26
      • 2014-05-30
      • 1970-01-01
      • 2011-01-31
      相关资源
      最近更新 更多