mirror of
https://github.com/norohind/hans.git
synced 2025-04-14 13:47:15 +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
|
||||
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)
|
||||
|
||||
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 "sha1.h"
|
||||
#include "utility.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
bool Auth::randInitialized = false;
|
||||
|
||||
Auth::Auth(const char *passphrase)
|
||||
{
|
||||
this->passphrase = passphrase;
|
||||
|
||||
if (!randInitialized)
|
||||
{
|
||||
srand(time(NULL));
|
||||
randInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
Auth::Response Auth::getResponse(const Challenge &challenge) const
|
||||
@ -59,7 +51,7 @@ Auth::Challenge Auth::generateChallenge(int length) const
|
||||
challenge.resize(length);
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
challenge[i] = rand();
|
||||
challenge[i] = Utility::rand();
|
||||
|
||||
return challenge;
|
||||
}
|
||||
|
2
auth.h
2
auth.h
@ -43,8 +43,6 @@ public:
|
||||
protected:
|
||||
std::string passphrase;
|
||||
std::string challenge;
|
||||
|
||||
static bool randInitialized;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
13
utility.cpp
13
utility.cpp
@ -19,6 +19,8 @@
|
||||
|
||||
#include "utility.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
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);
|
||||
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