summaryrefslogtreecommitdiffstats
path: root/source/cSocket.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-07 08:44:00 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-07 08:44:00 +0100
commit5750fbf65f1a27af80afb3e68353f3dc91d48bfc (patch)
tree4b51752c10242d7c07e75f6f077dc698636c6d7a /source/cSocket.cpp
parentcSocket: error reporting function now works correctly on GNU Linux; also includes the error number for all errors (diff)
downloadcuberite-5750fbf65f1a27af80afb3e68353f3dc91d48bfc.tar
cuberite-5750fbf65f1a27af80afb3e68353f3dc91d48bfc.tar.gz
cuberite-5750fbf65f1a27af80afb3e68353f3dc91d48bfc.tar.bz2
cuberite-5750fbf65f1a27af80afb3e68353f3dc91d48bfc.tar.lz
cuberite-5750fbf65f1a27af80afb3e68353f3dc91d48bfc.tar.xz
cuberite-5750fbf65f1a27af80afb3e68353f3dc91d48bfc.tar.zst
cuberite-5750fbf65f1a27af80afb3e68353f3dc91d48bfc.zip
Diffstat (limited to '')
-rw-r--r--source/cSocket.cpp57
1 files changed, 50 insertions, 7 deletions
diff --git a/source/cSocket.cpp b/source/cSocket.cpp
index 323ed59c8..90c31f58d 100644
--- a/source/cSocket.cpp
+++ b/source/cSocket.cpp
@@ -17,6 +17,12 @@
+ unsigned long cSocket::INTERNET_ADDRESS_LOCALHOST = htonl((127 << 24) | 1);
+
+
+
+
+
cSocket::cSocket(xSocket a_Socket)
: m_Socket(a_Socket)
{
@@ -194,13 +200,9 @@ int cSocket::Bind(SockAddr_In& a_Address)
{
sockaddr_in local;
- if (a_Address.Family == ADDRESS_FAMILY_INTERNET)
- local.sin_family = AF_INET;
-
- if (a_Address.Address == INTERNET_ADDRESS_ANY)
- local.sin_addr.s_addr = INADDR_ANY;
-
- local.sin_port=htons((u_short)a_Address.Port);
+ local.sin_family = a_Address.Family;
+ local.sin_addr.s_addr = a_Address.Address;
+ local.sin_port = htons((u_short)a_Address.Port);
return bind(m_Socket, (sockaddr*)&local, sizeof(local));
}
@@ -238,6 +240,21 @@ cSocket cSocket::Accept()
+int cSocket::Connect(SockAddr_In & a_Address)
+{
+ sockaddr_in local;
+
+ local.sin_family = a_Address.Family;
+ local.sin_addr.s_addr = a_Address.Address;
+ local.sin_port = htons((u_short)a_Address.Port);
+
+ return connect(m_Socket, (sockaddr *)&local, sizeof(local));
+}
+
+
+
+
+
int cSocket::Receive(char* a_Buffer, unsigned int a_Length, unsigned int a_Flags)
{
return recv(m_Socket, a_Buffer, a_Length, a_Flags);
@@ -246,3 +263,29 @@ int cSocket::Receive(char* a_Buffer, unsigned int a_Length, unsigned int a_Flags
+
+int cSocket::Send(const char * a_Buffer, unsigned int a_Length)
+{
+ return send(m_Socket, a_Buffer, a_Length, 0);
+}
+
+
+
+
+
+unsigned short cSocket::GetPort(void) const
+{
+ assert(IsValid());
+
+ sockaddr_in Addr;
+ socklen_t AddrSize = sizeof(Addr);
+ if (getsockname(m_Socket, (sockaddr *)&Addr, &AddrSize) != 0)
+ {
+ return 0;
+ }
+ return Addr.sin_port;
+}
+
+
+
+