2014-05-08 16:44:01 +02:00
/*@!Encoding:1252*/
variables
{
const long WSA_IO_PENDING = 997;
const long WSAEWOULDBLOCK = 10035;
const dword INVALID_IP = 0xffffffff;
long gIpLastErr = 0;
char gIpLastErrStr[512] = "";
enum SocketState { NULL, OK, ERROR, CLOSED };
2014-05-09 15:49:19 +02:00
enum SocketState gSocketState = NULL;
2014-05-08 16:44:01 +02:00
2014-05-09 15:49:19 +02:00
dword gRemoteIP = INVALID_IP;
word gRemotePort = 0;
2014-05-08 16:44:01 +02:00
}
dword SetupIp(char Local_IP[])
{
int adapterIndex;
const int size = 512;
char text[size] = "";
2014-05-12 10:46:53 +02:00
dword addresses[8];
2014-05-08 16:44:01 +02:00
dword address;
word adapterCount;
word i;
2014-05-12 10:46:53 +02:00
long error;
2014-05-08 16:44:01 +02:00
adapterCount = IpGetAdapterCount();
adapterIndex = @sysvar::TCPIP::AdapterIndex;
switch (adapterCount)
{
case 0:
2014-05-09 15:39:44 +02:00
writeLineEx(0, 3, "<%NODE_NAME%> Error: There is no network interface available!");
2014-05-08 16:44:01 +02:00
stop();
return INVALID_IP;
break;
case 1:
2014-05-09 15:39:44 +02:00
writeLineEx(0, 1, "<%NODE_NAME%> Info: There is 1 network interface available!");
2014-05-08 16:44:01 +02:00
if (adapterIndex != 1)
{
2014-05-09 15:39:44 +02:00
writeLineEx(0, 3, "<%NODE_NAME%> Error: You have not selected the first adapter!");
2014-05-08 16:44:01 +02:00
stop();
return INVALID_IP;
}
break;
default:
2014-05-09 15:39:44 +02:00
writeLineEx(0, 1, "<%NODE_NAME%> Info: There are %d network interfaces available!", adapterCount);
2014-05-08 16:44:01 +02:00
// // // // TEST \\ \\ \\ \\
for (i = 1; i <= adapterCount; i++)
{
IpGetAdapterDescription(i, text, size);
2014-05-09 15:39:44 +02:00
writeLineEx(0, 1, "<%NODE_NAME%> Info: Interface %d: %s", i, text);
2014-05-08 16:44:01 +02:00
}
break;
}
2014-05-12 10:46:53 +02:00
error = IpGetAdapterAddress(adapterIndex, addresses, elCount(addresses));
if (error == 8)
2014-05-08 16:44:01 +02:00
{
2014-05-12 10:46:53 +02:00
writeLineEx(0, 3, "<%NODE_NAME%> Error 8: Could not retrieve IP address from interface #%d: The address array was insufficient", adapterIndex);
stop();
return INVALID_IP;
}
else if (error == 87)
{
writeLineEx(0, 3, "<%NODE_NAME%> Error 87: Could not retrieve IP address from interface #%d: The specified interface index was invalid", adapterIndex);
2014-05-08 16:44:01 +02:00
stop();
return INVALID_IP;
}
address = addresses[0]; // the interface used
if (address == INVALID_IP)
{
2014-05-09 15:39:44 +02:00
writeLineEx(0, 3, "<%NODE_NAME%> Error: IP address to be used is invalid!");
2014-05-08 16:44:01 +02:00
stop();
return INVALID_IP;
}
IpGetAdapterDescription(adapterIndex, text, size);
2014-05-09 15:39:44 +02:00
writeLineEx(0, 1, "<%NODE_NAME%> Interface: %s", text);
writeLineEx(0, 1, "<%NODE_NAME%> Wrong interface? Change sysvar::TCPIP::AdapterIndex");
2014-05-08 16:44:01 +02:00
IpGetAdapterAddressAsString(adapterIndex, text, size);
2014-05-09 15:39:44 +02:00
writeLineEx(0, 1, "<%NODE_NAME%> Ip address: %s", text);
2014-05-08 16:44:01 +02:00
strncpy(Local_IP, text, 16);
IpGetAdapterMaskAsString(adapterIndex, text, size);
2014-05-09 15:39:44 +02:00
writeLineEx(0, 1, "<%NODE_NAME%> Subnet mask: %s", text);
2014-05-08 16:44:01 +02:00
IpGetAdapterGatewayAsString(adapterIndex, text, size);
2014-05-09 15:39:44 +02:00
writeLineEx(0, 1, "<%NODE_NAME%> Gateway address: %s", text);
2014-05-08 16:44:01 +02:00
return address;
}