Open source remastering of the Freespace 2 engine
psnet2.h File Reference
#include <errno.h>
#include "globalincs/pstypes.h"

Go to the source code of this file.


struct  net_addr


#define NET_NONE   0
#define NET_TCP   1
#define NET_VMT   3
#define MAX_PACKET_SIZE   512
#define DEFAULT_GAME_PORT   7808
#define UDP_HEADER_SIZE   34
#define TCP_HEADER_SIZE   40
#define PSNET_NUM_TYPES   5
#define RNF_UNUSED   0
#define RNF_CONNECTED   1
#define RNF_BROKEN   2
#define RNF_CONNECTING   4
#define RNF_LIMBO   5


typedef struct net_addr net_addr
typedef uint PSNET_SOCKET


int RECVFROM (uint s, char *buf, int len, int flags, sockaddr *from, int *fromlen, int psnet_type)
int SELECT (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const timeval *timeout, int psnet_type)
int SENDTO (uint s, char *buf, int len, int flags, sockaddr *to, int tolen, int psnet_type)
void psnet_init (int protocol, int default_port)
void psnet_close ()
int psnet_use_protocol (int type)
int psnet_get_network_status ()
char * psnet_addr_to_string (char *text, net_addr *address)
void psnet_string_to_addr (net_addr *address, char *text)
int psnet_same (net_addr *a1, net_addr *a2)
int psnet_send (net_addr *who_to, void *data, int len, int np_index=-1)
int psnet_get (void *data, net_addr *from_addr)
int psnet_broadcast (net_addr *who_to, void *data, int len)
void psnet_flush ()
int psnet_is_valid_ip_string (char *ip_string, int allow_port=1)
void psnet_mark_received (PSNET_SOCKET_RELIABLE socket)
void psnet_rel_close_socket (PSNET_SOCKET_RELIABLE *sockp)
int psnet_rel_check ()
int psnet_rel_send (PSNET_SOCKET_RELIABLE socket, ubyte *data, int length, int np_index=-1)
int psnet_rel_get (PSNET_SOCKET_RELIABLE socket, ubyte *buffer, int max_length)
void psnet_rel_work ()
int psnet_rel_get_status (PSNET_SOCKET_RELIABLE sock)
int psnet_rel_check_for_listen (net_addr *addr)
void psnet_rel_connect_to_server (PSNET_SOCKET_RELIABLE *s, net_addr *server_addr)


net_addr Psnet_my_addr
uint Psnet_my_ip
int Psnet_my_addr_valid
int Network_status
int Tcp_failure_code
int Tcp_active
int Socket_type
int Psnet_connection
ushort Psnet_default_port
SOCKET Unreliable_socket

Macro Definition Documentation

#define DEFAULT_GAME_PORT   7808

Definition at line 36 of file psnet2.h.


Definition at line 53 of file psnet2.h.

#define MAX_PACKET_SIZE   512

Definition at line 34 of file psnet2.h.

#define NET_NONE   0

Definition at line 28 of file psnet2.h.

#define NET_TCP   1

Definition at line 29 of file psnet2.h.

#define NET_VMT   3

Definition at line 30 of file psnet2.h.


Definition at line 90 of file psnet2.h.


Definition at line 91 of file psnet2.h.


Definition at line 89 of file psnet2.h.


Definition at line 66 of file psnet2.h.


Definition at line 67 of file psnet2.h.


Definition at line 64 of file psnet2.h.


Definition at line 62 of file psnet2.h.


Definition at line 63 of file psnet2.h.


Definition at line 61 of file psnet2.h.


Definition at line 65 of file psnet2.h.

#define PSNET_NUM_TYPES   5

Definition at line 70 of file psnet2.h.


Definition at line 74 of file psnet2.h.


Definition at line 72 of file psnet2.h.


Definition at line 71 of file psnet2.h.


Definition at line 73 of file psnet2.h.


Definition at line 75 of file psnet2.h.

#define RNF_BROKEN   2

Definition at line 100 of file psnet2.h.

#define RNF_CONNECTED   1

Definition at line 99 of file psnet2.h.

#define RNF_CONNECTING   4

Definition at line 102 of file psnet2.h.


Definition at line 101 of file psnet2.h.

#define RNF_LIMBO   5

Definition at line 103 of file psnet2.h.

#define RNF_UNUSED   0

Definition at line 98 of file psnet2.h.

#define TCP_HEADER_SIZE   40

Definition at line 57 of file psnet2.h.


Definition at line 58 of file psnet2.h.

#define UDP_HEADER_SIZE   34

Definition at line 56 of file psnet2.h.

Typedef Documentation

typedef struct net_addr net_addr
typedef uint PSNET_SOCKET

