2
votes
  1. I have configured Ubuntu Linux system with the following interfaces & assigned IPV6 addresses as follows:

    Eth0: Link encap:Ethernet HWaddr 00:50:56:8d:57:64
    inet addr:192.168.254.10 Bcast:0.0.0.0 Mask:255.255.255.0
    inet6 addr: fe80::250:56ff:fe8d:5764/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:74231424 errors:0 dropped:1 overruns:0 frame:0
    TX packets:400372550 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
    RX bytes:24514286488 (24.5 GB) TX bytes:115992171490 (115.9 GB)

    Eth1: Link encap:Ethernet HWaddr 00:50:56:8d:7c:4c
    inet addr:192.168.1.10 Bcast:0.0.0.0 Mask:255.255.255.0
    inet6 addr: fe80::250:56ff:fe8d:7c4c/64 Scope:Link
    inet6 addr: fc00:1234:1::10/120 Scope:Global
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:434933479 errors:0 dropped:1 overruns:0 frame:0
    TX packets:39666183 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
    RX bytes:126065364448 (126.0 GB) TX bytes:14437801257 (14.4 GB)

    Eth2: Link encap:Ethernet HWaddr 00:50:56:8d:56:14
    inet addr:192.168.2.10 Bcast:0.0.0.0 Mask:255.255.255.0
    inet6 addr: fc00:1234:2::10/120 Scope:Global
    inet6 addr: fe80::250:56ff:fe8d:5614/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:480068741 errors:0 dropped:0 overruns:0 frame:0
    TX packets:34145702 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
    RX bytes:146795537550 (146.7 GB) TX bytes:10045338657 (10.0 GB)

  2. I wanted to do Socket programming using IPV6 sockets. The code snippet that I have written is as follows:

    struct sockaddr_in6 sin
    Ipv6_fdr = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP)

    bzero(&sin, sizeof(sin));
    sin.sin6_family = AF_INET6;
    sin.sin6_port = htons(2152);
    if ((setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int))) < 0)
    memcpy(&(sin.sin6_addr), "fc00:1234:1::10",sizeof(sin.sin6_addr));
    if ((bind(sock, (struct sockaddr*)&sin, sizeof(sin)))< 0)

  3. After successful compilation, I’m getting IPV6 bind failure Error with the following error number & name:
    EADDRNOTAVAIL 99 /* Cannot assign requested address.
    After certain number of attempts for IPV6 Binding it throws Segmentation Fault error.

It would be great if someone could help me on what mistake I’m doing here & why IPV6 binding is failing?

1
FYI, the address, fc00:1234:1::10, is in a reserved range that you are not allowed to use. ULA addressing is in the fc00::/7 range, but the fc00::/8 half of the range is reserved for a yet-to-be-named global authority to assign. The fd00::/8 half of the range is open for local assignment, but you MUST use a random number generator to assign the next 40 bits in the address. You also seem to have a problem that you are not using /64 as the network size. Many things in IPv6 can fail if you use a different network size. With only a couple of exceptions, you should use /64 networks.Ron Maupin
@RonMaupin I tried changing my IPV6 address with a /64 network size as suggested by you. Also, I tried different inet6 addresses of various prefixes & different network configurations ranges. Still the same problem persists on running the script. IPV6 Bind failure: Cannot assign requested address. Kindly help me on the same.Kushal
I wasn't trying to solve the problem in your question. I was trying to guide you to proper IPv6 addressing, which I don't believe is your posted problem, but it could pose a different set of problems if you fix your current problem.Ron Maupin

1 Answers

3
votes

The problem in your code is the line:

memcpy(&(sin.sin6_addr), "fc00:1234:1::10",sizeof(sin.sin6_addr));

It is necessary to convert the human readable string to binary and store the binary form of address to sin6_addr like:

inet_pton (AF_INET6, "fc00:1234:1::10", sin.sin6_addr.s6_addr);