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

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes
net_lowlevel.h File Reference
#include <vector>
#include <winsock2.h>

Go to the source code of this file.

Classes

class  SocketSet
 

net_lowlevel.h - The network low level header file.

#define USE_WINSOCK
 
#define INADDR_NONE   -1
 
#define NIPQUAD(ad)
 
typedef SOCKET Socket
 
int NetInit ()
 Hardware dependend network init. More...
 
void NetExit ()
 Hardware dependend network exit. More...
 
unsigned long NetResolveHost (const std::string &host)
 Resolve host in name or or colon dot notation. More...
 
int NetSocketAddr (const Socket sock, unsigned long *ips, int maxAddr)
 Get local IP from network file descriptor. More...
 
Socket NetOpenUDP (unsigned long ip, int port)
 Open a UDP Socket port. (param in network format) More...
 
void NetCloseUDP (Socket sockfd)
 Close a UDP socket port. More...
 
int NetSendUDP (Socket sockfd, unsigned long host, int port, const void *buf, int len)
 Send through a UPD socket to a host:port. More...
 
int NetRecvUDP (Socket sockfd, void *buf, int len, unsigned long *hostFrom, int *portFrom)
 Receive from a UDP socket. More...
 
Socket NetOpenTCP (const char *addr, int port)
 Open a TCP Socket port. More...
 
void NetCloseTCP (Socket sockfd)
 Close a TCP socket port. More...
 
int NetConnectTCP (Socket sockfd, unsigned long addr, int port)
 Open a TCP connection. More...
 
int NetSendTCP (Socket sockfd, const void *buf, int len)
 Send through a TCP socket. More...
 
int NetRecvTCP (Socket sockfd, void *buf, int len)
 Receive from a TCP socket. More...
 
int NetListenTCP (Socket sockfd)
 Listen for connections on a TCP socket. More...
 
Socket NetAcceptTCP (Socket sockfd, unsigned long *clientHost, int *clientPort)
 Accept a connection on a TCP socket. More...
 
int NetSetNonBlocking (Socket sockfd)
 Set socket to non-blocking. More...
 
int NetSocketReady (Socket sockfd, int timeout)
 Wait for socket ready. More...
 

Macro Definition Documentation

#define INADDR_NONE   -1
#define NIPQUAD (   ad)
Value:
(int)(((ad) >> 24) & 0xff), (int)(((ad) >> 16) & 0xff), \
(int)(((ad) >> 8) & 0xff), (int)((ad) & 0xff)
#define USE_WINSOCK

Typedef Documentation

typedef SOCKET Socket

Function Documentation

Socket NetAcceptTCP ( Socket  sockfd,
unsigned long *  clientHost,
int *  clientPort 
)

Accept a connection on a TCP socket.

Accept a connection on a TCP socket.

Parameters
sockfdSocket
clientHosthost of the client connected.
clientPortport of the client connected.
Returns
If success the new socket fildes, -1 otherwise.
void NetCloseTCP ( Socket  sockfd)

Close a TCP socket port.

Close a TCP socket port.

Parameters
sockfdSocket fildes
void NetCloseUDP ( Socket  sockfd)

Close a UDP socket port.

Close an UDP socket port.

Parameters
sockfdSocket fildes
int NetConnectTCP ( Socket  sockfd,
unsigned long  addr,
int  port 
)

Open a TCP connection.

Open a TCP connection

Parameters
sockfdAn open socket to use
addrAddress returned from NetResolveHost
portPort on remote host to connect to
Returns
0 if success, -1 if failure
void NetExit ( )

Hardware dependend network exit.

Hardware dependend network exit.

int NetInit ( )

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
sockfdSocket
Returns
0 for success, -1 for error
Socket NetOpenTCP ( const char *  addr,
int  port 
)

Open a TCP Socket port.

Open a TCP socket

Parameters
portBind socket to a specific port number
Returns
If success the socket fildes, -1 otherwise
Socket NetOpenUDP ( unsigned long  ip,
int  port 
)

Open a UDP Socket port. (param in network format)

Open an UDP Socket port.

Parameters
ip!=0 Ip to bind in host notation.
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
sockfdSocket
bufReceive message buffer.
lenReceive message buffer length.
Returns
Number of bytes placed in buffer or -1 if failure.
int NetRecvUDP ( Socket  sockfd,
void *  buf,
int  len,
unsigned long *  hostFrom,
int *  portFrom 
)

Receive from a UDP socket.

Receive from a UDP socket.

Parameters
sockfdSocket
bufReceive message buffer.
lenReceive message buffer length.
hostFromhost of the sender.
portFromport of the sender.
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
hostHost 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
sockfdSocket
bufSend message buffer.
lenSend 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
sockfdSocket
hostHost to send to (network byte order).
portPort of host to send to (network byte order).
bufSend message buffer.
lenSend message buffer length.
Returns
Number of bytes sent.
int NetSetNonBlocking ( Socket  sockfd)

Set socket to non-blocking.

Set socket to non-blocking.

Parameters
sockfdSocket
Returns
0 for success, -1 for error
int NetSocketAddr ( const Socket  sock,
unsigned long *  ips,
int  maxAddr 
)

Get local IP from network file descriptor.

Get IP-addrs of local interfaces from Network file descriptor

Parameters
socklocal socket.
ipswhere to stock ip addrs.
maxAddrsize of ips.
Returns
number of IP-addrs found.
int NetSocketReady ( Socket  sockfd,
int  timeout 
)

Wait for socket ready.

Wait for socket ready.

Parameters
sockfdSocket fildes to probe.
timeoutTimeout in 1/1000 seconds.
Returns
1 if data is available, 0 if not, -1 if failure.
(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.