(usagi-users 03346) Re: Bind on an AF_INET6 socket issue
David Stevens <[email protected]>
| Newsgroups | gmane.linux.ipv6.usagi.users,gmane.network.ipv6.general |
|---|---|
| Message-ID | <OFE0394832.5FD0EEB5-ON88256FFD.0033D48E-88256FFD.0034CACC@us.ibm.com> |
You can bind to link-local addresses. You need to specify which
interface by setting the sin6_scope_id value to the index of the
interface. I expect the scope_id wasn't set to a valid index to get
the ENODEV.
You want something like:
sin6.sin6_family = AF_INET6;
sin6.sin6_port = htonl(myport);
sin6.sin6_scope_id = if_nametoindex("eth0");
if (inet_pton(AF_INET6, "fe80::2a0:9cff:fe00:436",
&sin6.sin6_addr) <= 0) {
/* error */
exit(1);
}
if (bind(s, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
perror("bind");
exit(1);
}
...
+-DLS