mirror of
https://github.com/norohind/hans.git
synced 2025-04-17 23:12:20 +03:00
added Utility::rand()
This commit is contained in:
parent
735b71804d
commit
08e3d4fae3
2
Makefile
2
Makefile
@ -55,7 +55,7 @@ client.o: client.cpp client.h server.h exception.h config.h worker.h auth.h time
|
|||||||
server.o: server.cpp server.h client.h utility.h config.h worker.h auth.h time.h echo.h tun.h tun_dev.h
|
server.o: server.cpp server.h client.h utility.h config.h worker.h auth.h time.h echo.h tun.h tun_dev.h
|
||||||
g++ -c server.cpp $(CFLAGS)
|
g++ -c server.cpp $(CFLAGS)
|
||||||
|
|
||||||
auth.o: auth.cpp auth.h sha1.h
|
auth.o: auth.cpp auth.h sha1.h utility.h
|
||||||
g++ -c auth.cpp $(CFLAGS)
|
g++ -c auth.cpp $(CFLAGS)
|
||||||
|
|
||||||
worker.o: worker.cpp worker.h tun.h exception.h time.h echo.h tun_dev.h
|
worker.o: worker.cpp worker.h tun.h exception.h time.h echo.h tun_dev.h
|
||||||
|
12
auth.cpp
12
auth.cpp
@ -19,21 +19,13 @@
|
|||||||
|
|
||||||
#include "auth.h"
|
#include "auth.h"
|
||||||
#include "sha1.h"
|
#include "sha1.h"
|
||||||
|
#include "utility.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
bool Auth::randInitialized = false;
|
|
||||||
|
|
||||||
Auth::Auth(const char *passphrase)
|
Auth::Auth(const char *passphrase)
|
||||||
{
|
{
|
||||||
this->passphrase = passphrase;
|
this->passphrase = passphrase;
|
||||||
|
|
||||||
if (!randInitialized)
|
|
||||||
{
|
|
||||||
srand(time(NULL));
|
|
||||||
randInitialized = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Auth::Response Auth::getResponse(const Challenge &challenge) const
|
Auth::Response Auth::getResponse(const Challenge &challenge) const
|
||||||
@ -59,7 +51,7 @@ Auth::Challenge Auth::generateChallenge(int length) const
|
|||||||
challenge.resize(length);
|
challenge.resize(length);
|
||||||
|
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
challenge[i] = rand();
|
challenge[i] = Utility::rand();
|
||||||
|
|
||||||
return challenge;
|
return challenge;
|
||||||
}
|
}
|
||||||
|
2
auth.h
2
auth.h
@ -43,8 +43,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
std::string passphrase;
|
std::string passphrase;
|
||||||
std::string challenge;
|
std::string challenge;
|
||||||
|
|
||||||
static bool randInitialized;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
13
utility.cpp
13
utility.cpp
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
string Utility::formatIp(uint32_t ip)
|
string Utility::formatIp(uint32_t ip)
|
||||||
@ -27,3 +29,14 @@ string Utility::formatIp(uint32_t ip)
|
|||||||
sprintf(buffer, "%d.%d.%d.%d", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
|
sprintf(buffer, "%d.%d.%d.%d", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Utility::rand()
|
||||||
|
{
|
||||||
|
static bool init = false;
|
||||||
|
if (!init)
|
||||||
|
{
|
||||||
|
init = true;
|
||||||
|
srand(time(NULL));
|
||||||
|
}
|
||||||
|
return ::rand();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user