$treeview $search $mathjax
Stratagus  2.2.7
$projectbrief
$projectbrief
$searchbox
-->
         _________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

src/include/net_lowlevel.h File Reference

#include <vector>
#include <errno.h>
#include <time.h>
#include <winsock2.h>
#include <windows.h>
#include <winsock.h>

Go to the source code of this file.


Classes

struct  _OLD_INTERFACE_INFO
struct  SocketSet

net_lowlevel.h - The network low level header file.

#define USE_WINSOCK
#define SIO_GET_INTERFACE_LIST   0x4004747F
#define IFF_UP   1
#define IFF_LOOPBACK   4
#define INTERFACE_INFO   OLD_INTERFACE_INFO
#define INADDR_NONE   -1
#define NIPQUAD(ad)
typedef struct _OLD_INTERFACE_INFO OLD_INTERFACE_INFO
typedef SOCKET Socket
int NetLastSocket
unsigned long NetLastHost
 Last socket.
int NetLastPort
 Last host number (net format).
unsigned long NetLocalAddrs []
 Last port number (net format).
int NetInit ()
 Local IP-Addrs of this host (net format).
void NetExit ()
 Hardware dependend network exit.
unsigned long NetResolveHost (const std::string &host)
 Resolve host in name or or colon dot notation.
int NetSocketAddr (const Socket sock)
 Get local IP from network file descriptor.
Socket NetOpenUDP (const char *addr, int port)
 Open a UDP Socket port.
Socket NetOpenTCP (const char *addr, int port)
 Open a TCP Socket port.
void NetCloseUDP (Socket sockfd)
 Close a UDP socket port.
void NetCloseTCP (Socket sockfd)
 Close a TCP socket port.
int NetSetNonBlocking (Socket sockfd)
 Set socket to non-blocking.
int NetConnectTCP (Socket sockfd, unsigned long addr, int port)
 Open a TCP connection.
int NetSendUDP (Socket sockfd, unsigned long host, int port, const void *buf, int len)
 Send through a UPD socket to a host:port.
int NetSendTCP (Socket sockfd, const void *buf, int len)
 Send through a TCP socket.
int NetSocketReady (Socket sockfd, int timeout)
 Wait for socket ready.
int NetSocketSetReady (SocketSet *sockfd, int timeout)
 Wait for socket set ready.
int NetSocketSetSocketReady (SocketSet *set, Socket socket)
 Check if a socket in a socket set is ready.
int NetRecvUDP (Socket sockfd, void *buf, int len)
 Receive from a UDP socket.
int NetRecvTCP (Socket sockfd, void *buf, int len)
 Receive from a TCP socket.
int NetListenTCP (Socket sockfd)
 Listen for connections on a TCP socket.
Socket NetAcceptTCP (Socket sockfd)
 Accept a connection on a TCP socket.
void NetAddSocket (SocketSet *set, Socket socket)
 Add a socket to a socket set.
void NetDelSocket (SocketSet *set, Socket socket)
 Delete a socket from a socket set.

Define Documentation

#define IFF_LOOPBACK   4

#define IFF_UP   1

#define INADDR_NONE   -1

#define INTERFACE_INFO   OLD_INTERFACE_INFO

#define NIPQUAD ( ad   ) 

Value:

(int)(((ad) >> 24) & 0xff), (int)(((ad) >> 16) & 0xff), \
        (int)(((ad) >> 8) & 0xff), (int)((ad) & 0xff)

#define SIO_GET_INTERFACE_LIST   0x4004747F

#define USE_WINSOCK


Typedef Documentation

typedef SOCKET Socket


Function Documentation

Socket NetAcceptTCP ( Socket  sockfd  ) 

Accept a connection on a TCP socket.

Accept a connection on a TCP socket.

Parameters:
sockfd Socket
Returns:
If success the new socket fildes, -1 otherwise.

void NetAddSocket ( SocketSet set,
Socket  socket 
)

Add a socket to a socket set.

void NetCloseTCP ( Socket  sockfd  ) 

Close a TCP socket port.

Close a TCP socket port.

Parameters:
sockfd Socket fildes

void NetCloseUDP ( Socket  sockfd  ) 

Close a UDP socket port.

Close an UDP socket port.

Parameters:
sockfd Socket fildes