Definition at line 46 of file psnet2.h.

Definition at line 47 of file psnet2.h.

Function Documentation

char* psnet_addr_to_string ( char *  text,
net_addr address 

Convert a net_addr to a string

Definition at line 705 of file psnet2.cpp.

int psnet_broadcast ( net_addr who_to,
void data,
int  len 

Broadcast data on unreliable socket

Definition at line 897 of file psnet2.cpp.

void psnet_close ( )

Shutdown psnet

Definition at line 563 of file psnet2.cpp.

void psnet_flush ( )

Flush all sockets

Definition at line 927 of file psnet2.cpp.

int psnet_get ( void data,
net_addr from_addr 

Get data from the unreliable socket

Definition at line 881 of file psnet2.cpp.

int psnet_get_network_status ( )

Get the status of the network

Definition at line 670 of file psnet2.cpp.

void psnet_init ( int  protocol,
int  port_num 

Initialize psnet to use the specified port

Definition at line 458 of file psnet2.cpp.

int psnet_is_valid_ip_string ( char *  ip_string,
int  allow_port 

If the passed string is a valid IP string

Definition at line 938 of file psnet2.cpp.

void psnet_mark_received ( PSNET_SOCKET_RELIABLE  socket)

Mark a socket as having received data

Definition at line 2174 of file psnet2.cpp.

int psnet_rel_check ( )

Definition at line 1067 of file psnet2.cpp.

int psnet_rel_check_for_listen ( net_addr from_addr)

Checks the Listen_socket for possibly incoming requests to be connected.

0 on error or nothing waiting. 1 if we should try to accept

Definition at line 1555 of file psnet2.cpp.

void psnet_rel_close_socket ( PSNET_SOCKET_RELIABLE sockp)

Function to shutdown and close the given socket.

It takes a couple of things into consideration when closing, such as possibly reiniting reliable sockets if they are closed here.

Definition at line 1008 of file psnet2.cpp.

void psnet_rel_connect_to_server ( PSNET_SOCKET socket,
net_addr server_addr 

Attempt to connect() to the server's tcp socket. socket parameter is simply assigned to the Reliable_socket socket created in psnet_init

Definition at line 1593 of file psnet2.cpp.

int psnet_rel_get ( PSNET_SOCKET_RELIABLE  socket,
ubyte buffer,
int  max_length 

Definition at line 1152 of file psnet2.cpp.

int psnet_rel_get_status ( PSNET_SOCKET_RELIABLE  socketid)

Get the status of a reliable socket, see RNF_* defines above

Definition at line 1542 of file psnet2.cpp.

int psnet_rel_send ( PSNET_SOCKET_RELIABLE  socketid,
ubyte data,
int  length,
int  np_index 

Send data reliably

Definition at line 1075 of file psnet2.cpp.

void psnet_rel_work ( )

Process all active reliable sockets

Definition at line 1187 of file psnet2.cpp.

int psnet_same ( net_addr a1,
net_addr a2 

Compare 2 addresses

Definition at line 785 of file psnet2.cpp.

int psnet_send ( net_addr who_to,
void data,
int  len,
int  np_index 

Send data unreliably

Definition at line 793 of file psnet2.cpp.

void psnet_string_to_addr ( net_addr address,
char *  text 

Convert a string to a net addr

Definition at line 732 of file psnet2.cpp.


Call this once per frame to read everything off of our socket

Definition at line 360 of file psnet2.cpp.

int psnet_use_protocol ( int  protocol)

Set the protocol to use

Definition at line 596 of file psnet2.cpp.

int RECVFROM ( uint  s,
char *  buf,
int  len,
int  flags,
sockaddr *  from,
int fromlen,
int  psnet_type 
int SELECT ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
const timeval *  timeout,
int  psnet_type 
int SENDTO ( uint  s,
char *  buf,
int  len,
int  flags,
sockaddr *  to,
int  tolen,
int  psnet_type 

Variable Documentation

int Network_status

Definition at line 62 of file psnet2.cpp.

int Psnet_connection

Definition at line 65 of file psnet2.cpp.

ushort Psnet_default_port

Definition at line 67 of file psnet2.cpp.

net_addr Psnet_my_addr

Definition at line 52 of file psnet2.cpp.

int Psnet_my_addr_valid

Definition at line 51 of file psnet2.cpp.

uint Psnet_my_ip
int Socket_type

Definition at line 56 of file psnet2.cpp.

int Tcp_active

Definition at line 60 of file psnet2.cpp.

int Tcp_failure_code

Definition at line 63 of file psnet2.cpp.

SOCKET Unreliable_socket

Definition at line 208 of file psnet2.cpp.