Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

get IP address of client socket #232

@kaiduanx

Description

@kaiduanx

I want to get the IP address of the client on SSL server with the following code,

        int sock;
        sock = SSL_get_fd(s); // s is a type of SSL, sock returns right value
        struct sockaddr_in peer;
        socklen_t peer_len = sizeof(peer);
        int ret = getpeername(sock, (struct sockaddr *) &peer, &peer_len);

Here ret is 0, but peer address is

(gdb) print peer
$16 = {sin_family = 10, sin_port = 37604, sin_addr = {s_addr = 0}, sin_zero = "\000\000\000\000\000\000\000"}

Look the sin_family value is 10, that is AF_INET6, and s_addr is 0. However the client makes connection to server on IPv4.

apps/openssl s_server and s_client are used as server and client.

This is very weird, any ideas?

Many thanks,

/Kaiduan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions