Skip to content

Commit

Permalink
Improve "TFTP Server" Code
Browse files Browse the repository at this point in the history
  • Loading branch information
LipkeGu committed Feb 3, 2019
1 parent ff7300f commit 6f2c897
Show file tree
Hide file tree
Showing 20 changed files with 687 additions and 1,040 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,4 @@ BINL-Server.VC.db
*.opendb
*.db
*.com
*.diagsession
2 changes: 0 additions & 2 deletions BINL-Server/BINL-Server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
<ClInclude Include="src\Client.h" />
<ClInclude Include="src\Connection.h" />
<ClInclude Include="src\Defines.h" />
<ClInclude Include="src\FileSystem.h" />
<ClInclude Include="src\Functions.h" />
<ClInclude Include="src\Includes.h" />
<ClInclude Include="src\Main.h" />
Expand All @@ -155,7 +154,6 @@
<ItemGroup>
<ClCompile Include="src\Client.cpp" />
<ClCompile Include="src\Connection.cpp" />
<ClCompile Include="src\FileSystem.cpp" />
<ClCompile Include="src\Functions.cpp" />
<ClCompile Include="src\Main.cpp" />
<ClCompile Include="src\Packet.cpp" />
Expand Down
6 changes: 0 additions & 6 deletions BINL-Server/BINL-Server.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
<ClInclude Include="src\Defines.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\FileSystem.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\Functions.h">
<Filter>Headerdateien</Filter>
</ClInclude>
Expand All @@ -50,9 +47,6 @@
<ClCompile Include="src\Connection.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\FileSystem.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\Functions.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
Expand Down
273 changes: 13 additions & 260 deletions BINL-Server/src/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,282 +16,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define _CRT_SECURE_NO_WARNINGS
#include "Includes.h"

Client::Client(ServerType type, std::string* id, char* hwaddr)
Client::Client(ServerType* type, std::string id)
{
this->SetType(type);
this->id = id;
}

void Client::SetType(ServerType type)
{
this->type = type;
}

ServerType Client::GetType()
{
return this->type;
}

void Client::DHCP_CLIENT::SetDHCPMessageType(DHCPMsgTypes type)
{
this->msgtype = type;
}

DHCPMsgTypes Client::DHCP_CLIENT::GetDHCPMessageType()
{
return this->msgtype;
}

void Client::DHCP_CLIENT::WDS::SetReferralServer(uint32_t addr)
{
this->referralIP = addr;
}

uint32_t Client::DHCP_CLIENT::WDS::GetReferralServer()
{
return this->referralIP;
}

void Client::DHCP_CLIENT::WDS::SetRequestID(uint32_t id)
{
this->requestid = id;
}

uint32_t Client::DHCP_CLIENT::WDS::GetRequestID()
{
return this->requestid;
}

void Client::SetSocket(SOCKET* s)
{
this->s = s;
}

SOCKET* Client::GetSocket()
{
return this->s;
}

CLIENT_ARCH Client::DHCP_CLIENT::GetArchitecture()
{
return this->arch;
}

void Client::DHCP_CLIENT::SetArchitecture(CLIENT_ARCH arch)
{
this->arch = arch;
}

#ifdef WITH_TFTP
void Client::TFTP_CLIENT::SetTFTPState(TFTP_State state)
{
this->tftp_state = state;
}

TFTP_State Client::TFTP_CLIENT::GetTFTPState()
{
return this->tftp_state;
}
#endif

void Client::DHCP_CLIENT::SetBootfile(std::string file)
{
this->bootfile = file;
}

void Client::DHCP_CLIENT::WDS::SetWDSMessage(std::string message)
{
this->AdminMessage = message;
}

std::string Client::DHCP_CLIENT::WDS::GetWDSMessage()
{
return this->AdminMessage;
}

void Client::DHCP_CLIENT::WDS::SetNextAction(WDSNBP_OPTION_NEXTACTION action)
{
this->NextAction = action;
}

WDSNBP_OPTION_NEXTACTION Client::DHCP_CLIENT::WDS::GetNextAction()
{
return this->NextAction;
}

void Client::DHCP_CLIENT::WDS::SetRetryCount(uint16_t action)
{
this->RetryCount = action;
}

