Question
C++ program question-----Conversion of IPv6 address from binary to text format. The basic parts of the code and the output are provided in the following
C++ program question-----Conversion of IPv6 address from binary to text format. The basic parts of the code and the output are provided in the following text. How to program the rest? ( The remaining part of coding)
#include
using namespace std; char toHex(unsigned d);
char* bin2Text_IPv6(const unsigned char *v) { // Convert an IPv6 address from binary to text format. // See the pdf file for the explanation on the conversion requirements.
// IPv6 address is an 128-bit bit-vector represented by an array of 16 unsigned char. // v[0] represents the left most 8 bits of the IPv6 address, and so on. // Bits in a byte are numbered from 7 down to 0 (from left to right). // The 7-th bit of v[0] is the first bit of the IPv6 address.
char *a = new char[40]; // IPv6 address in text format is up to 40 chars, including '\0'
a[0] = '\0'; // dummy statement, replace it by your own codes
// !!!The remaining part of coding!!!
return a; }
char toHex(unsigned d) { // Precondition: 0
if (d >= 10) return d - 10 + 'a'; return d + '0'; }
void printIPv6address_hex(const unsigned char *v) { cout
void test2(unsigned char *v) { cout
void part_2() { cout
// An IPv6 address (in binary) is represented by an array of unsigned char of size 16.
unsigned char v1[] = { 0x12, 0x34, 0x0a, 0xbc, 0x00, 0x00, 0x00, 0x78, 0xff, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x05 }; unsigned char v2[] = { 0x20, 0x01, 0x0d, 0xb8, 0x00, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x08 }; unsigned char v3[] = { 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; unsigned char v4[] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x70, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 }; unsigned char v5[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; unsigned char v6[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
test2(v1); test2(v2); test2(v3); test2(v4); test2(v5); test2(v6); }
int main() { part_2();
system("pause"); return 0; }
IPv6 address (bin) 1234:0abc: 0000:0078: ff00:0000:0030:0005 IPv6 address (text) 1234:abc:0:78: ff00:0:30:5 IPv6 address (bin) 2001: Odb8:00a3:0000:0000:0000:0200:0008 IPv6 address (text) 2001:db8:a3::200:8 IPv6 address (bin) 2001: Odb8:0000:0000:0001: 0000:0000:0000 IPv6 address (text) 2001:db8:0:0:1:: IPv6 address (bin) 0000:0000:0101:7000:0003: 0000:0000:0004 IPv6 address (text) :: 101:7000:3:0:0:4, IPv6 address (bin) 0000:0000:0000:0000:0000:0000:0000:0001 IPv6 address (text) ::1 IPv6 address (bin) 0000:0000:0000:0000:0000:0000:0000:0000 IPv6 address (text)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started