Add missing [] to delete.

Some clean up.
This commit is contained in:
joris 2013-03-19 18:42:31 +01:00
parent edf4c14348
commit 0a6e1760d5
3 changed files with 37 additions and 42 deletions

View file

@ -40,42 +40,27 @@
// Include system network headers
#ifdef USE_WIN32
#define USE_WINSOCK
# define USE_WINSOCK
#include <winsock2.h>
#include <windows.h>
#include <winsock.h>
//#include <ws2tcpip.h>
// MS Knowledge base fix for SIO_GET_INTERFACE_LIST with NT4.0 ++
#define SIO_GET_INTERFACE_LIST 0x4004747F
#define IFF_UP 1
#define IFF_LOOPBACK 4
typedef struct _OLD_INTERFACE_INFO {
unsigned long iiFlags; /* Interface flags */
SOCKADDR iiAddress; /* Interface address */
SOCKADDR iiBroadcastAddress; /* Broadcast address */
SOCKADDR iiNetmask; /* Network mask */
} OLD_INTERFACE_INFO;
#define INTERFACE_INFO OLD_INTERFACE_INFO
# include <winsock2.h>
#else // UNIX
#include <sys/time.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#ifndef __BEOS__
#include <net/if.h>
#include <arpa/inet.h>
#endif
#define INVALID_SOCKET -1
# include <sys/time.h>
# include <unistd.h>
# include <netinet/in.h>
# include <netdb.h>
# include <sys/socket.h>
# include <sys/ioctl.h>
# ifndef __BEOS__
# include <net/if.h>
# include <arpa/inet.h>
# endif
# define INVALID_SOCKET -1
#endif // !WIN32
#ifndef INADDR_NONE
#define INADDR_NONE -1
# define INADDR_NONE -1
#endif
/*----------------------------------------------------------------------------

View file

@ -46,6 +46,23 @@
//----------------------------------------------------------------------------
#ifdef USE_WIN32
#include <windows.h>
#include <winsock.h>
//#include <ws2tcpip.h>
// MS Knowledge base fix for SIO_GET_INTERFACE_LIST with NT4.0 ++
#define SIO_GET_INTERFACE_LIST 0x4004747F
#define IFF_UP 1
#define IFF_LOOPBACK 4
typedef struct _OLD_INTERFACE_INFO {
unsigned long iiFlags; /* Interface flags */
SOCKADDR iiAddress; /* Interface address */
SOCKADDR iiBroadcastAddress; /* Broadcast address */
SOCKADDR iiNetmask; /* Network mask */
} OLD_INTERFACE_INFO;
#define INTERFACE_INFO OLD_INTERFACE_INFO
typedef const char *setsockopttype;
typedef char *recvfrombuftype;
typedef char *recvbuftype;
@ -244,7 +261,7 @@ int NetSocketAddr(const Socket sock, unsigned long *ips, int maxAddr)
}
}
}
delete localAddr;
delete [] localAddr;
return nif;
}
#elif USE_LINUX // } {

View file

@ -44,7 +44,7 @@ public:
TEST_FIXTURE(AutoNetwork, NetResolveHost)
{
const unsigned long localhost = ntohl(0x7F000001); // 127.0.0.1
const unsigned long localhost = htonl(0x7F000001); // 127.0.0.1
CHECK_EQUAL(localhost, NetResolveHost("127.0.0.1"));
CHECK_EQUAL(localhost, NetResolveHost("localhost"));
@ -84,9 +84,7 @@ static unsigned long GetMyIP()
template<typename T>
void TCPWrite(Socket socket, const T &obj)
{
T dup(obj);
const char *buf = reinterpret_cast<const char *>(&dup);
const char *buf = reinterpret_cast<const char *>(&obj);
size_t s = 0;
while (s != sizeof(T)) {
s += NetSendTCP(socket, buf + s, sizeof(T) - s);
@ -232,15 +230,10 @@ TEST_FIXTURE(AutoNetwork, ExchangeTCP)
template<typename T>
void UDPWrite(Socket socket, const char *hostname, int port, const T &obj)
{
T dup(obj);
const long host = NetResolveHost(hostname);
const char *buf = reinterpret_cast<const char *>(&dup);
const char *buf = reinterpret_cast<const char *>(&obj);
port = htons(port);
size_t s = 0;
while (s != sizeof(T)) {
s += NetSendUDP(socket, host, port, buf + s, sizeof(T) - s);
}
NetSendUDP(socket, host, port, buf, sizeof(T));
}
template<typename T>