Bind ipv6 socket fails on 8.3 (1188 Views)
Reply
Advisor
Trifox
Posts: 15
Registered: ‎05-28-2004
Message 1 of 18 (1,188 Views)

Bind ipv6 socket fails on 8.3

I cannot bind an ipv6 socket on 8.3 using tcpip 5.6. I know that the sockaddr_in6 structure is correct because the same code works on OVMS 7.3 AXP, Windows and *nix. I keep getting EINVAL. I dumped the contents of the sockaddr_in6 structure before the bind call and it is identical to the one on AXP. The length is the same. But the bind() always fails.  The sample in the HP TCPIP manual fails in the same way. Is there an ECO that I need to apply? Do I have to upgrade to 8.4? BTW ipv4 sockets work perfectly.

Honored Contributor
Steven Schweda
Posts: 9,091
Registered: ‎02-23-2005
Message 2 of 18 (1,162 Views)

Re: Bind ipv6 socket fails on 8.3

Occasional Visitor
MarkFromAUS
Posts: 2
Registered: ‎11-23-2013
Message 3 of 18 (1,153 Views)

Re: Bind ipv6 socket fails on 8.3

Mate, for goodness sake post some code or expect the echoes of a vacant house to whisper in your ears.

Advisor
Trifox
Posts: 15
Registered: ‎05-28-2004
Message 4 of 18 (1,126 Views)

Re: Bind ipv6 socket fails on 8.3

HP TCP/IP Services for OpenVMS Industry Standard 64 Version V5.6

on an HP rx2600  (1.50GHz/6.0MB) running OpenVMS 8.3

 

I have the latest OVMS 8.3 Patch Bundle V18 installed.

 

From the

HP TCP/IP Services for OpenVMS
Sockets API and System Services Programming Guide, Appendix E.6:

************************************

#include <in.h>                       /* define internet related constants,
                                      /* functions, and structures            */
#include <inet.h>                     /* define network address info          */

#include <netdb.h>                    /* define network database library info */

#include <socket.h>                   /* define BSD 4.x socket api            */
#include <stdio.h>                    /* define standard i/o functions        */
#include <stdlib.h>                   /* define standard library functions    */
#include <string.h>                   /* define string handling functions     */

#include <unixio.h>                   /* define unix i/o                      */

#define SERV_BACKLOG    1             /* server backlog                       */
#define SERV_PORTNUM    12345         /* server port number                   */

int  main( void );                    /* server main                          */

