in_addr_t to string

后端 未结 3 1238
太阳男子
太阳男子 2021-02-20 12:19

I have an IP address stored in in_addr_t and I want to create the corresponding string representation of this data type (e.g. in_addr_t to 10.0.0

相关标签:
3条回答
  • 2021-02-20 12:35
    -(NSString*)long2ip:(uint32_t)ip
    {
        char str[40];
        struct in_addr myaddr;
        myaddr.s_addr = htonl(ip);
        if (inet_ntop(AF_INET, &myaddr, str, sizeof(str)))
        {
            return [NSString stringWithFormat:@"%s",str];
        }
        else
        {
            return nil;
        }
    }
    
    0 讨论(0)
  • 2021-02-20 12:40

    Use inet_ntop() - convert IPv4 and IPv6 addresses from binary to text form.

    0 讨论(0)
  • 2021-02-20 12:59

    char *inet_ntoa(struct in_addr in);
    is the desired function.

    0 讨论(0)
提交回复
热议问题