Skip to content

Commit

Permalink
Merge pull request #23 from gedOHub/SCTPToServerSocket
Browse files Browse the repository at this point in the history
Sctp to server socket
  • Loading branch information
gedOHub committed May 6, 2016
2 parents eb1c472 + 2fff2cf commit b75096e
Show file tree
Hide file tree
Showing 306 changed files with 156,109 additions and 33 deletions.
6 changes: 5 additions & 1 deletion Client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ int _tmain(int argc, _TCHAR* argv[])
ToServer = gcnew UDPToServerSocket(settings->getSetting("serverAddress"),
settings->getSetting("serverPort"), &skaitomiSocket, &rasomiSocket, &klaidingiSocket, STOContainer, settings, tunnels);
}
else if (settings->getSetting("protocol") == "SCTP"){
ToServer = gcnew SCTPToServerSocket(settings->getSetting("serverAddress"),
settings->getSetting("serverPort"), &skaitomiSocket, &rasomiSocket, &klaidingiSocket, STOContainer, settings, tunnels);
}
else {
printf("Gauta nezinoma protocol reiksme\n");
exit(999);
Expand Down Expand Up @@ -97,7 +101,7 @@ int _tmain(int argc, _TCHAR* argv[])
tempWrite = rasomiSocket;
tempError = klaidingiSocket;
// Pasiemam dekriptorius kurie turi kazka nuskaitimui
if (select(Globals::maxD + 1, &tempRead, &tempWrite, &tempError, &time) == SOCKET_ERROR){
if (select(Globals::maxD + 1, &tempRead, nullptr, nullptr, nullptr) < 0){
// Select nepasiseke grazinti dekriptoriu
Console::WriteLine(WSAGetLastError());
switch(WSAGetLastError()){
Expand Down
39 changes: 24 additions & 15 deletions Client/Client.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
Expand All @@ -44,7 +44,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
Expand Down Expand Up @@ -87,23 +87,25 @@
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Full</Optimization>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>D:\git\GClient\GClientLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalUsingDirectories>
</AdditionalUsingDirectories>
<AdditionalIncludeDirectories>C:\Program Files\SctpDrv\inc\netinet;C:\Program Files\SctpDrv\inc;D:\git\GClient\GClientLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalUsingDirectories>%(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<WholeProgramOptimization>true</WholeProgramOptimization>
<OmitFramePointers>true</OmitFramePointers>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<AdditionalOptions />
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>D:\git\GClient\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>GClientLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>D:\git\GClient\Win32\Debug;D:\git\GClient\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sctpsp.lib;GClientLib.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
</Link>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
Expand Down Expand Up @@ -139,23 +141,27 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Full</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>D:\git\GClient\GClientLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>D:\git\GClient\sctpdrv-12_05_00\apps\inc;D:\git\GClient\sctpdrv-12_05_00\netinet6;D:\git\GClient\sctpdrv-12_05_00\netinet;D:\git\GClient\GClientLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
<OmitFramePointers>true</OmitFramePointers>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
<AdditionalUsingDirectories>%(AdditionalUsingDirectories)</AdditionalUsingDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<AdditionalOptions />
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>D:\git\GClient\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>GClientLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>D:\git\GClient\Release;C:\Program Files\SctpDrv\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sctpsp.lib;GClientLib.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
</Link>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
Expand Down Expand Up @@ -210,6 +216,9 @@
<ProjectReference Include="..\GClientLib\GClientLib.vcxproj">
<Project>{2cdf672d-6c97-466e-97be-000cc2850cdd}</Project>
</ProjectReference>
<ProjectReference Include="..\sctpdrv-12_05_00\sp\sctpsp\sctpsp.vcxproj">
<Project>{35d3177d-dc37-447a-9362-5b0dfd701e1a}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
10 changes: 8 additions & 2 deletions GClientLib/GClientLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
#pragma comment (lib, "Ws2_32.lib")
#using <mscorlib.dll>

#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <mswsock.h>
#include <WS2tcpip.h>
//#include <WS2sctp.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iphlpapi.h>
#include <stdio.h>
#include <process.h>
Expand Down
32 changes: 27 additions & 5 deletions GClientLib/GClientLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
Expand All @@ -43,7 +43,7 @@
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<CharacterSet>MultiByte</CharacterSet>
<CLRSupport>true</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
Expand Down Expand Up @@ -80,15 +80,22 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<AdditionalIncludeDirectories>C:\Program Files\SctpDrv\inc\netinet;C:\Program Files\SctpDrv\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions />
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
<AdditionalOptions>/ignore:4221</AdditionalOptions>
<AdditionalLibraryDirectories>$(SolutionDir)$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>sctpsp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Lib>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand All @@ -110,19 +117,28 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<AdditionalIncludeDirectories>D:\git\GClient\sctpdrv-12_05_00\netinet6;D:\git\GClient\sctpdrv-12_05_00\netinet;D:\git\GClient\sctpdrv-12_05_00\apps\inc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions />
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Lib>
<AdditionalLibraryDirectories>D:\git\GClient\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;sctpsp.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Lib>
<ProjectReference>
<LinkLibraryDependencies>true</LinkLibraryDependencies>
</ProjectReference>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand Down Expand Up @@ -166,6 +182,7 @@
<ClInclude Include="ToServerSocket.h" />
<ClInclude Include="TunnelContainer.h" />
<ClInclude Include="UDPToServerSocket.h" />
<ClInclude Include="usrsctp\usrsctp.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp" />
Expand All @@ -187,6 +204,11 @@
<ClCompile Include="TunnelContainer.cpp" />
<ClCompile Include="UDPToServerSocket.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\sctpdrv-12_05_00\sp\sctpsp\sctpsp.vcxproj">
<Project>{35d3177d-dc37-447a-9362-5b0dfd701e1a}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
5 changes: 4 additions & 1 deletion GClientLib/GClientLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
<Filter>Header Files\Sujungimai\Darbiniai\ToServerSocket</Filter>
</ClInclude>
<ClInclude Include="SCTPToServerSocket.h">
<Filter>Header Files\Sujungimai\Darbiniai\ToServerSocket</Filter>
</ClInclude>
<ClInclude Include="usrsctp\usrsctp.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
Expand Down Expand Up @@ -165,7 +168,7 @@
<Filter>Source Files\Sujungimai\Darbiniai\ToServerSocket</Filter>
</ClCompile>
<ClCompile Include="SCTPToServerSocket.cpp">
<Filter>Source Files</Filter>
<Filter>Source Files\Sujungimai\Darbiniai\ToServerSocket</Filter>
</ClCompile>
</ItemGroup>
</Project>
45 changes: 45 additions & 0 deletions GClientLib/SCTPToServerSocket.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "SCTPToServerSocket.h"
#include <ws2sctp.h>


GClientLib::SCTPToServerSocket::SCTPToServerSocket(string ip, string port, fd_set* skaitomiSocket, fd_set* rasomiSocket, fd_set* klaidingiSocket,
Expand All @@ -12,4 +13,48 @@ GClientLib::SCTPToServerSocket::SCTPToServerSocket(string ip, string port, fd_se

GClientLib::SCTPToServerSocket::~SCTPToServerSocket()
{
printf("Obejktas %s baigia darba\n", this->name);
}

int GClientLib::SCTPToServerSocket::Send(char* data, int lenght){
int returnValue = 0;
returnValue = sctp_send(this->Socket, data, lenght, NULL, 0);
if (returnValue < 0){
printf("%s", "Nepavyko isisusti duomenu");
}
return returnValue;
}

// Gaunam galimus adresu varaintus
void GClientLib::SCTPToServerSocket::GetAddressInfo(){
// Laikinieji kintamieji
struct addrinfo *result, hints;
// Nustatom paieskos parametrus
ZeroMemory(&hints, sizeof hints);
// Pildoma pagal http://msdn.microsoft.com/en-us/library/windows/desktop/ms737530(v=vs.85).aspx
// Ieskomp adreso tipas (IPv4, IPv6 ar kitas)
hints.ai_family = AF_UNSPEC;
// Sujungimo tipas
hints.ai_socktype = SOCK_STREAM;
// Transporto protokolas
hints.ai_protocol = IPPROTO_SCTP;
this->addrHints = &hints;
// Gaunam adreso duomenis
LPCSTR ip = this->IP->c_str();
LPCSTR port = this->PORT->c_str();
int rGetAddrInfo = getaddrinfo(ip, port, &hints, &result);
if (rGetAddrInfo != 0){
// Nepavyko gauti adreso duomenu
printf("Nepavyko gauti adreso duomenu: %d\n", rGetAddrInfo);
// Naikinam objekta
freeaddrinfo(result);
}
this->addrResult = result;
}

int GClientLib::SCTPToServerSocket::Recive(){
sockaddr_in clientAddress;
int AddrSize = sizeof(clientAddress);

return recvfrom(this->Socket, &this->buffer[0], TenMBofChar, 0, (SOCKADDR *)& clientAddress, &AddrSize);
}
19 changes: 19 additions & 0 deletions GClientLib/SCTPToServerSocket.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
#pragma once
#include "ToServerSocket.h"
#include "GClientLib.h"

namespace GClientLib{

ref class SCTPToServerSocket :
public ToServerSocket
{
public:
SCTPToServerSocket(string ip, string port, fd_set* skaitomiSocket, fd_set* rasomiSocket, fd_set* klaidingiSocket,
SocketToObjectContainer^ STOC, SettingsReader^ settings, TunnelContainer^ tunnel);
virtual ~SCTPToServerSocket();

//Perrasomos funkcijos

// Uzdarome sujungima
virtual bool CloseSocket()override{ return false; }
// Naikiname sujungima
virtual void ShutdownSocket()override{}
// Duomenu siuntimas
virtual int Send(char* data, int lenght) override;
// Metodas sksirtas priimti duomenis
virtual int Recive() override;

protected:
void GetAddressInfo() override;
private:

};
}

2 changes: 1 addition & 1 deletion GClientLib/ServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int GClientLib::ServerSocket::Accept(SocketToObjectContainer^ container){
} else {
struct sockaddr_in *p = (struct sockaddr_in *) &peer;
char address[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(p->sin_addr), address, INET_ADDRSTRLEN);
//inet_ntop(AF_INET, &(p->sin_addr), address, INET_ADDRSTRLEN);
// printf("Klientas %s prisijunge prie %d deskriptoriaus", address, (int)ntohs(p->sin_port));
}

Expand Down
1 change: 0 additions & 1 deletion GClientLib/UDPToServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ int GClientLib::UDPToServerSocket::GetPort(){
}

int GClientLib::UDPToServerSocket::Recive(){

sockaddr_in clientAddress;
int AddrSize = sizeof(clientAddress);

Expand Down
5 changes: 3 additions & 2 deletions GClientLib/gNetSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ GClientLib::gNetSocket::gNetSocket(string ip, string port, int tag, fd_set* skai
this->skaitomi = skaitomiSocket;
this->rasomi = rasomiSocket;
this->klaidingi = klaidingiSocket;
// Gaunam adreso duomenis
this->GetAddressInfo();
// Kuriam SOCKET
this->CreateSocket();
if (this->Socket != INVALID_SOCKET) {
Expand Down Expand Up @@ -73,6 +75,7 @@ GClientLib::gNetSocket::gNetSocket(int socket, int tag, fd_set* skaitomiSocket,
GClientLib::gNetSocket::~gNetSocket(){
this->RemuveFromLists();
this->CloseSocket();
WSACleanup();
}

// Grazina tag reiksme
Expand Down Expand Up @@ -154,8 +157,6 @@ void GClientLib::gNetSocket::ShutdownSocket(){
// Kuriam SOCKET
void GClientLib::gNetSocket::CreateSocket(){
struct addrinfo *ptr;
// Gaunam adreso duomenis
this->GetAddressInfo();
// Einam per visus gautus rezultatus
for (ptr = this->addrResult; ptr != NULL; ptr = ptr->ai_next){
// Bandom kurti socket
Expand Down
7 changes: 4 additions & 3 deletions GClientLib/gNetSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ namespace GClientLib {
bool read, write;
char* name;
// ---Funkcijos---
// Gaunam galimus adresu varaintus
void GetAddressInfo();

// Sukuriamas socketas
virtual void CreateSocket();
// Salina socketa is skaitomu, rasomu ir kalidingu sokcetu saras
void RemuveFromLists();

protected:
// Gaunam galimus adresu varaintus
virtual void GetAddressInfo();
public:
// Konstruktorius
gNetSocket(string ip, string port, int tag,
Expand Down
Loading

0 comments on commit b75096e

Please sign in to comment.