mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

How to get client IP address?

Open joe-average-user opened this issue 1 year ago • 1 comments

Hello,

I want to create an auth module for mosquitto that uses amongst other the client IP address. Is mosquitto->address the client IP (in some form (as string))?

Thank you!

joe-average-user avatar Jul 25 '24 14:07 joe-average-user

mosquitto_client_address func

static int basic_auth_callback(int event, void *event_data, void *userdata) { struct mosquitto_evt_basic_auth *ed = event_data; const char *ip_address;

UNUSED(event);
UNUSED(userdata);

ip_address = mosquitto_client_address(ed->client);
if(!strcmp(ip_address, "127.0.0.1")){
	/* Only allow connections from localhost */
	return MOSQ_ERR_SUCCESS;
}else{
	return MOSQ_ERR_AUTH;
}

}

Miguel-AgRz avatar Aug 22 '24 05:08 Miguel-AgRz

I guess this answered the question. Can we close?

Daedaluz avatar Oct 06 '24 14:10 Daedaluz

Thank you for giving me the chance on a sunday to reply ;-)

joe-average-user avatar Oct 07 '24 00:10 joe-average-user

Sorry, I was being a bit quick at trying to tidy up,

ralight avatar Oct 07 '24 13:10 ralight

Was no offense. I just did not request close myself because was not able to test the suggestion so far. busy busy ...

Thank you for your work!

joe-average-user avatar Oct 07 '24 13:10 joe-average-user