in_addr_t to string

后端 未结 3 1167
太阳男子
太阳男子 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;
        }
    }
    

提交回复
热议问题