Skip to content

Commit

Permalink
Merge branch 'x-forwarded-for-lws' of https://github.com/hardillb/mos…
Browse files Browse the repository at this point in the history
…quitto into hardillb-x-forwarded-for-lws
  • Loading branch information
ralight committed Aug 16, 2022
2 parents 9d9469c + 0eec37a commit 4a65705
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/websockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ static int callback_mqtt(
uint8_t *buf;
int rc;
uint8_t byte;
char ip_addr_buff[1024];

switch (reason) {
case LWS_CALLBACK_ESTABLISHED:
Expand All @@ -157,7 +158,12 @@ static int callback_mqtt(
}else{
return -1;
}
easy_address(lws_get_socket_fd(wsi), mosq);

if (lws_hdr_copy(wsi, ip_addr_buff, sizeof(ip_addr_buff), WSI_TOKEN_X_FORWARDED_FOR) > 0) {
mosq->address = mosquitto__strdup(ip_addr_buff);
} else {
easy_address(lws_get_socket_fd(wsi), mosq);
}
if(!mosq->address){
/* getpeername and inet_ntop failed and not a bridge */
mosquitto__free(mosq);
Expand Down

0 comments on commit 4a65705

Please sign in to comment.