uint16_t Client::DHCP_CLIENT::WDS::GetRetryCount()
{
return this->RetryCount;
}

void Client::DHCP_CLIENT::WDS::SetPollInterval(uint16_t interval)
{
this->PollIntervall = interval;
}

uint16_t Client::DHCP_CLIENT::WDS::GetPollInterval()
{
return this->PollIntervall;
}

std::string Client::DHCP_CLIENT::GetBootfile(CLIENT_ARCH arch)
{
switch (arch)
switch (*type)
{
case INTEL_X86:
switch (this->WDS.GetNextAction())
{
case ABORT:
this->bootfile = "Boot\\x86\\abortpxe.com";
break;
default:
this->bootfile = "Boot\\x86\\pxeboot.n12";
// this->bcdfile = "Boot\\x86\\default.bcd";
break;
}
break;
case INTEL_X64:
switch (this->WDS.GetNextAction())
{
case ABORT:
this->bootfile = "Boot\\x64\\abortpxe.com";
// this->bcdfile = "";
break;
default:
this->bootfile = "Boot\\x64\\pxeboot.n12";
// this->bcdfile = "Boot\\x64\\default.bcd";
break;
}
case TYPE_DHCP:
case TYPE_BINL:
this->dhcp = new DHCP_CLIENT();
break;
case INTEL_EFI:
this->bootfile = "Boot\\efi\\bootmgfw.efi";
// this->bcdfile = "Boot\\efi\\default.bcd";
break;
default:
this->bootfile = DHCP_BOOTFILE;
// this->bcdfile = "";
case TYPE_TFTP:
this->tftp = new TFTP_CLIENT();
break;
}

return this->bootfile;
}

void Client::SetBCDfile(std::string file)
{
this->bcdfile = file;
}

std::string Client::GetBCDfile()
{
return this->bcdfile;
}

#ifdef WITH_TFTP
void Client::TFTP_CLIENT::SetBlock()
{
this->block++;
}

void Client::TFTP_CLIENT::SetBlock(uint16_t block)
{
this->block = block;
}

uint16_t Client::TFTP_CLIENT::GetWindowSize()
void Client::SetType(ServerType* type)
{
return this->windowsize;
}

void Client::TFTP_CLIENT::SetWindowSize(uint16_t window)
{
this->windowsize = window;
}

uint16_t Client::TFTP_CLIENT::GetBlockSize()
{
return this->blocksize;
}

void Client::TFTP_CLIENT::SetBlockSize(uint16_t blocksize)
{
this->blocksize = (blocksize < this->max_blocksize) ?
blocksize : this->max_blocksize;
}

uint16_t Client::TFTP_CLIENT::GetMSFTWindow()
{
return this->msftwindow;
}

void Client::TFTP_CLIENT::SetMSFTWindow(uint16_t window)
{
this->msftwindow = window;
}
#endif

uint16_t Client::TFTP_CLIENT::GetBlock()
{
return this->block;
}

bool Client::TFTP_CLIENT::GetACK(Packet* packet)
{
bool b = false;
#
if (packet->GetLength() > 4)
this->SetWindowSize(packet->GetBuffer()[4]);
#
char* x = new char[2];
x[0] = (this->GetBlock() & 0xFF00) >> 8;
x[1] = (this->GetBlock() & 0x00FF);

b = (memcmp(&packet->GetBuffer()[2], x, 2) == 0) ?
true : false;

delete x;

return b;
}

long Client::TFTP_CLIENT::GetBytesToRead()
{
return this->bytesToRead;
}

void Client::TFTP_CLIENT::SetBytesToRead(long bytes)
{
this->bytesToRead = bytes;
}

long Client::TFTP_CLIENT::GetBytesRead()
{
return this->bytesread;
this->type = type;
}

void Client::TFTP_CLIENT::SetBytesRead(long bytes)
ServerType* Client::GetType()
{
if (bytes == 0)
this->bytesread = bytes;
else
this->bytesread += bytes;
return this->type;
}

Client::~Client()
{
if (this->s)
close(*this->s);

if (this->file)
{
this->file->Close();
delete this->file;
}

delete this->Data;
delete id;
delete this->dhcp;
delete this->tftp;
}
Loading

0 comments on commit 6f2c897

Please sign in to comment.