Skip to content
Snippets Groups Projects
Commit a6cb6cc4 authored by echicken's avatar echicken :chicken:
Browse files

Added inet_pton function borrowed from the internet.

Added incomplete send of haproxy protocol header. Need to sort
out lookup of target (BBS) IP address.
parent fa3e7132
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -93,7 +93,20 @@ try {
var ServerData = [];
if (UsingHAProxy()) {
// Do HAProxy stuff here
[0x0D, 0x0A, 0x0D, 0x0A, 0x00, 0x0D, 0x0A, 0x51, 0x55, 0x49, 0x54, 0x0A, 0x21].forEach(function (e) {
FServerSocket.sendBin(e, 1);
});
if (client.socket.family === PF_INET) {
FServerSocket.sendBin(0x11, 1);
FServerSocket.sendBin(12, 2);
} else if (client.socket.family === PF_INET6) {
FServerSocket.sendBin(0x21, 1);
FServerSocket.sendBin(36, 2);
}
FServerSocket.sendBin(inet_pton(client.ip_address), 4);
FServerSocket.sendBin(inet_pton(TARGET_IP_ADDRESS_GOES_HERE), 4);
FServerSocket.sendBin(client.port, 2);
FServerSocket.sendBin(TargetPort, 2);
}
// Loop while we're still connected on both ends
......@@ -599,3 +612,48 @@ function ShakeHandsVersion7() {
return false;
}
}
function inet_pton (a) {
// http://kevin.vanzonneveld.net
// + original by: Theriault
// * example 1: inet_pton('::');
// * returns 1: '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' (binary)
// * example 2: inet_pton('127.0.0.1');
// * returns 2: '\x7F\x00\x00\x01' (binary)
var r, m, x, i, j, f = String.fromCharCode;
m = a.match(/^(?:\d{1,3}(?:\.|$)){4}/); // IPv4
if (m) {
m = m[0].split('.');
m = f(m[0]) + f(m[1]) + f(m[2]) + f(m[3]);
// Return if 4 bytes, otherwise false.
return m.length === 4 ? m : false;
}
r = /^((?:[\da-f]{1,4}(?::|)){0,8})(::)?((?:[\da-f]{1,4}(?::|)){0,8})$/;
m = a.match(r); // IPv6
if (m) {
// Translate each hexadecimal value.
for (j = 1; j < 4; j++) {
// Indice 2 is :: and if no length, continue.
if (j === 2 || m[j].length === 0) {
continue;
}
m[j] = m[j].split(':');
for (i = 0; i < m[j].length; i++) {
m[j][i] = parseInt(m[j][i], 16);
// Would be NaN if it was blank, return false.
if (isNaN(m[j][i])) {
return false; // Invalid IP.
}
m[j][i] = f(m[j][i] >> 8) + f(m[j][i] & 0xFF);
}
m[j] = m[j].join('');
}
x = m[1].length + m[3].length;
if (x === 16) {
return m[1] + m[3];
} else if (x < 16 && m[2].length > 0) {
return m[1] + (new Array(16 - x + 1)).join('\x00') + m[3];
}
}
return false; // Invalid IP.
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment