Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 03 Aug 2022 02:49:50 +0000
From:      bugzilla-noreply@freebsd.org
To:        net@FreeBSD.org
Subject:   [Bug 265489] IPV6 Non-Local Bind Operation timeout.
Message-ID:  <bug-265489-7501-1LyWLumjAl@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-265489-7501@https.bugs.freebsd.org/bugzilla/>
References:  <bug-265489-7501@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D265489

--- Comment #2 from todenerey@gmail.com ---
(In reply to Zhenlei Huang from comment #1)
#include <stdio.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>

const char *bind_ip =3D " "; // My /64 block ip.

const char *HOST =3D "2a01:4f8:c0c:bd0a::1";
const int PORT =3D 80;

int main()
{
    int sockfd;
    struct sockaddr_in6 sin;
    struct sockaddr_in6 sa;

    sockfd =3D socket(AF_INET6, SOCK_STREAM, 0);

    if(sockfd =3D=3D -1) {
        perror("Socket error: ");

        return 1;
    }

    int on =3D 1;

    setsockopt(sockfd, IPPROTO_IPV6, IPV6_BINDANY, &on, sizeof(on));

    sin.sin6_family =3D AF_INET6;
    sin.sin6_port =3D htons(0);

    if(inet_pton(AF_INET6, bind_ip, &sin.sin6_addr) !=3D 1)
    {
        fprintf(stderr, "Invalid bind source address.\n");

        return 1;
    }

        sa.sin6_family =3D AF_INET6;
    sa.sin6_port =3D htons(PORT);

    if(inet_pton(AF_INET6, HOST, &sa.sin6_addr) !=3D 1)
    {
        fprintf(stderr, "Invalid host address.\n");

        return 1;
    }

    if(bind(sockfd, (struct sockaddr *) &sin, sizeof(sin)) =3D=3D -1)
    {
        perror("Bind error: ");

        return 1;
    }


    if(connect(sockfd, (struct sockaddr *)&sa, sizeof(sa)) !=3D 0) {
        perror("Connect error: ");

        return 1;
    }


    printf("Connection successful!\n");

    close(sockfd);

    return 0;
}

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-265489-7501-1LyWLumjAl>