LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-07-2010, 06:14 AM   #1
lprasanna
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Rep: Reputation: 0
bind() fails with EADDRNOTAVAIL after calling an SIOCSIFADDR ioctl for IPV6 address


Hi,

I am trying to assign an IPV6 address to the interface using SIOCSIFADDR ioctl call. After that trying to bind to that particular IPV6 address added. Bind fails with errno 99 (EADDRNOTAVAIL).
Tried introducing some sleep after ioctl and before bind() call, the same error is returned.

Linux kernel version is 2.6.28.9.

Does anyone know how to fix this??

The program is below:
OUTPUT:

fed1::81
Error: 0
Return of Bind: -1, errno: 99


struct sockaddr_in6 in_addr;
void setIP()
{
struct ifreq ifr;
struct in6_ifreq ifr6;
int socv6;
char ip[50]={0};

memset(&in_addr, 0, sizeof(in_addr));

socv6=socket(AF_INET6, SOCK_DGRAM, 0);
strcpy(ifr.ifr_name,"eth0");
ioctl(socv6, SIOGIFINDEX, &ifr);

ifr6.ifr6_ifindex = ifr.ifr_ifindex;
ifr6.ifr6_prefixlen = 64;

inet_pton(AF_INET6, "fed1::81", &in_addr);
inet_pton(AF_INET6, "fed1::81", &ifr6.ifr6_addr);
inet_ntop(AF_INET6, &in_addr, &ip, sizeof(ip) );

inet_ntop(AF_INET6, &ifr6.ifr6_addr, &ip, sizeof(ip) );
printf("%s:\n", ip);

ioctl(socv6,SIOCSIFADDR,&ifr6);
printf("Error: %d\n",errno);
}
int main()
{
int sockFd=0, ret =0;

setIP();

sockFd = socket(AF_INET6, SOCK_STREAM, 0);
inet_pton(AF_INET6, "fed1::81", &(in_addr.sin6_addr));

int one = 1;

if (setsockopt(sockFd, SOL_SOCKET, SO_REUSEADDR, &one,
sizeof(one)) < 0)
{
printf("ERROR in set_sockopt(): %d\n", errno);
return 0;
}

in_addr.sin6_port = htons(8888);
in_addr.sin6_family = AF_INET6;

ret = bind(sockFd, (struct sockaddr *)&in_addr, sizeof(in_addr));
printf("Return of Bind: %d, errno: %d\n", ret, errno);

getchar();
return 0;
}

thanks in advance,
Lakshmi

Last edited by lprasanna; 10-08-2010 at 03:26 AM.
 
Old 10-12-2010, 11:48 PM   #2
lprasanna
LQ Newbie
 
Registered: Oct 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Hi,

Found a workaround at this blog http://mwnnlin.blogspot.com/2010/05/...nd-issues.html.

If anyone knows of another solution other than modifying the Kernel source and disabling DAD requests, please reply..

thanks
Lakshmi


Quote:
Originally Posted by lprasanna View Post
Hi,

I am trying to assign an IPV6 address to the interface using SIOCSIFADDR ioctl call. After that trying to bind to that particular IPV6 address added. Bind fails with errno 99 (EADDRNOTAVAIL).
Tried introducing some sleep after ioctl and before bind() call, the same error is returned.

Linux kernel version is 2.6.28.9.

Does anyone know how to fix this??

The program is below:
OUTPUT:

fed1::81
Error: 0
Return of Bind: -1, errno: 99


struct sockaddr_in6 in_addr;
void setIP()
{
struct ifreq ifr;
struct in6_ifreq ifr6;
int socv6;
char ip[50]={0};

memset(&in_addr, 0, sizeof(in_addr));

socv6=socket(AF_INET6, SOCK_DGRAM, 0);
strcpy(ifr.ifr_name,"eth0");
ioctl(socv6, SIOGIFINDEX, &ifr);

ifr6.ifr6_ifindex = ifr.ifr_ifindex;
ifr6.ifr6_prefixlen = 64;

inet_pton(AF_INET6, "fed1::81", &in_addr);
inet_pton(AF_INET6, "fed1::81", &ifr6.ifr6_addr);
inet_ntop(AF_INET6, &in_addr, &ip, sizeof(ip) );

inet_ntop(AF_INET6, &ifr6.ifr6_addr, &ip, sizeof(ip) );
printf("%s:\n", ip);

ioctl(socv6,SIOCSIFADDR,&ifr6);
printf("Error: %d\n",errno);
}
int main()
{
int sockFd=0, ret =0;

setIP();

sockFd = socket(AF_INET6, SOCK_STREAM, 0);
inet_pton(AF_INET6, "fed1::81", &(in_addr.sin6_addr));

int one = 1;

if (setsockopt(sockFd, SOL_SOCKET, SO_REUSEADDR, &one,
sizeof(one)) < 0)
{
printf("ERROR in set_sockopt(): %d\n", errno);
return 0;
}

in_addr.sin6_port = htons(8888);
in_addr.sin6_family = AF_INET6;

ret = bind(sockFd, (struct sockaddr *)&in_addr, sizeof(in_addr));
printf("Return of Bind: %d, errno: %d\n", ret, errno);

getchar();
return 0;
}

thanks in advance,
Lakshmi
 
Old 08-15-2011, 02:29 PM   #3
AGWA
LQ Newbie
 
Registered: Aug 2011
Posts: 1

Rep: Reputation: Disabled
It's possible to disable DAD (and thus fix this problem) without patching the kernel. You just need to set net.ipv6.conf.INTERFACE.accept_dad to 0 in sysctl.

For example, before bringing up eth0, run:

Code:
echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_dad
If you're using Debian, you can put this in your interfaces file as a "pre-up" command.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get IPv6 address using ioctl() SIOCGIFADDR ashok449 Linux - Networking 6 01-03-2012 11:39 PM
[bind] reverse lookup for loopback ipv6 address yuguri Linux - Server 1 02-26-2011 05:00 PM
Cannot create an IPv6 virtual IP (alias interface) using ioctl(SIOCSIFADDR) the_rock Linux - Newbie 2 08-20-2010 04:14 PM
bind() is failing with errno=EADDRNOTAVAIL (99); the man page forbids this shachter Linux - Networking 1 05-09-2008 03:20 AM
bind() fail while binding to an IPv6 Address ydb82 Programming 3 07-05-2005 05:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration