____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
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"
#include <vector>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <arpa/inet.h>
Go to the source code of this file.
Classes | |
| struct | SocketSet |
Defines | |
| #define | INVALID_SOCKET -1 |
| #define | INADDR_NONE -1 |
| #define | NIPQUAD(ad) |
Typedefs | |
| typedef int | Socket |
Functions | |
| int | NetInit (void) |
| < Hardware dependend network init. | |
| void | NetExit (void) |
| Resolve host in name or or colon dot notation. | |
| 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. | |
| 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. | |
| int | NetConnectTCP (Socket sockfd, unsigned long addr, int port) |
| Send through a UPD socket to a host:port. | |
| 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 | NetSocketReady (Socket sockfd, int timeout) |
| Wait for socket set ready. | |
| int | NetSocketSetReady (SocketSet *sockfd, 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 | NetListenTCP (Socket sockfd) |
| Accept a connection on a TCP socket. | |
| Socket | NetAcceptTCP (Socket sockfd) |
| Add a socket to a socket set. | |
| void | NetAddSocket (SocketSet *set, Socket socket) |
| Delete a socket from a socket set. | |
| void | NetDelSocket (SocketSet *set, Socket socket) |
Variables | |
| int | NetLastSocket |
| Last socket. | |
| unsigned long | NetLastHost |
| Last host number (net format). | |
| int | NetLastPort |
| Last port number (net format). | |
| unsigned long | NetLocalAddrs [] |
| Local IP-Addrs of this host (net format). | |
Definition in file net_lowlevel.h.
| #define INADDR_NONE -1 |
Definition at line 83 of file net_lowlevel.h.
Referenced by NetConnectTCP(), NetResolveHost(), and NetworkSetupServerAddress().
| #define INVALID_SOCKET -1 |
| #define NIPQUAD | ( | ad | ) |
Value:
(int)(((ad) >> 24) & 0xff), (int)(((ad) >> 16) & 0xff), \ (int)(((ad) >> 8) & 0xff), (int)((ad) & 0xff)
Definition at line 90 of file net_lowlevel.h.
Referenced by CheckVersions(), ClientParseConnecting(), ClientParseSynced(), InitNetwork1(), NetConnectTCP(), NetworkEvent(), NetworkExitServerConnect(), NetworkParseMenuPacket(), NetworkProcessServerRequest(), NetworkSendRateLimitedClientMessage(), NetworkServerStartGame(), NetworkSetupServerAddress(), ServerParseGoodBye(), ServerParseHello(), ServerParseMap(), ServerParseResync(), ServerParseState(), and ServerParseWaiting().
| typedef int Socket |
Definition at line 97 of file net_lowlevel.h.
Add a socket to a socket set.
Accept a connection on a TCP socket.
| sockfd | Socket |
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.
| 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.
| 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
| sockfd | An open socket to use | |
| addr | Address returned from NetResolveHost | |
| port | Port on remote host to connect to |
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 exit.
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.
| sockfd | Socket |
Definition at line 691 of file lowlevel.cpp.
References PlayerMax.
| Socket NetOpenTCP | ( | int | port | ) |
Close a UDP socket port.
Open a TCP socket
| port | Bind socket to a specific port number |
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.
| port | !=0 Port to bind in host notation. |
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.
| sockfd | Socket | |
| buf | Receive message buffer. | |
| len | Receive message buffer length. |
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.
| sockfd | Socket | |
| buf | Receive message buffer. | |
| len | Receive message buffer length. |
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.
| 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.
| sockfd | Socket | |
| buf | Send message buffer. | |
| len | Send message buffer length. |
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.
| 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. |
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.
| sockfd | Socket |
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.
| sock | local socket. |
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.
| sockfd | Socket fildes to probe. | |
| timeout | Timeout in 1/1000 seconds. |
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.
| set | Socket set to probe. | |
| timeout | Timeout in 1/1000 seconds. |
Definition at line 529 of file lowlevel.cpp.
Receive from a UDP socket.
Check if a socket in a socket set is ready.
| set | Socket set | |
| socket | Socket to check |
Definition at line 570 of file lowlevel.cpp.
References DebugPrint.
| unsigned long NetLastHost |
Last host number (net format).
Definition at line 76 of file lowlevel.cpp.
Referenced by CheckVersions(), ClientParseConnecting(), ClientParseSynced(), NetAcceptTCP(), NetOpenTCP(), NetOpenUDP(), NetRecvUDP(), NetworkEvent(), NetworkParseMenuPacket(), NetworkServerStartGame(), ServerParseGoodBye(), ServerParseHello(), ServerParseMap(), ServerParseResync(), ServerParseState(), and ServerParseWaiting().
| int NetLastPort |
Last port number (net format).
Definition at line 77 of file lowlevel.cpp.
Referenced by CheckVersions(), ClientParseConnecting(), ClientParseSynced(), InitNetwork1(), NetAcceptTCP(), NetOpenTCP(), NetOpenUDP(), NetRecvUDP(), NetworkEvent(), NetworkParseMenuPacket(), NetworkServerStartGame(), ServerParseGoodBye(), ServerParseHello(), ServerParseMap(), ServerParseResync(), ServerParseState(), and ServerParseWaiting().
| int NetLastSocket |
Last socket.
Definition at line 75 of file lowlevel.cpp.
Referenced by NetAcceptTCP(), NetOpenTCP(), and NetRecvTCP().
| unsigned long NetLocalAddrs[] |
Local IP-Addrs of this host (net format).
Definition at line 79 of file lowlevel.cpp.
Referenced by InitNetwork1(), and NetSocketAddr().
1.5.6