diff --git a/examples/pipeExample.cpp b/examples/pipeExample.cpp index a0532fe..2368784 100755 --- a/examples/pipeExample.cpp +++ b/examples/pipeExample.cpp @@ -231,6 +231,7 @@ void PipeExample::OnServerEvent(ProtoSocket& /*theSocket*/, unsigned int len = 8191; if (server_pipe.Recv(buffer, len)) { + buffer[len] = '\0'; if (len) PLOG(PL_ERROR, "pipeExample: recvd \"%s\"\n", buffer); } diff --git a/examples/protoPipeSend.py b/examples/protoPipeSend.py index c23a1fb..6d43f69 100755 --- a/examples/protoPipeSend.py +++ b/examples/protoPipeSend.py @@ -21,8 +21,6 @@ # Uncomment this one to send as bytes (example/test) #msg = text.encode('ascii') -x = 12 - -pipe.Send(x) +pipe.Send(msg) print("Sent message '%s'" % text) diff --git a/makefiles/Makefile.common b/makefiles/Makefile.common index 10ba11e..3ef92e0 100755 --- a/makefiles/Makefile.common +++ b/makefiles/Makefile.common @@ -391,8 +391,9 @@ stree: $(STREE_OBJ) libprotokit.a clean: rm -f *.o $(COMMON)/*.o $(MANET)/*.o $(NS)/*.o ../src/*/*.o ../examples/*.o \ - *.a *.$(SYSTEM_SOEXT) ../lib/*.a ../lib/*.../bin/* $(SYSTEM_SOEXT) \ - arposer averageExample base64Example detourExample graphExample graphRider graphXMLExample jsonExample lfsrExample msg2MsgExample msgExample netExample pcmd pipe2SockExample pipeExample protoCapExample protoApp protoExample protoFileExample queueExample riposer serialExample simpleTcpExample sock2PipeExample threadExample timerTest ting vifExample vifLan gr ../bin/* + *.a *.$(SYSTEM_SOEXT) ../lib/*.a ../lib/* ../bin/* $(SYSTEM_SOEXT) \ + arposer averageExample base64Example detourExample graphExample graphRider graphXMLExample jsonExample lfsrExample msg2MsgExample msgExample netExample pcmd pipe2SockExample pipeExample protoCapExample protoApp protoExample protoFileExample queueExample riposer serialExample simpleTcpExample sock2PipeExample threadExample timerTest ting vifExample vifLan gr + rm -rf ../build/* ../protokit.egg-info # DO NOT DELETE THIS LINE -- mkdep uses it. diff --git a/src/common/protoNet.cpp b/src/common/protoNet.cpp index 26b543b..75f70c0 100755 --- a/src/common/protoNet.cpp +++ b/src/common/protoNet.cpp @@ -127,6 +127,9 @@ unsigned int ProtoNet::GetInterfaceAddressMask(unsigned int ifIndex, const Proto return 0; } #else + + // TBD - actually this appears to have been implemented and these #if/#else are OBE + // with them blocked within a larger #ifndef WIN32 ... so this code could be cleaned up. PLOG(PL_ERROR,"ProtoNet::GetInterfaceAddressMask() error: function not implemented for WIN32\n"); return 0; #endif diff --git a/src/common/protoSocket.cpp b/src/common/protoSocket.cpp index 943d989..2305b68 100755 --- a/src/common/protoSocket.cpp +++ b/src/common/protoSocket.cpp @@ -1303,6 +1303,7 @@ bool ProtoSocket::Accept(ProtoSocket* newSocket) bool ProtoSocket::Send(const char* buffer, unsigned int& numBytes) { + //TRACE("ProtoSocket::Send() ...\n"); if (IsConnected()) { #ifdef WIN32 diff --git a/src/linux/linuxDetour.cpp b/src/linux/linuxDetour.cpp index c44a6bc..91b5dfa 100755 --- a/src/linux/linuxDetour.cpp +++ b/src/linux/linuxDetour.cpp @@ -595,7 +595,9 @@ int LinuxDetour::NfqCallback(nfq_q_handle* nfqQueue, // A change to the nfq_get_payload() prototype seemed to kick in around Linux header files // version 3.6? (This will probably need to be fine tuned for the right version threshold.) +#ifndef LINUX_VERSION_MAJOR #define LINUX_VERSION_MAJOR (LINUX_VERSION_CODE/65536) +#endif // !LINUX_VERSION_MAJOR #define LINUX_VERSION_MINOR ((LINUX_VERSION_CODE - (LINUX_VERSION_MAJOR*65536)) / 256) #if ((LINUX_VERSION_MAJOR > 3) || ((LINUX_VERSION_MAJOR == 3) && (LINUX_VERSION_MINOR > 5))) diff --git a/src/python/protopipe.cpp b/src/python/protopipe.cpp index 17f0155..4fc330a 100755 --- a/src/python/protopipe.cpp +++ b/src/python/protopipe.cpp @@ -69,8 +69,8 @@ extern "C" { } } - static PyObject* Pipe_GetName(Pipe *self) { - + static PyObject* Pipe_GetName(Pipe *self) + { #if PY_MAJOR_VERSION >= 3 PyObject *rv = PyUnicode_FromString(self->thisptr->GetName()); //Human readable? #else @@ -83,7 +83,8 @@ extern "C" { return rv; } - static PyObject* Pipe_Connect(Pipe *self, PyObject *args) { + static PyObject* Pipe_Connect(Pipe *self, PyObject *args) + { const char * name; if (!PyArg_ParseTuple(args, "s", &name)) @@ -143,9 +144,10 @@ extern "C" { } if (PyObject_TypeCheck(obj, &PyUnicode_Type)) { - //PySys_WriteStdout("sending string ...\n"); - int size; - if (!PyArg_ParseTuple(args, "s#", &buffer, &size)) + //PySys_WriteStderr("sending string ...\n"); + Py_ssize_t size; + + if (NULL == (buffer = PyUnicode_AsUTF8AndSize(obj, &size))) { PyErr_SetString(ProtoError, "Invalid string."); return NULL; @@ -154,7 +156,7 @@ extern "C" { } else if (PyObject_TypeCheck(obj, &PyBytes_Type)) { - //PySys_WriteStdout("sending bytes ...\n"); + //PySys_WriteStderr("sending bytes ...\n"); Py_ssize_t size = PyBytes_Size(obj); if (0 == size) { @@ -171,7 +173,7 @@ extern "C" { } else if (PyObject_TypeCheck(obj, &PyByteArray_Type)) { - //PySys_WriteStdout("sending bytearray ...\n"); + //PySys_WriteStderr("sending bytearray ...\n"); Py_ssize_t size = PyByteArray_Size(obj); if (0 == size) { @@ -191,7 +193,7 @@ extern "C" { PyErr_SetString(ProtoError, "Invalid argument type (must be str, bytes, or bytearray)."); return NULL; } - //PySys_WriteStdout("sending message size %u\n", size_u); + if (!self->thisptr->Send(buffer, size_u)) { PyErr_SetString(ProtoError, "Could not send buffer."); return NULL; @@ -200,7 +202,7 @@ extern "C" { } static PyObject* Pipe_Recv(Pipe *self, PyObject *args) { - char *buffer; + //char *buffer; Py_ssize_t size; bool result = false; @@ -208,8 +210,16 @@ extern "C" { return NULL; unsigned int size_u = size; - buffer = new char[size]; - + // Had to use "malloc() here instead of "new" operator, + // but not really sure why + char* buffer = (char*)malloc(size_u); + + if (NULL == buffer) + { + PyErr_SetString(ProtoError, "Could not allocate receive buffer."); + return NULL; + } + // Release the GIL since this can block... Py_BEGIN_ALLOW_THREADS result = self->thisptr->Recv(buffer, size_u); @@ -217,8 +227,10 @@ extern "C" { //PySys_WriteStdout("received message size %u\n", size_u); - if (!result) { + if (!result) + { PyErr_SetString(ProtoError, "Could not recv."); + free(buffer); return NULL; } @@ -228,7 +240,7 @@ extern "C" { #else PyObject *rv = PyString_FromStringAndSize(buffer, size_u); //Human readable? #endif - delete[] buffer; + free(buffer); return rv; } diff --git a/src/python/protospace.cpp b/src/python/protospace.cpp index 20e7dd2..2d35960 100644 --- a/src/python/protospace.cpp +++ b/src/python/protospace.cpp @@ -321,7 +321,7 @@ extern "C" { // Init space with number of dimensions inferrred from list length unsigned int numDimensions = PyList_Size(pList); - double* originOrdinates = new double[numDimensions]; + double* originOrdinates = (double*)malloc(numDimensions); if (NULL == originOrdinates) { PyErr_SetString(ProtoError, "new origin ordinates error"); @@ -343,18 +343,18 @@ extern "C" { } else { - delete[] originOrdinates; + free(originOrdinates); PyErr_SetString(ProtoError, "Space ordinates must be integers or doubles"); return -1; } } if (!self->thisptr->Init(originOrdinates)) { - delete[] originOrdinates; + free(originOrdinates); PyErr_SetString(ProtoError, "ProtoSpace::Iterator::Init() error"); return -1; } - delete[] originOrdinates; + free(originOrdinates); // SpaceIterator maintains reference to Space until destroyed Py_INCREF(pSpace); self->py_space = pSpace; @@ -424,7 +424,7 @@ extern "C" { 0, /* tp_dictoffset */ (initproc)SpaceIterator_init, /* tp_init */ 0, /* tp_alloc */ - Space_new, /* tp_new */ + SpaceIterator_new, /* tp_new */ }; static PyObject* Space_iterate(Space* self, PyObject* args) @@ -499,5 +499,4 @@ extern "C" { return (PyObject*)iterator; } // end Space_iterate() - } // end extern "C" diff --git a/src/win32/win32Net.cpp b/src/win32/win32Net.cpp index a00cde4..610f124 100755 --- a/src/win32/win32Net.cpp +++ b/src/win32/win32Net.cpp @@ -1107,6 +1107,7 @@ bool ProtoNet::AddInterfaceAddress(unsigned int ifaceIndex, const ProtoAddress& PLOG(PL_ERROR, "ProtoNet::AddInterfaceAddress() no matching interface found for ifaceIndex %s", ifaceIndex); return false; }; + bool ProtoNet::AddInterfaceAddress(const char* ifaceName, const ProtoAddress& ifaceAddr, unsigned int maskLen, bool dhcp_enabled) { /*