Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get client IP address? #3086

Open
joe-average-user opened this issue Jul 25, 2024 · 1 comment
Open

How to get client IP address? #3086

joe-average-user opened this issue Jul 25, 2024 · 1 comment

Comments

@joe-average-user
Copy link

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!

@Miguel-AgRz
Copy link

Miguel-AgRz commented Aug 22, 2024

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;
}

}

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

No branches or pull requests

2 participants