libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Can't log client address


From: Evgeny Grin
Subject: Re: [libmicrohttpd] Can't log client address
Date: Thu, 25 Aug 2022 14:03:29 +0300
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0

Hi Klemens,

Which MHD example has direct print of the "sa_data"?

'struct sockaddr' has the only accessible member, it is sa_family. You should check sa_family value to detect which protocol is used. Then, if it is IPv4, you must cast the pointer to 'struct sockaddr_in*' and operate members of sockaddr_in ('_in' is short for 'internet').
The member 'sin_addr' of 'sockaddr_in' gives you the address.

Try search the web for 'struct sockaddr' and 'struct sockaddr_in'. It is very basic.

--
Best Wishes,
Evgeny


On 24.08.2022 18:26, klemens wrote:

try to log an incoming clients address, as suggested in
example 2 of the tutorial:

get_client_adr (void *cls, const struct sockaddr *addr, socklen_t addrlen)
{
     printf ("ADR>>%14.14x<<\n", addr->sa_data);
     return MHD_YES;
}

main (int argc, char **argv)
{
     struct MHD_Daemon *daemon;

     daemon = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION,
                                PORT,
                                &get_client_adr,
                                NULL,
                                &answer_to_connection,
                                NULL,
                                MHD_OPTION_END);
     if (NULL == daemon)
       return 1;

     (void) getchar ();
     //answer_to_connection

     MHD_stop_daemon (daemon);
     return 0;
}


The program compiles on Debian6. But when I connect from the same
server [192.168.0.95] the outcome is ADR>>000000ab00ac82<<, which
does not make sense to me. Could anyone please help, what I'm
doing wrong here. Thanks in advance.

Klemens.

Attachment: OpenPGP_0x460A317C3326D2AE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]