Commit 58c8344c authored by captainwong's avatar captainwong

fix vs2017 warnings

parent 6225f0bb
...@@ -33,62 +33,69 @@ ...@@ -33,62 +33,69 @@
class icmp_header class icmp_header
{ {
public: public:
enum { echo_reply = 0, destination_unreachable = 3, source_quench = 4, enum {
redirect = 5, echo_request = 8, time_exceeded = 11, parameter_problem = 12, echo_reply = 0, destination_unreachable = 3, source_quench = 4,
timestamp_request = 13, timestamp_reply = 14, info_request = 15, redirect = 5, echo_request = 8, time_exceeded = 11, parameter_problem = 12,
info_reply = 16, address_request = 17, address_reply = 18 }; timestamp_request = 13, timestamp_reply = 14, info_request = 15,
info_reply = 16, address_request = 17, address_reply = 18
icmp_header() { std::fill(rep_, rep_ + sizeof(rep_), 0); } };
unsigned char type() const { return rep_[0]; } icmp_header() { memset(rep_, 0, sizeof(rep_)); }
unsigned char code() const { return rep_[1]; }
unsigned short checksum() const { return decode(2, 3); } unsigned char type() const { return rep_[0]; }
unsigned short identifier() const { return decode(4, 5); } unsigned char code() const { return rep_[1]; }
unsigned short sequence_number() const { return decode(6, 7); } unsigned short checksum() const { return decode(2, 3); }
unsigned short identifier() const { return decode(4, 5); }
void type(unsigned char n) { rep_[0] = n; } unsigned short sequence_number() const { return decode(6, 7); }
void code(unsigned char n) { rep_[1] = n; }
void checksum(unsigned short n) { encode(2, 3, n); } void type(unsigned char n) { rep_[0] = n; }
void identifier(unsigned short n) { encode(4, 5, n); } void code(unsigned char n) { rep_[1] = n; }
void sequence_number(unsigned short n) { encode(6, 7, n); } void checksum(unsigned short n) { encode(2, 3, n); }
void identifier(unsigned short n) { encode(4, 5, n); }
friend std::istream& operator>>(std::istream& is, icmp_header& header) void sequence_number(unsigned short n) { encode(6, 7, n); }
{ return is.read(reinterpret_cast<char*>(header.rep_), 8); }
friend std::istream& operator>>(std::istream& is, icmp_header& header)
friend std::ostream& operator<<(std::ostream& os, const icmp_header& header) {
{ return os.write(reinterpret_cast<const char*>(header.rep_), 8); } return is.read(reinterpret_cast<char*>(header.rep_), 8);
}
friend std::ostream& operator<<(std::ostream& os, const icmp_header& header)
{
return os.write(reinterpret_cast<const char*>(header.rep_), 8);
}
private: private:
unsigned short decode(int a, int b) const unsigned short decode(int a, int b) const
{ return ((rep_[a] << 8) + rep_[b]) & 0xFFFF; } {
return ((rep_[a] << 8) + rep_[b]) & 0xFFFF;
void encode(int a, int b, unsigned short n) }
{
rep_[a] = static_cast<unsigned char>(n >> 8); void encode(int a, int b, unsigned short n)
rep_[b] = static_cast<unsigned char>(n & 0xFF); {
} rep_[a] = static_cast<unsigned char>(n >> 8);
rep_[b] = static_cast<unsigned char>(n & 0xFF);
unsigned char rep_[8]; }
unsigned char rep_[8];
}; };
template <typename Iterator> template <typename Iterator>
void compute_checksum(icmp_header& header, void compute_checksum(icmp_header& header,
Iterator body_begin, Iterator body_end) Iterator body_begin, Iterator body_end)
{ {
unsigned int sum = (header.type() << 8) + header.code() unsigned int sum = (header.type() << 8) + header.code()
+ header.identifier() + header.sequence_number(); + header.identifier() + header.sequence_number();
Iterator body_iter = body_begin; Iterator body_iter = body_begin;
while (body_iter != body_end) while (body_iter != body_end) {
{ sum += (static_cast<unsigned char>(*body_iter++) << 8);
sum += (static_cast<unsigned char>(*body_iter++) << 8); if (body_iter != body_end)
if (body_iter != body_end) sum += static_cast<unsigned char>(*body_iter++);
sum += static_cast<unsigned char>(*body_iter++); }
}
sum = (sum >> 16) + (sum & 0xFFFF);
sum = (sum >> 16) + (sum & 0xFFFF); sum += (sum >> 16);
sum += (sum >> 16); header.checksum(static_cast<unsigned short>(~sum));
header.checksum(static_cast<unsigned short>(~sum));
} }
#endif // ICMP_HEADER_HPP #endif // ICMP_HEADER_HPP
\ No newline at end of file
...@@ -51,52 +51,54 @@ ...@@ -51,52 +51,54 @@
class ipv4_header class ipv4_header
{ {
public: public:
ipv4_header() { std::fill(rep_, rep_ + sizeof(rep_), 0); } ipv4_header() { memset(rep_, 0, sizeof(rep_)); }
unsigned char version() const { return (rep_[0] >> 4) & 0xF; } unsigned char version() const { return (rep_[0] >> 4) & 0xF; }
unsigned short header_length() const { return ((rep_[0] & 0xF) * 4) & 0xFFFF; } unsigned short header_length() const { return ((rep_[0] & 0xF) * 4) & 0xFFFF; }
unsigned char type_of_service() const { return rep_[1]; } unsigned char type_of_service() const { return rep_[1]; }
unsigned short total_length() const { return decode(2, 3); } unsigned short total_length() const { return decode(2, 3); }
unsigned short identification() const { return decode(4, 5); } unsigned short identification() const { return decode(4, 5); }
bool dont_fragment() const { return (rep_[6] & 0x40) != 0; } bool dont_fragment() const { return (rep_[6] & 0x40) != 0; }
bool more_fragments() const { return (rep_[6] & 0x20) != 0; } bool more_fragments() const { return (rep_[6] & 0x20) != 0; }
unsigned short fragment_offset() const { return decode(6, 7) & 0x1FFF; } unsigned short fragment_offset() const { return decode(6, 7) & 0x1FFF; }
unsigned int time_to_live() const { return rep_[8]; } unsigned int time_to_live() const { return rep_[8]; }
unsigned char protocol() const { return rep_[9]; } unsigned char protocol() const { return rep_[9]; }
unsigned short header_checksum() const { return decode(10, 11); } unsigned short header_checksum() const { return decode(10, 11); }
boost::asio::ip::address_v4 source_address() const boost::asio::ip::address_v4 source_address() const
{ {
boost::asio::ip::address_v4::bytes_type bytes boost::asio::ip::address_v4::bytes_type bytes
= { { rep_[12], rep_[13], rep_[14], rep_[15] } }; = { { rep_[12], rep_[13], rep_[14], rep_[15] } };
return boost::asio::ip::address_v4(bytes); return boost::asio::ip::address_v4(bytes);
} }
boost::asio::ip::address_v4 destination_address() const boost::asio::ip::address_v4 destination_address() const
{ {
boost::asio::ip::address_v4::bytes_type bytes boost::asio::ip::address_v4::bytes_type bytes
= { { rep_[16], rep_[17], rep_[18], rep_[19] } }; = { { rep_[16], rep_[17], rep_[18], rep_[19] } };
return boost::asio::ip::address_v4(bytes); return boost::asio::ip::address_v4(bytes);
} }
friend std::istream& operator>>(std::istream& is, ipv4_header& header) friend std::istream& operator>>(std::istream& is, ipv4_header& header)
{ {
is.read(reinterpret_cast<char*>(header.rep_), 20); is.read(reinterpret_cast<char*>(header.rep_), 20);
if (header.version() != 4) if (header.version() != 4)
is.setstate(std::ios::failbit); is.setstate(std::ios::failbit);
std::streamsize options_length = header.header_length() - 20; std::streamsize options_length = header.header_length() - 20;
if (options_length < 0 || options_length > 40) if (options_length < 0 || options_length > 40)
is.setstate(std::ios::failbit); is.setstate(std::ios::failbit);
else else
is.read(reinterpret_cast<char*>(header.rep_) + 20, options_length); is.read(reinterpret_cast<char*>(header.rep_) + 20, options_length);
return is; return is;
} }
private: private:
unsigned short decode(int a, int b) const unsigned short decode(int a, int b) const
{ return ((rep_[a] << 8) + rep_[b]) & 0xFFFF; } {
return ((rep_[a] << 8) + rep_[b]) & 0xFFFF;
}
unsigned char rep_[60]; unsigned char rep_[60];
}; };
#endif // IPV4_HEADER_HPP #endif // IPV4_HEADER_HPP
\ No newline at end of file
...@@ -253,7 +253,7 @@ public: ...@@ -253,7 +253,7 @@ public:
num.ReleaseBuffer(); num.ReleaseBuffer();
num.Format(_T("%03d"), nums); num.Format(_T("%03d"), nums);
tittle += num; tittle += num;
newFileName.Format(_T("%s%s"), tittle, ext); newFileName.Format(_T("%s%s"), (LPCWSTR)tittle, (LPCWSTR)ext);
LPCTSTR szOldName = fileName.GetBuffer(fileName.GetLength()); LPCTSTR szOldName = fileName.GetBuffer(fileName.GetLength());
fileName.ReleaseBuffer(); fileName.ReleaseBuffer();
LPCTSTR szNewName = newFileName.GetBuffer(newFileName.GetLength()); LPCTSTR szNewName = newFileName.GetBuffer(newFileName.GetLength());
...@@ -281,7 +281,7 @@ public: ...@@ -281,7 +281,7 @@ public:
filepath = find.GetFilePath(); filepath = find.GetFilePath();
if(DeleteFile(filepath.GetBuffer(filepath.GetLength()))){ if(DeleteFile(filepath.GetBuffer(filepath.GetLength()))){
CString trace;trace.Format(_T("CFileOper::DeleteFilesInFolder delete file %s \n"), CString trace;trace.Format(_T("CFileOper::DeleteFilesInFolder delete file %s \n"),
find.GetFilePath()); (LPCWSTR)find.GetFilePath());
TRACE(trace); TRACE(trace);
bfoundone = TRUE; bfoundone = TRUE;
dwDeletedFileNums++; dwDeletedFileNums++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment