Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

get IP address of client socket #232

Closed
kaiduanx opened this issue Aug 15, 2020 · 1 comment
Closed

get IP address of client socket #232

kaiduanx opened this issue Aug 15, 2020 · 1 comment

Comments

@kaiduanx
Copy link

kaiduanx commented Aug 15, 2020

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

@dstebila
Copy link
Member

Nope, not something we have experience with. Maybe check some generic Unix networking programming guides.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants