Operating System - OpenVMS
1824976 Members
3223 Online
109678 Solutions
New Discussion юеВ

Bind ipv6 socket fails on 8.3

 
Trifox
Advisor

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.

17 REPLIES 17
Steven Schweda
Honored Contributor

Re: Bind ipv6 socket fails on 8.3

 
MarkFromAUS
Occasional Visitor

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.

Trifox
Advisor

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.

 

Steven Schweda
Honored Contributor

Re: Bind ipv6 socket fails on 8.3

 
Trifox
Advisor

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.

Steven Schweda
Honored Contributor

Re: Bind ipv6 socket fails on 8.3

 
Trifox
Advisor

Re: Bind ipv6 socket fails on 8.3

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

MarkOfAus
Valued Contributor

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.

 

 

 

Trifox
Advisor

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                     *.*

 

 

MarkOfAus
Valued Contributor

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?

Dennis Handly
Acclaimed Contributor

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.

 

MarkOfAus
Valued Contributor

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.

MarkOfAus
Valued Contributor

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.

 

Dennis Handly
Acclaimed Contributor

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.

MarkOfAus
Valued Contributor

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.

Trifox
Advisor

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.

 

 

Trifox
Advisor

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.