Fixed compiler warnings

This commit is contained in:
Brychan Dempsey 2021-01-07 17:26:00 +13:00
parent cf96c7dae7
commit 6716f7bb6e
3 changed files with 10 additions and 9 deletions

View File

@ -50,14 +50,14 @@ std::vector<unsigned char> DHCP::Generate_DHCP_Option(unsigned char option, unsi
} }
else if (option == 6) { else if (option == 6) {
if (DNSServers.size() > 0) { if (DNSServers.size() > 0) {
for (size_t i = 0; i < DNSServers.size(); i++) for (unsigned int i = 0; i < DNSServers.size(); i++)
{ {
if (DNSServers[i] != 0) if (DNSServers[i] != 0)
{ {
s.push_back((size_t)(DNSServers[i] >> 24)); s.push_back((unsigned char)(DNSServers[i] >> 24));
s.push_back((size_t)(DNSServers[i] >> 16)); s.push_back((unsigned char)(DNSServers[i] >> 16));
s.push_back((size_t)(DNSServers[i] >> 8)); s.push_back((unsigned char)(DNSServers[i] >> 8));
s.push_back((size_t)DNSServers[i]); s.push_back((unsigned char)DNSServers[i]);
length += 4; length += 4;
} }
} }
@ -91,7 +91,7 @@ std::vector<unsigned char> DHCP::Generate_DHCP_Option(unsigned char option, unsi
} }
unsigned char DHCP::FindPosByMac(Net::MACAddress MAC, DHCP::DHCPEntry* entries, unsigned char entries_size) { unsigned char DHCP::FindPosByMac(Net::MACAddress MAC, DHCP::DHCPEntry* entries, unsigned char entries_size) {
for (size_t i = 0; i < entries_size; i++) for (unsigned char i = 0; i < entries_size; i++)
{ {
if (entries[i].MAC.equals(MAC)) { if (entries[i].MAC.equals(MAC)) {
return i; return i;
@ -104,7 +104,7 @@ unsigned char DHCP::FindPosByMac(Net::MACAddress MAC, DHCP::DHCPEntry* entries,
std::vector<std::vector<unsigned char>> DHCP::ProcessDHCP(unsigned char* rxBuffer, unsigned long bufferLength) { std::vector<std::vector<unsigned char>> DHCP::ProcessDHCP(unsigned char* rxBuffer, unsigned long bufferLength) {
unsigned char txBuffer[Net::TYPICAL_MTU] = {}; // ensure we have base zeros unsigned char txBuffer[Net::TYPICAL_MTU] = {}; // ensure we have base zeros
u_long destAddress = ULLONG_MAX; u_long destAddress = 0xFFFFFFFF;
if (rxBuffer[236] == DHCP::MAGIC_COOKIE[0] && rxBuffer[237] == DHCP::MAGIC_COOKIE[1] && rxBuffer[238] == DHCP::MAGIC_COOKIE[2] && rxBuffer[239] == DHCP::MAGIC_COOKIE[3]) { if (rxBuffer[236] == DHCP::MAGIC_COOKIE[0] && rxBuffer[237] == DHCP::MAGIC_COOKIE[1] && rxBuffer[238] == DHCP::MAGIC_COOKIE[2] && rxBuffer[239] == DHCP::MAGIC_COOKIE[3]) {
unsigned int position = 240; unsigned int position = 240;
// Find all options // Find all options
@ -303,6 +303,7 @@ std::vector<std::vector<unsigned char>> DHCP::ProcessDHCP(unsigned char* rxBuffe
return std::vector<std::vector<unsigned char>> {std::vector<unsigned char> {(unsigned char)(destAddress >> 24), (unsigned char)(destAddress >> 16), (unsigned char)(destAddress >> 8), (unsigned char)destAddress}, returnBuffer}; return std::vector<std::vector<unsigned char>> {std::vector<unsigned char> {(unsigned char)(destAddress >> 24), (unsigned char)(destAddress >> 16), (unsigned char)(destAddress >> 8), (unsigned char)destAddress}, returnBuffer};
} }
return std::vector<std::vector<unsigned char>>(0);
} }
DHCP::DHCP(unsigned char* deviceAddress, unsigned char* subnetMask, unsigned char maxLeases, unsigned char leaseStart, unsigned int leaseTime, unsigned int* dnsServers, unsigned char dnsServerCount) { DHCP::DHCP(unsigned char* deviceAddress, unsigned char* subnetMask, unsigned char maxLeases, unsigned char leaseStart, unsigned int leaseTime, unsigned int* dnsServers, unsigned char dnsServerCount) {
localAddress1 = deviceAddress[0]; localAddress1 = deviceAddress[0];

View File

@ -80,7 +80,7 @@ int Net::UdpClient::Send(char* Datagram, short DatagramSize, IPEndPoint ep) {
} }
int Net::UdpClient::Send(std::vector<unsigned char> Datagram, IPEndPoint ep) { int Net::UdpClient::Send(std::vector<unsigned char> Datagram, IPEndPoint ep) {
return Send((char*)Datagram.data(), Datagram.size(), ep); return Send((char*)Datagram.data(), (short)Datagram.size(), ep);
} }
int Net::UdpClient::Send(std::vector<unsigned char> Datagram, std::vector<unsigned char> DestinationIP, int DestPort) { int Net::UdpClient::Send(std::vector<unsigned char> Datagram, std::vector<unsigned char> DestinationIP, int DestPort) {

View File

@ -23,7 +23,7 @@ int main()
while (true) { while (true) {
waitingBytes = udpClient.Available(); waitingBytes = udpClient.Available();
if (waitingBytes > 240) { // DHCP requires *at least* 240 bytes, the packet is malformed or incorrect if it is less if (waitingBytes > 240) { // DHCP requires *at least* 240 bytes, the packet is malformed or incorrect if it is less
std::vector<std::vector<unsigned char>> result = dhcp.ProcessDHCP(udpClient.Recieve(&remote, waitingBytes), waitingBytes); std::vector<std::vector<unsigned char>> result = dhcp.ProcessDHCP(udpClient.Recieve(&remote, (unsigned short)waitingBytes), waitingBytes);
if (result.size() == 2) { if (result.size() == 2) {
if (remote.Address.Equals(Net::IPAddress::Empty())) { if (remote.Address.Equals(Net::IPAddress::Empty())) {
udpClient.Send(result[1], result[0], 68); udpClient.Send(result[1], result[0], 68);