[Bug 265489] IPV6 Non-Local Bind Operation timeout.

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 03 Aug 2022 02:49:50 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=265489

--- 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 = " "; // My /64 block ip.

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

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

    sockfd = socket(AF_INET6, SOCK_STREAM, 0);

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

        return 1;
    }

    int on = 1;

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

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

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

        return 1;
    }

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

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

        return 1;
    }

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

        return 1;
    }


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

        return 1;
    }


    printf("Connection successful!\n");

    close(sockfd);

    return 0;
}

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