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

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 (unsigned long *ips, int maxAddr)
 Get local IPs. More...
 
std::string NetGetHostname ()
 Get local hostname. 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

◆ INADDR_NONE

#define INADDR_NONE   -1

◆ NIPQUAD

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

◆ USE_WINSOCK

#define USE_WINSOCK

Typedef Documentation

◆ Socket

typedef SOCKET Socket

Function Documentation

◆ NetAcceptTCP()

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.

◆ NetCloseTCP()

void NetCloseTCP ( Socket  sockfd)

Close a TCP socket port.

Close a TCP socket port.

Parameters
sockfdSocket fildes

◆ NetCloseUDP()

void NetCloseUDP ( Socket  sockfd)

Close a UDP socket port.

Close an UDP socket port.

Parameters
sockfdSocket fildes

◆ NetConnectTCP()

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

◆ NetExit()

void NetExit ( )

Hardware dependend network exit.

Hardware dependend network exit.

◆ NetGetHostname()

std::string NetGetHostname ( )

Get local hostname.

Return the system hostname.

◆ NetInit()

int NetInit ( )

Hardware dependend network init.

Hardware dependend network init.

◆ NetListenTCP()

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

◆ NetOpenTCP()

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

◆ NetOpenUDP()

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.

◆ NetRecvTCP()

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.

◆ NetRecvUDP()

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.

◆ NetResolveHost()

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)

◆ NetSendTCP()

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.

◆ NetSendUDP()

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.

◆ NetSetNonBlocking()

int NetSetNonBlocking ( Socket  sockfd)

Set socket to non-blocking.

Set socket to non-blocking.

Parameters
sockfdSocket
Returns
0 for success, -1 for error

◆ NetSocketAddr()

int NetSocketAddr ( unsigned long *  ips,
int  maxAddr 
)

Get local IPs.

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.

◆ NetSocketReady()

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.