int
main( void )
{
    int optval = 1;                   /* SO_REUSEADDR'S option value (on)     */

    int conn_sockfd;                  /* connection socket descriptor         */
    int listen_sockfd;                /* listen socket descriptor             */
    int gni_error;                   /* return status for getnameinfo()      */

    unsigned int client_addrlen;      /* returned length of client socket     */
                                      /* address structure                    */
    struct sockaddr_in6 client_addr;  /* client socket address structure      */
    struct sockaddr_in6 serv_addr;    /* server socket address structure      */

    char buf[] = "Hello, world!";     /* server data buffer                   */
    char node[NI_MAXHOST];            /* buffer to receive node name          */
    char port[NI_MAXHOST];            /* buffer to receive port number        */
    char addrbuf[INET6_ADDRSTRLEN];   /* buffer to receive host's address     */

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

    memset( &serv_addr, 0, sizeof(serv_addr) );
    serv_addr.sin6_family      = AF_INET6;
    serv_addr.sin6_port        = htons( SERV_PORTNUM );
    serv_addr.sin6_addr        = in6addr_any;

    if ( (listen_sockfd = socket(AF_INET6, SOCK_STREAM, 0)) < 0 )
        {
        perror( "Failed to create socket" );
        exit( EXIT_FAILURE );
        }

    if ( setsockopt(listen_sockfd,
         SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0 )
        {
        perror( "Failed to set socket option" );
        exit( EXIT_FAILURE );
        }

    if ( bind(listen_sockfd,
         (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0 )
        {
        perror( "Failed to bind socket" );
        exit( EXIT_FAILURE );
        }

    if ( listen(listen_sockfd, SERV_BACKLOG) < 0 )
        {
        perror( "Failed to set socket passive" );
        exit( EXIT_FAILURE );
        }

    printf( "Waiting for a client connection on port: %d\n",
            ntohs(serv_addr.sin6_port)
          );

    client_addrlen = sizeof(client_addr);

    conn_sockfd = accept( listen_sockfd,
                          (struct sockaddr *) &client_addr,
                          &client_addrlen
                          );
    if ( conn_sockfd < 0 )
        {
        perror( "Failed to accept client connection" );
        exit( EXIT_FAILURE );
        }

    gni_error = getnameinfo( (struct sockaddr *)&client_addr,client_addrlen,
                             node, sizeof(node), NULL, 0, NI_NAMEREQD
                             );
    if ( gni_error )
        {
        printf( "Failed to translate client address: %s\n",
                gai_strerror(gni_error)
              );
        exit( EXIT_FAILURE );
        }

    gni_error = getnameinfo( (struct sockaddr *)&client_addr, client_addrlen,
                             addrbuf, sizeof(addrbuf), port, sizeof(port),
                             NI_NUMERICHOST | NI_NUMERICSERV
                           );
    if ( gni_error )
        {
        printf( "Failed to translate client address and/or port: %s\n",
                gai_strerror(gni_error)
              );
 exit( EXIT_FAILURE );
        }

    printf( "Accepted connection from host: %s (%s), port: %s\n",
            node, addrbuf, port
          );

    if ( send(conn_sockfd, buf, sizeof(buf), 0) < 0 )
        {
        perror( "Failed to write data to client connection" );
        exit( EXIT_FAILURE );
        }

    printf( "Data sent: %s\n", buf );    /* output server's data buffer       */

    if ( shutdown(conn_sockfd, 2) < 0 )
        {
        perror( "Failed to shutdown client connection" );
        exit( EXIT_FAILURE );
        }

    if ( close(conn_sockfd) < 0 )
        {
        perror( "Failed to close socket" );
        exit( EXIT_FAILURE );
        }

    if ( close(listen_sockfd) < 0 )
        {
        perror( "Failed to close socket" );
        exit( EXIT_FAILURE );
        }

    exit( EXIT_SUCCESS );
}

************************

 

It fails at the bind() call. I am wondering if there is something that I need to turn on in TCPIP for IPV6 but I never did anything like that on our 7.3 AXP. I did run the TCPIP$IP6_SETUP script.

 

Honored Contributor
Steven Schweda
Posts: 9,091
Registered: ‎02-23-2005
Message 5 of 18 (1,111 Views)

Re: Bind ipv6 socket fails on 8.3

Advisor
Trifox
Posts: 15
Registered: ‎05-28-2004
Message 6 of 18 (1,108 Views)

Re: Bind ipv6 socket fails on 8.3

The original submission says bind() fails with EINVAL. I looked for TCPIP ECOs but did not find any. You are running 8.3-1H1, I am running 8.3, hence the difference in (cut and pasted) version strings.

Honored Contributor
Steven Schweda
Posts: 9,091
Registered: ‎02-23-2005
Message 7 of 18 (1,098 Views)

Re: Bind ipv6 socket fails on 8.3

Advisor
Trifox
Posts: 15
Registered: ‎05-28-2004
Message 8 of 18 (1,094 Views)

Re: Bind ipv6 socket fails on 8.3

TCPIP ECO5 does not help, still fails. Take the sample code, compile,link and run it.

Super Advisor
MarkOfAus
Posts: 170
Registered: ‎01-08-2007
Message 9 of 18 (1,031 Views)

Re: Bind ipv6 socket fails on 8.3

Call me thick, but I don't see in the code where errno is used? Are you compiling something not the same as this code?

 

Also, perhaps you could show the ACTUAL output of the executable.

 

It may be failing, but this code you posted gives NO indication as to what error is being issued, other than the generic trap to check bind() returns -1.

 

 

On the off chance, that socket's not being used?

 

Do a netstat of the system just to eliminate this possibility.

 

You may need to run @sys$manager:tcpip$define_commands before hand.

 

 

 

Advisor
Trifox
Posts: 15
Registered: ‎05-28-2004
Message 10 of 18 (1,027 Views)

Re: Bind ipv6 socket fails on 8.3

The

 

perror( "Failed to bind socket" );

 

returns the message:

 

Failed to bind socket: invalid argument

 

Invalid argument means EINVAL.  Output is

 

TRI21>cc/decc qq

TRI21>link qq,tcpip$library:tcpip$lib/lib

TRI21>run qq

Failed to bind socket: invalid argument

TRI21>

 

nestat shows

 

Active Internet connections
Proto Recv-Q Send-Q  Local Address             Foreign Address           (state)

tcp        0      0  tri21.49152               RAD.2049                  ESTABLI
SHED
tcp        0      0  tri21.23                  RAD.53979                 ESTABLI
SHED
tcp        0      0  *.611                     *.*                       LISTEN
udp        0      0  fe80::230:6eff:fe39:575b.123 *.*
udp        0      0  tri21.123                 *.*
udp        0      0  localhost.123             *.*
udp        0      0  LOCALHOST.123             *.*
udp        0      0  *.123                     *.*

 

 

Super Advisor
MarkOfAus
Posts: 170
Registered: ‎01-08-2007
Message 11 of 18 (1,008 Views)

Re: Bind ipv6 socket fails on 8.3

(WHY .. WHY... WHY with this software do you lose the ability to view all messages under the current subject when you reply. What brain-dead software!)

 

Can you throw in:

char ip6addr[INET6_ADDRSTRLEN];

inet_ntop(AF_INET6, &(serv_addr.sin6_addr), ip6addr, INET6_ADDRSTRLEN);

printf("The address is: %s\n", ip6addr);

 

Does it return your IP6 address?

Acclaimed Contributor
Dennis Handly
Posts: 25,198
Registered: ‎03-06-2006
Message 12 of 18 (1,002 Views)

Re: Bind IPv6 socket fails on 8.3

>Why with this software do you lose the ability to view all messages under the current subject when you reply?

 

That's what tabs are for.  :-)

There is a "View discussion in a popup" link on the reply page and the post you are replying to.

 

Super Advisor
MarkOfAus
Posts: 170
Registered: ‎01-08-2007
Message 13 of 18 (984 Views)

Re: Bind IPv6 socket fails on 8.3

I have no idea what "tabs" are? Maybe it's a firefox thing. Perhaps it's because I don't enable every site because I use NoScript.

 

I now see the "View discussion in a popup" - a rather vague html link. A button would do wonders, one would think?

 

Anyway, thanks for the heads-up.

Super Advisor
MarkOfAus
Posts: 170
Registered: ‎01-08-2007
Message 14 of 18 (983 Views)

Re: Bind ipv6 socket fails on 8.3

Trifox,

 

Also, I was doing some debugging myself (different platform) and was using strace. So I recalled there's a similar approach available on VMS:

 

set proc/sslog

 

and

 

analyze/sslog

 

Run the program after you've done the set proc then analyze it. Maybe that will shed some light on the issue.

 

Acclaimed Contributor
Dennis Handly
Posts: 25,198
Registered: ‎03-06-2006
Message 15 of 18 (970 Views)

Re: Bind IPv6 socket fails on 8.3

>I have no idea what "tabs" are? Maybe it's a firefox thing.

 

No, tabs is a browser-wide feature, though firefox had it before IE.  It allows multiple pages in a browser window, and clicking on a tab will switch between the two.

Super Advisor
MarkOfAus
Posts: 170
Registered: ‎01-08-2007
Message 16 of 18 (962 Views)

Re: Bind IPv6 socket fails on 8.3

Ah, right, browser tabs were what you were referring to.

 

Yes, I know what browser tabs are, thanks.

Advisor
Trifox
Posts: 15
Registered: ‎05-28-2004
Message 17 of 18 (943 Views)

Re: Bind ipv6 socket fails on 8.3

It returns

 

TRI21>run qq
The address is: >::<
Failed to bind socket: invalid argument

TRI21>

 

The same is returned on OVMS 7.3 AXP as well as Linux, except that those work. BTW  I updated the machine to OVMS 8.4 with the 900 patchset and TCPIP version 5.7 with ECO 4.

 

 

Advisor
Trifox
Posts: 15
Registered: ‎05-28-2004
Message 18 of 18 (942 Views)

Re: Bind ipv6 socket fails on 8.3

analyze/ssylog results attached. Nothing obvious to me but then I think the bind() EINVAL is happening right up front, long before it gets to any system calls.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.