int NetConnectTCP ( Socket  sockfd,
unsigned long  addr,
int  port 
)

Open a TCP connection.

Open a TCP connection

Parameters:
sockfd An open socket to use
addr Address returned from NetResolveHost
port Port on remote host to connect to
Returns:
0 if success, -1 if failure

void NetDelSocket ( SocketSet set,
Socket  socket 
)

Delete a socket from a socket set.

void NetExit (  ) 

Hardware dependend network exit.

Hardware dependend network exit.

int NetInit (  ) 

Local IP-Addrs of this host (net format).

Hardware dependend network init.

Hardware dependend network init.

int NetListenTCP ( Socket  sockfd  ) 

Listen for connections on a TCP socket.

Listen for connections on a TCP socket.

Parameters:
sockfd Socket
Returns:
0 for success, -1 for error

Socket NetOpenTCP ( const char *  addr,
int  port 
)

Open a TCP Socket port.

Open a TCP socket

Parameters:
port Bind socket to a specific port number
Returns:
If success the socket fildes, -1 otherwise

Socket NetOpenUDP ( const char *  addr,
int  port 
)

Open a UDP Socket port.

Open an UDP Socket port.

Parameters:
port !=0 Port to bind in host notation.
Returns:
If success the socket fildes, -1 otherwise.

int NetRecvTCP ( Socket  sockfd,
void *  buf,
int  len 
)

Receive from a TCP socket.

Receive from a TCP socket.

Parameters:
sockfd Socket
buf Receive message buffer.
len Receive message buffer length.
Returns:
Number of bytes placed in buffer or -1 if failure.

int NetRecvUDP ( Socket  sockfd,
void *  buf,
int  len 
)

Receive from a UDP socket.

Receive from a UDP socket.

Parameters:
sockfd Socket
buf Receive message buffer.
len Receive message buffer length.
Returns:
Number of bytes placed in buffer, or -1 if failure.

unsigned long NetResolveHost ( const std::string &  host  ) 

Resolve host in name or or colon dot notation.

Resolve host in name or dotted quad notation.

Parameters:
host Host name (f.e. 192.168.0.0 or stratagus.net)

int NetSendTCP ( Socket  sockfd,
const void *  buf,
int  len 
)

Send through a TCP socket.

Send through a TCP socket.

Parameters:
sockfd Socket
buf Send message buffer.
len Send message buffer length.
Returns:
Number of bytes sent.

int NetSendUDP ( Socket  sockfd,
unsigned long  host,
int  port,
const void *  buf,
int  len 
)

Send through a UPD socket to a host:port.

Send through a UPD socket to a host:port.

Parameters:
sockfd Socket
host Host to send to (network byte order).
port Port of host to send to (network byte order).
buf Send message buffer.
len Send message buffer length.
Returns:
Number of bytes sent.

int NetSetNonBlocking ( Socket  sockfd  ) 

Set socket to non-blocking.

Set socket to non-blocking.

Parameters:
sockfd Socket
Returns:
0 for success, -1 for error

int NetSocketAddr ( const Socket  sock  ) 

Get local IP from network file descriptor.

Get IP-addrs of local interfaces from Network file descriptor and store them in the NetLocalAddrs array.

Parameters:
sock local socket.
Returns:
number of IP-addrs found.

int NetSocketReady ( Socket  sockfd,
int  timeout 
)

Wait for socket ready.

Wait for socket ready.

Parameters:
sockfd Socket fildes to probe.
timeout Timeout in 1/1000 seconds.
Returns:
1 if data is available, 0 if not, -1 if failure.

int NetSocketSetReady ( SocketSet set,
int  timeout 
)

Wait for socket set ready.

Wait for socket set ready.

Parameters:
set Socket set to probe.
timeout Timeout in 1/1000 seconds.
Returns:
1 if data is available, 0 if not, -1 if failure.

int NetSocketSetSocketReady ( SocketSet set,
Socket  socket 
)

Check if a socket in a socket set is ready.

Check if a socket in a socket set is ready.

Parameters:
set Socket set
socket Socket to check
Returns:
Non-zero if socket is ready


Variable Documentation

unsigned long NetLastHost

Last socket.

Last host number (net format).

unsigned long NetLocalAddrs[]

Last port number (net format).

(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.