____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

lowlevel.cpp File Reference

The network lowlevel. More...

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include "stratagus.h"
#include "net_lowlevel.h"
#include "network.h"

Go to the source code of this file.

Defines

#define MAX_LOC_IP   10

Typedefs

typedef const void * setsockopttype
typedef void * recvfrombuftype
typedef void * recvbuftype
typedef const void * sendtobuftype
typedef const void * sendbuftype

Functions

int NetInit (void)
 < Hardware dependend network init.
void NetExit (void)
 Resolve host in name or or colon dot notation.
void NetCloseUDP (Socket sockfd)
 Close a TCP socket port.
void NetCloseTCP (Socket sockfd)
 Set socket to non-blocking.
int NetSetNonBlocking (Socket sockfd)
 Open a TCP connection.
unsigned long NetResolveHost (const std::string &host)
 Get local IP from network file descriptor.
int NetSocketAddr (const Socket sock)
 Open a UDP Socket port.
Socket NetOpenUDP (int port)
 Open a TCP Socket port.
Socket NetOpenTCP (int port)
 Close a UDP socket port.
int NetConnectTCP (Socket sockfd, unsigned long addr, int port)
 Send through a UPD socket to a host:port.
int NetSocketReady (Socket sockfd, int timeout)
 Wait for socket set ready.
int NetSocketSetReady (SocketSet *set, int timeout)
 Check if a socket in a socket set is ready.
int NetSocketSetSocketReady (SocketSet *set, Socket socket)
 Receive from a UDP socket.
int NetRecvUDP (Socket sockfd, void *buf, int len)
 Receive from a TCP socket.
int NetRecvTCP (Socket sockfd, void *buf, int len)
 Listen for connections on a TCP socket.
int NetSendUDP (Socket sockfd, unsigned long host, int port, const void *buf, int len)
 Send through a TCP socket.
int NetSendTCP (Socket sockfd, const void *buf, int len)
 Wait for socket ready.
int NetListenTCP (Socket sockfd)
 Accept a connection on a TCP socket.
Socket NetAcceptTCP (Socket sockfd)
 Add a socket to a socket set.

Variables

int NetLastSocket
 Last socket.
unsigned long NetLastHost
 Last host number (net format).
int NetLastPort
 Last port number (net format).
unsigned long NetLocalAddrs [MAX_LOC_IP]
 Local IP-Addrs of this host (net format).


Detailed Description

The network lowlevel.

Definition in file lowlevel.cpp.


Define Documentation

#define MAX_LOC_IP   10

Definition at line 54 of file lowlevel.cpp.


Typedef Documentation

typedef void* recvbuftype

Definition at line 66 of file lowlevel.cpp.

typedef void* recvfrombuftype

Definition at line 65 of file lowlevel.cpp.

typedef const void* sendbuftype

Definition at line 68 of file lowlevel.cpp.

typedef const void* sendtobuftype

Definition at line 67 of file lowlevel.cpp.

typedef const void* setsockopttype

Definition at line 64 of file lowlevel.cpp.


Function Documentation

Socket NetAcceptTCP ( Socket  sockfd  ) 

Add a socket to a socket set.

Accept a connection on a TCP socket.

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

Definition at line 703 of file lowlevel.cpp.

References NetLastHost, NetLastPort, and NetLastSocket.

void NetCloseTCP ( Socket  sockfd  ) 

Set socket to non-blocking.

Close a TCP socket port.

Parameters:
sockfd Socket fildes

Definition at line 170 of file lowlevel.cpp.

Referenced by NetOpenTCP().

void NetCloseUDP ( Socket  sockfd  ) 

Close a TCP socket port.

Close an UDP socket port.

Parameters:
sockfd Socket fildes

Definition at line 160 of file lowlevel.cpp.

Referenced by ExitNetwork1(), and NetOpenUDP().

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

Send through a UPD socket to a host:port.

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

Definition at line 456 of file lowlevel.cpp.

References INADDR_NONE, and NIPQUAD.

void NetExit ( void   ) 

Resolve host in name or or colon dot notation.

Hardware dependend network exit.

Definition at line 151 of file lowlevel.cpp.

Referenced by ExitNetwork1(), and InitNetwork1().

int NetInit ( void   ) 

< Hardware dependend network init.

Hardware dependend network init.

Definition at line 143 of file lowlevel.cpp.

Referenced by InitNetwork1().

int NetListenTCP ( Socket  sockfd  ) 

Accept a connection on a TCP socket.

Listen for connections on a TCP socket.

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

Definition at line 691 of file lowlevel.cpp.

References PlayerMax.

Socket NetOpenTCP ( int  port  ) 

Close a UDP socket port.

Open a TCP socket

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

Definition at line 414 of file lowlevel.cpp.

References INVALID_SOCKET, NetCloseTCP(), NetLastHost, NetLastPort, and NetLastSocket.

Socket NetOpenUDP ( int  port  ) 

Open a TCP Socket port.

Open an UDP Socket port.

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

Definition at line 378 of file lowlevel.cpp.

References INVALID_SOCKET, NetCloseUDP(), NetLastHost, and NetLastPort.

Referenced by InitNetwork1().

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

Listen for connections on 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.

Definition at line 621 of file lowlevel.cpp.

References NetLastSocket.

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

Receive from a TCP 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.

Definition at line 590 of file lowlevel.cpp.

References NetLastHost, NetLastPort, and PrintFunction.

Referenced by NetworkEvent(), and NetworkServerStartGame().

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

Get local IP from network file descriptor.

Resolve host in name or dotted quad notation.

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

Definition at line 203 of file lowlevel.cpp.

References Assert, and INADDR_NONE.

Referenced by InitNetwork1(), and NetworkSetupServerAddress().

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

Wait for socket ready.

Send through a TCP socket.

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

Definition at line 679 of file lowlevel.cpp.

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

Send through a TCP socket.

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.

Definition at line 654 of file lowlevel.cpp.

Referenced by NetworkBroadcast(), NetworkSendICMessage(), and NetworkSendSelection().

int NetSetNonBlocking ( Socket  sockfd  ) 

Open a TCP connection.

Set socket to non-blocking.

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

Definition at line 191 of file lowlevel.cpp.

int NetSocketAddr ( const Socket  sock  ) 

Open a UDP Socket port.

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.

Definition at line 363 of file lowlevel.cpp.

References NetLocalAddrs.

Referenced by InitNetwork1().

int NetSocketReady ( Socket  sockfd,
int  timeout 
)

Wait for socket set 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.

Definition at line 494 of file lowlevel.cpp.

Referenced by NetworkServerStartGame().

int NetSocketSetReady ( SocketSet set,
int  timeout 
)

Check if a socket in a socket set is 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.

Definition at line 529 of file lowlevel.cpp.

int NetSocketSetSocketReady ( SocketSet set,
Socket  socket 
)

Receive from a UDP socket.

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

Definition at line 570 of file lowlevel.cpp.

References DebugPrint.


Variable Documentation

unsigned long NetLastHost

Last socket.

Definition at line 75 of file lowlevel.cpp.

Referenced by NetAcceptTCP(), NetOpenTCP(), and NetRecvTCP().

unsigned long NetLocalAddrs[MAX_LOC_IP]

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

Definition at line 79 of file lowlevel.cpp.

Referenced by InitNetwork1(), and NetSocketAddr().


Generated on Sat Feb 21 00:28:17 2009 for Bos Wars by  doxygen 1.5.6