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.
OpenPGP_0x460A317C3326D2AE.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature
