Skip to content

Commit 4d8990c

Browse files
authored
Add network typedefs to start cross-platform support (#6)
* Add network typedefs to start cross-platform support * use winsock2
1 parent bfd5dda commit 4d8990c

34 files changed

Lines changed: 148 additions & 113 deletions

Code/BandTest/BandTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static int Ping_Host(unsigned long host_ip, unsigned long my_ip, int times, int
204204
static float Average_Ping(int num_pings, unsigned long *ping_times, bool ignore_low_high);
205205
static float Lowest_Ping(int num_pings, unsigned long *ping_times);
206206
static int Get_Path_To_Server(unsigned long *path, unsigned long my_ip, unsigned long server_ip);
207-
static void Ping_Profile(SOCKADDR_IN *router_addr, unsigned long my_ip);
207+
static void Ping_Profile(struct sockaddr_in *router_addr, unsigned long my_ip);
208208

209209
static bool Set_Registry_Int(const char *name, int value);
210210
static int Get_Registry_Int(const char *name, int def_value);
@@ -1072,7 +1072,7 @@ unsigned long Upstream_Detect(unsigned long server_ip, unsigned long my_ip, int
10721072

10731073

10741074

1075-
void Ping_Profile(SOCKADDR_IN *router_addr, unsigned long my_ip)
1075+
void Ping_Profile(struct sockaddr_in *router_addr, unsigned long my_ip)
10761076
{
10771077
float ping_averages[1000];
10781078
unsigned long ping_times[100];

Code/Commando/bioevent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ cBioEvent::Act(void)
137137
// Record his IP address for diagnostic purposes
138138
//
139139
WWASSERT(cNetwork::Get_Server_Rhost(SenderId) != NULL);
140-
SOCKADDR_IN & address = cNetwork::Get_Server_Rhost(SenderId)->Get_Address();
140+
struct sockaddr_in & address = cNetwork::Get_Server_Rhost(SenderId)->Get_Address();
141141
p_player->Set_Ip_Address(address.sin_addr.s_addr);
142142

143143
//

Code/Commando/gamedata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ void cGameData::Rebalance_Team_Sides(void)
478478
void cGameData::Set_Ip_And_Port(void)
479479
{
480480
/*
481-
SOCKADDR_IN local_address;
481+
struct sockaddr_in local_address;
482482
bool retcode = cNetUtil::Get_Local_Address(&local_address);
483483
WWASSERT(retcode == true);
484484

Code/Commando/lanchat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#define LANCHAT_H
3333

3434
#include "win.h"
35-
#include <winsock.h>
35+
#include "network-typedefs.h"
3636

3737
#include "chatshre.h"
3838

@@ -72,7 +72,7 @@ class cLanChat
7272
void Process_Position_Broadcast(cPacket & packet);
7373

7474
SOCKET Socket;
75-
SOCKADDR_IN LocalAddress;
75+
struct sockaddr_in LocalAddress;
7676
DWORD LastPositionBroadcastTimeMs;
7777
int PositionBroadcastNumber;
7878
ChatLocationEnum CurrentLocation;

Code/Commando/natsock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "assert.h"
4444
#include "vector.h"
4545

46-
#include <winsock.h>
46+
#include "network-typedefs.h"
4747

4848
#ifndef DebugString
4949
#include "wwdebug.h"
@@ -231,4 +231,4 @@ class SocketHandlerClass
231231
};
232232

233233

234-
#endif //NATSOCK_H
234+
#endif //NATSOCK_H

Code/Commando/natter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ bool WOLNATInterfaceClass::Send_Game_Format_Packet_To(IPAddressClass *address, c
12741274

12751275
#if (0)
12761276
WWDEBUG_SAY(("WOLNATInterface - sendto %s\n", address->As_String()));
1277-
int result = sendto(socket_handler->Get_Socket(), full_packet.Get_Data(), full_packet.Get_Compressed_Size_Bytes(), 0, (LPSOCKADDR) &sock_address, sizeof(SOCKADDR_IN));
1277+
int result = sendto(socket_handler->Get_Socket(), full_packet.Get_Data(), full_packet.Get_Compressed_Size_Bytes(), 0, (LPSOCKADDR) &sock_address, sizeof(struct sockaddr_in));
12781278
if (result == SOCKET_ERROR){
12791279
if (LAST_ERROR != WSAEWOULDBLOCK) {
12801280
WWDEBUG_SAY(("WOLNATInterface - sendto returned error code %d\n", LAST_ERROR));
@@ -1379,7 +1379,7 @@ void WOLNATInterfaceClass::Service_Receive_Queue(SocketHandlerClass *socket)
13791379
unsigned short port;
13801380
int bytes = PacketManager.Get_Packet(socket->Get_Socket(), (unsigned char *)full_packet.Get_Data(), full_packet.Get_Max_Size(), ip_address, port);
13811381
if (bytes > 0) {
1382-
sockaddr_in *addr_ptr = (LPSOCKADDR_IN) &full_packet.Get_From_Address_Wrapper()->FromAddress;
1382+
sockaddr_in *addr_ptr = (struct sockaddr_in*) &full_packet.Get_From_Address_Wrapper()->FromAddress;
13831383
memcpy(&addr_ptr->sin_addr.s_addr, ip_address, 4);
13841384
addr_ptr->sin_port = port;
13851385
}

Code/Commando/nicenum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include "nicenum.h"
2727

28-
#include <winsock.h>
28+
#include "network-typedefs.h"
2929
#include <stdio.h>
3030

3131
#include "wwdebug.h"

Code/Commando/pkthandlers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void cNetwork::Server_Packet_Handler(cPacket & packet, int rhost_id)
131131
if (object != NULL)
132132
{
133133
#ifdef WWDEBUG
134-
//sockaddr_in *actual_from_addr_ptr = (LPSOCKADDR_IN) &packet.Get_From_Address_Wrapper()->FromAddress;
134+
//sockaddr_in *actual_from_addr_ptr = (struct sockaddr_in*) &packet.Get_From_Address_Wrapper()->FromAddress;
135135
//sockaddr_in rhost_addr = PServerConnection->Get_Remote_Host(rhost_id)->Get_Address();
136136
#endif //WWDEBUG
137137

Code/SControl/servercontrolsocket.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include "assert.h"
4343
#include "vector.h"
4444

45-
#include <winsock.h>
45+
#include "network-typedefs.h"
4646

4747
#ifndef DebugString
4848
#include "wwdebug.h"
@@ -209,4 +209,4 @@ class ServerControlSocketClass
209209
};
210210

211211

212-
#endif //SERVERCONTROLSOCKET_H
212+
#endif //SERVERCONTROLSOCKET_H

Code/Tests/Bandy/bandy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Functions: *
4040
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
4141

42-
#include <winsock.h>
42+
#include <winsock2.h>
4343
#include <assert.h>
4444
#include <stdio.h>
4545
#include <stdlib.h>

0 commit comments

Comments
 (0)