擴大IPv6地址我想拓展我的IPv6 address.Is有沒有辦法到該地址擴展到完整的一個? 如果我得到ABCD:12 :: 7然後我需要把它擴大到ABCD:0012:0000:0000:0000:0000:0000:0007 主要用於incrementating地址。如何在C
我已經寫了一些代碼,但顯示錯誤。錯誤是 - 「致命錯誤C1083:無法打開包含文件:'arpa/inet.h':沒有這樣的文件或目錄」。我正在使用visual studio 2005。
擴大IPv6地址我想拓展我的IPv6 address.Is有沒有辦法到該地址擴展到完整的一個? 如果我得到ABCD:12 :: 7然後我需要把它擴大到ABCD:0012:0000:0000:0000:0000:0000:0007 主要用於incrementating地址。如何在C
我已經寫了一些代碼,但顯示錯誤。錯誤是 - 「致命錯誤C1083:無法打開包含文件:'arpa/inet.h':沒有這樣的文件或目錄」。我正在使用visual studio 2005。
對於任何類型的IPv6的地址操作,你需要將它存儲爲4個無符號整型(4字節每個)的陣列。多數棧它存儲有點像這個,這是從Linux內核:
struct in6_addr {
union {
__u8 u6_addr8[16];
__be16 u6_addr16[8];
__be32 u6_addr32[4];
} in6_u;
#define s6_addr in6_u.u6_addr8
#define s6_addr16 in6_u.u6_addr16
#define s6_addr32 in6_u.u6_addr32
};
您需要將您的字符串轉換爲使用inet_pton()
這種壓縮格式。
我的代碼 - 的#include 「stdafx.h中」 的#include 「string.h中」 的#include 「stdlib.h中」 的#include 「CONIO.H」 的#include 「ARPA/inet.h」 INT _tmain (INT的argc,argv的炭[]){ 結構in6_addr { 無符號字符s6_addr [16]; // IPv6地址 }; struct in6_addr ipv6; char str [] =「abcd:1234 :: ffff」; 如果(strcnt(STR, 「:」)> 1) { \t如果(inet_pton(AF_INET6,STR,和ipv6.s6_addr)) \t \t的printf( 「%s是%0llu(IPv6)的\ n」 個,STR ,ipv6.s6_addr); \t else \t \t printf(「Error ..」); } 的getch(); return 0; } – Neha
問題,看起來像命令不上這個網站很好地工作。嘗試發佈你嘗試過的東西。 – cnicutar