23 #include "runtime.hpp"
39 enum { MAX_MSG = 81 };
41 Log::Log(
const char* str)
43 log_ = fopen(str,
"w");
44 Trace(
"********** Logger Attached **********");
50 Trace(
"********** Logger Detached **********");
56 void Log::Trace(
const char* str)
60 time_t clicks = time(0);
64 strncpy(timeStr, ctime(&clicks),
sizeof(timeStr));
65 unsigned int len = strlen(timeStr);
70 strncpy(msg, timeStr,
sizeof(timeStr));
72 strncat(msg, str, MAX_MSG -
sizeof(timeStr) - 2);
73 strncat(msg,
"\n", 1);
80 #if defined(_WIN32) || defined(__MACH__) || defined(__hpux__)
81 typedef int socklen_t;
86 void Log::ShowTCP(socket_t fd,
bool ended)
89 socklen_t len =
sizeof(peeraddr);
90 if (getpeername(fd, (sockaddr*)&peeraddr, &len) != 0)
93 const char* p =
reinterpret_cast<const char*
>(&peeraddr.sin_addr);
98 strncpy(msg,
"yaSSL conn DONE w/ peer ", 26);
100 strncpy(msg,
"yaSSL conn BEGUN w/ peer ", 26);
101 for (
int i = 0;
i < 4; ++
i) {
102 sprintf(number,
"%u", static_cast<unsigned short>(p[
i]));
103 strncat(msg, number, 8);
105 strncat(msg,
".", 1);
107 strncat(msg,
" port ", 8);
108 sprintf(number,
"%d", htons(peeraddr.sin_port));
109 strncat(msg, number, 8);
111 msg[MAX_MSG - 1] = 0;
117 void Log::ShowData(uint bytes,
bool sent)
123 strncpy(msg,
"Sent ", 10);
125 strncpy(msg,
"Received ", 10);
126 sprintf(number,
"%u", bytes);
127 strncat(msg, number, 8);
128 strncat(msg,
" bytes of application data", 27);
130 msg[MAX_MSG - 1] = 0;
135 #else // no YASSL_LOG
138 Log::Log(
const char*) {}
140 void Log::Trace(
const char*) {}
141 void Log::ShowTCP(socket_t,
bool) {}
142 void Log::ShowData(uint,
bool) {}