Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-07-2010, 06:14 AM
|
#1
|
|
LQ Newbie
Registered: Oct 2010
Posts: 3
Rep:
|
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.
|
|
|
|
10-12-2010, 11:48 PM
|
#2
|
|
LQ Newbie
Registered: Oct 2010
Posts: 3
Original Poster
Rep:
|
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
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
|
|
|
|
|
08-15-2011, 02:29 PM
|
#3
|
|
LQ Newbie
Registered: Aug 2011
Posts: 1
Rep: 
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:42 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|