Date
Nov. 23rd, 2024
 
2024年 10月 23日

Post: iOS: in6_addr to string

iOS: in6_addr to string

Published 12:10 Oct 20, 2016.

Created by @ezra. Categorized in #Programming, and tagged as #iOS.

Source format: Markdown

Table of Content

struct in6_addr 转换为字符串:

+ (NSString *)formatIPV6Address:(struct in6_addr)ipv6Addr {
    NSString *address = nil;

    char dstStr[INET6_ADDRSTRLEN];
    char srcStr[INET6_ADDRSTRLEN];

    memcpy(srcStr, &ipv6Addr, sizeof(struct in6_addr));

    if (inet_ntop(AF_INET6, srcStr, dstStr, INET6_ADDRSTRLEN) != NULL){
        address = [NSString stringWithUTF8String:dstStr];
    }

    return address;
}
Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询