Roy Smith <(E-Mail Removed)> writes:
> In article <Xns992ED8B1141C1JamesLLugojcom@216.168.3.30>,
> Jim Logajan <(E-Mail Removed)> wrote:
>
> > Roy Smith <(E-Mail Removed)> wrote:
> > > The code below attempts to bind an IPv6 address to an AF_INET socket.
> > > I belive this should fail, yet when compiled and run on our RedHat
> > > AS-3 and AS-4 boxes, it prints "bind worked". Does this make sense?
> >
> > It makes sense and if the underlying OS supports IPv6 then the bind should
> > work. The behavior of bind() under IPv6 is described in RFC 3493.
> >
> > Why do you believe the bind should fail?
>
> Because I'm trying to bind an AF_INET6 address to a PF_INET socket. I
> don't see anything in 3493 that explicitly says this will fail, but it
> seems logical. This isn't something which "3.7 Compatibility with IPv4
> Nodes" talks about.
Yes. This is logical, because RFC 3493 defines new protocol family PF_INET6.
| 3.1 IPv6 Address Family and Protocol Family
|
| A new address family name, AF_INET6, is defined in <sys/socket.h>.
| The AF_INET6 definition distinguishes between the original
| sockaddr_in address data structure, and the new sockaddr_in6 data
| structure.
|
| A new protocol family name, PF_INET6, is defined in <sys/socket.h>.
| Like most of the other protocol family names, this will usually be
| defined to have the same value as the corresponding address family
| name:
|
| #define PF_INET6 AF_INET6
|
| The AF_INET6 is used in the first argument to the socket() function
| to indicate that an IPv6 socket is being created.
> > > #include <sys/types.h>
> > > #include <sys/socket.h>
> > > #include <netinet/in.h>
> > > #include <errno.h>
> > > #include <stdio.h>
> > >
> > > int main (int argc, char* argv[]) {
> > > Â* Â* int s = socket(PF_INET, SOCK_STREAM, 0);
> > > Â* Â* printf ("s = %d\n", s);
> > >
> > > Â* Â* struct in6_addr anyaddr = IN6ADDR_ANY_INIT;
> > > Â* Â* struct sockaddr_in6 sa;
> > >
> > > Â* Â* sa.sin6_family = AF_INET6;
> > > Â* Â* sa.sin6_port = 0;
> > > Â* Â* sa.sin6_flowinfo = 0;
> > > Â* Â* sa.sin6_addr = anyaddr;
> > > Â* Â* sa.sin6_scope_id = 0;
> > >
> > > Â* Â* int retval = bind(s, (struct sockaddr*) &sa, sizeof (sa));
> > > Â* Â* if (retval == 0) {
> > > Â* Â* Â* Â* printf ("bind worked\n");
> > > Â* Â* } else {
> > > Â* Â* Â* Â* perror ("bind failed");
> > > Â* Â* }
> > > }
|