summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/PracticalSocket.cpp6
-rw-r--r--src/anytun.cpp8
-rw-r--r--src/authAlgo.cpp4
-rw-r--r--src/bsd/tunDevice.cpp4
-rw-r--r--src/cipher.cpp20
-rw-r--r--src/datatypes.h2
-rw-r--r--src/keyDerivation.cpp20
-rw-r--r--src/linux/tunDevice.cpp14
8 files changed, 42 insertions, 36 deletions
diff --git a/src/PracticalSocket.cpp b/src/PracticalSocket.cpp
index 8565878..3ff286f 100644
--- a/src/PracticalSocket.cpp
+++ b/src/PracticalSocket.cpp
@@ -28,6 +28,8 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "datatypes.h"
+
// this is from: http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/practical/
// and this is their header:
/*
@@ -80,8 +82,8 @@ SocketException::SocketException(const string &message, bool inclSysMsg)
throw() : userMessage(message) {
if (inclSysMsg) {
userMessage.append(": ");
- char buf[NL_TEXTMAX];
- strerror_r(errno, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ strerror_r(errno, buf, STERROR_TEXT_MAX);
userMessage.append(buf);
}
}
diff --git a/src/anytun.cpp b/src/anytun.cpp
index 64da130..3d985d4 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -355,16 +355,16 @@ bool initLibGCrypt()
gcry_error_t err = gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
if( err ) {
- char buf[NL_TEXTMAX];
- std::cout << "initLibGCrypt: Failed to disable secure memory: " << gpg_strerror_r(err, buf, NL_TEXTMAX) << std::endl;
+ char buf[STERROR_TEXT_MAX];
+ std::cout << "initLibGCrypt: Failed to disable secure memory: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX) << std::endl;
return false;
}
// Tell Libgcrypt that initialization has completed.
err = gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
if( err ) {
- char buf[NL_TEXTMAX];
- std::cout << "initLibGCrypt: Failed to finish initialization: " << gpg_strerror_r(err, buf, NL_TEXTMAX) << std::endl;
+ char buf[STERROR_TEXT_MAX];
+ std::cout << "initLibGCrypt: Failed to finish initialization: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX) << std::endl;
return false;
}
diff --git a/src/authAlgo.cpp b/src/authAlgo.cpp
index 4657ddc..617c93b 100644
--- a/src/authAlgo.cpp
+++ b/src/authAlgo.cpp
@@ -74,8 +74,8 @@ void Sha1AuthAlgo::setKey(Buffer& key)
gcry_error_t err = gcry_md_setkey( ctx_, key.getBuf(), key.getLength() );
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "Sha1AuthAlgo::setKey: Failed to set cipher key: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "Sha1AuthAlgo::setKey: Failed to set cipher key: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
}
}
diff --git a/src/bsd/tunDevice.cpp b/src/bsd/tunDevice.cpp
index f8b6795..0fe27f5 100644
--- a/src/bsd/tunDevice.cpp
+++ b/src/bsd/tunDevice.cpp
@@ -90,8 +90,8 @@ TunDevice::TunDevice(const char* dev_name, const char* dev_type, const char* ifc
msg = "can't open device file (";
msg.append(device_file);
msg.append("): ");
- char buf[NL_TEXTMAX];
- strerror_r(errno, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ strerror_r(errno, buf, STERROR_TEXT_MAX);
msg.append(buf);
}
throw std::runtime_error(msg);
diff --git a/src/cipher.cpp b/src/cipher.cpp
index 6a572b9..593218f 100644
--- a/src/cipher.cpp
+++ b/src/cipher.cpp
@@ -79,8 +79,8 @@ AesIcmCipher::AesIcmCipher() : cipher_(NULL)
// TODO: hardcoded keysize
gcry_error_t err = gcry_cipher_open( &cipher_, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR, 0 );
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_CRIT) << "AesIcmCipher::AesIcmCipher: Failed to open cipher" << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_CRIT) << "AesIcmCipher::AesIcmCipher: Failed to open cipher" << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
}
}
@@ -98,8 +98,8 @@ void AesIcmCipher::setKey(Buffer& key)
gcry_error_t err = gcry_cipher_setkey( cipher_, key.getBuf(), key.getLength() );
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "AesIcmCipher::setKey: Failed to set cipher key: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "AesIcmCipher::setKey: Failed to set cipher key: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
}
}
@@ -129,8 +129,8 @@ void AesIcmCipher::calc(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t o
gcry_error_t err = gcry_cipher_reset( cipher_ );
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to reset cipher: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to reset cipher: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
return;
}
@@ -159,15 +159,15 @@ void AesIcmCipher::calc(u_int8_t* in, u_int32_t ilen, u_int8_t* out, u_int32_t o
err = gcry_cipher_setctr( cipher_, ctr_buf, written ); // TODO: hardcoded size
delete[] ctr_buf;
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to set cipher CTR: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to set cipher CTR: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
return;
}
err = gcry_cipher_encrypt( cipher_, out, olen, in, ilen );
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to generate cipher bitstream: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "AesIcmCipher: Failed to generate cipher bitstream: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
return;
}
}
diff --git a/src/datatypes.h b/src/datatypes.h
index 29ac8a7..441799a 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -60,4 +60,6 @@ typedef u_int16_t mux_t;
//#define AUTH_TAG_T_NTOH(a) ntohl(a)
//#define AUTH_TAG_T_HTON(a) htonl(a)
//
+#define STERROR_TEXT_MAX 100
+
#endif
diff --git a/src/keyDerivation.cpp b/src/keyDerivation.cpp
index d2baeac..eda2189 100644
--- a/src/keyDerivation.cpp
+++ b/src/keyDerivation.cpp
@@ -71,8 +71,8 @@ void AesIcmKeyDerivation::updateMasterKey()
gcry_error_t err = gcry_cipher_setkey( cipher_, master_key_.getBuf(), master_key_.getLength() );
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::updateMasterKey: Failed to set cipher key: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::updateMasterKey: Failed to set cipher key: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
}
}
@@ -85,8 +85,8 @@ void AesIcmKeyDerivation::init(Buffer key, Buffer salt)
// TODO: hardcoded size
gcry_error_t err = gcry_cipher_open( &cipher_, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR, 0 );
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::init: Failed to open cipher: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::init: Failed to open cipher: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
return;
}
@@ -107,8 +107,8 @@ void AesIcmKeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, Buffer
gcry_error_t err = gcry_cipher_reset( cipher_ );
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to reset cipher: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to reset cipher: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
}
// see at: http://tools.ietf.org/html/rfc3711#section-4.3
@@ -148,15 +148,15 @@ void AesIcmKeyDerivation::generate(satp_prf_label label, seq_nr_t seq_nr, Buffer
delete[] ctr_buf;
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to set CTR: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to set CTR: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
}
for(u_int32_t i=0; i < key.getLength(); ++i) key[i] = 0;
err = gcry_cipher_encrypt( cipher_, key, key.getLength(), NULL, 0);
if( err ) {
- char buf[NL_TEXTMAX];
- cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to generate cipher bitstream: " << gpg_strerror_r(err, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ cLog.msg(Log::PRIO_ERR) << "KeyDerivation::generate: Failed to generate cipher bitstream: " << gpg_strerror_r(err, buf, STERROR_TEXT_MAX);
}
}
diff --git a/src/linux/tunDevice.cpp b/src/linux/tunDevice.cpp
index 1882a93..a226641 100644
--- a/src/linux/tunDevice.cpp
+++ b/src/linux/tunDevice.cpp
@@ -28,6 +28,10 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#define _XOPEN_SOURCE 600
+#include <string.h>
+#include <sstream>
+
#include <fcntl.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
@@ -38,8 +42,6 @@
#include <linux/if_tun.h>
#define DEFAULT_DEVICE "/dev/net/tun"
-#include <sstream>
-
#include "tunDevice.h"
#include "threadUtils.hpp"
@@ -51,8 +53,8 @@ TunDevice::TunDevice(const char* dev_name, const char* dev_type, const char* ifc
std::string msg("can't open device file (");
msg.append(DEFAULT_DEVICE);
msg.append("): ");
- char buf[NL_TEXTMAX];
- strerror_r(errno, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ strerror_r(errno, buf, STERROR_TEXT_MAX);
msg.append(buf);
throw std::runtime_error(msg);
}
@@ -80,8 +82,8 @@ TunDevice::TunDevice(const char* dev_name, const char* dev_type, const char* ifc
actual_name_ = ifr.ifr_name;
} else {
std::string msg("tun/tap device ioctl failed: ");
- char buf[NL_TEXTMAX];
- strerror_r(errno, buf, NL_TEXTMAX);
+ char buf[STERROR_TEXT_MAX];
+ strerror_r(errno, buf, STERROR_TEXT_MAX);
msg.append(buf);
throw std::runtime_error(msg);
}