12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include "Network.h"
- #ifndef WIN32
- #include <iostream>
- #include <netdb.h>
- #include <signal.h>
- #endif
- #include <openssl/err.h>
- #include <openssl/ssl.h>
- #include <openssl/bio.h>
- // Starte Netzwerk
- void Network::Start( int maxClients )
- {
- #ifdef WIN32
- WSADATA lpwd;
- lpwd.iMaxSockets = maxClients;
- int fehler = WSAStartup( MAKEWORD( 2, 0 ), &lpwd );
- if( fehler != 0 )
- MessageBox( 0, "Win Sock 2.0 konnte nocht gestartet werden.", "Fehler", MB_ICONERROR );
- #else
- signal( SIGPIPE, SIG_IGN );
- #endif
- SSL_library_init();
- SSL_load_error_strings();
- }
- void Network::getHostName( char *name, int bufferLen )
- {
- gethostname( name, bufferLen );
- }
- char *Network::getHostAddresse()
- {
- char *addresse;
- char name[ 255 ] = "";
- getHostName( name, 255 );
- PHOSTENT hostinfo;
- hostinfo = gethostbyname( name );
- if( !hostinfo )
- {
- #ifdef WIN32
- MessageBox( 0, "Die Ip Addresse konnte nicht ermittelt werden.", "Fehler", MB_ICONERROR );
- #else
- std::cout << "Fehler: Die Ip Addresse konnte nicht ermittelt werden.";
- #endif
- }
- addresse = inet_ntoa( *( struct in_addr* )*hostinfo->h_addr_list );
- return addresse;
- }
- // Beende Netzwerk
- void Network::Exit()
- {
- #ifdef WIN32
- WSACleanup();
- #endif
- }
|