#include <UDP_Socket.hpp>
Inheritance diagram for UDP_Socket::

Public Methods | |
| __inline | UDP_Socket () |
| virtual __inline | ~UDP_Socket () |
| __inline int | getSocket () |
| __inline void | setSocket (int socket) |
| virtual __inline bool | send (void *msg, size_t msgLen)=0 |
| bool | send (void *msg, size_t msgLength, struct sockaddr_in *dest) |
| void | PrintIP (ULONG ipname) |
| void | PrintInfo () |
Protected Methods | |
| void | getHostData (char *host) |
Protected Attributes | |
| int | mySocket |
| hostent * | hostdata |
| char | buffer [40960] |
| sockaddr_in | server |
|
|
Definition at line 6 of file UDP_Socket.cpp. 00007 : mySocket( INVALID_SOCKET) { } |
|
|
Definition at line 19 of file UDP_Socket.cpp. 00020 {
00021 if ( mySocket != INVALID_SOCKET )
00022 {
00023 closesocket( mySocket );
00024 }
00025 }
|
|
|
Definition at line 58 of file UDP_Socket.cpp. 00059 {
00060 ULONG ipn = ipname;
00061 UCHAR ip1, ip2, ip3, ip4;
00062
00063 ip4 = ipn % 256;
00064 ipn >>= 8;
00065
00066 ip3 = ipn % 256;
00067 ipn >>= 8;
00068
00069 ip2 = ipn % 256;
00070 ipn >>= 8;
00071
00072 ip1 = ipn % 256;
00073 ipn >>= 8;
00074
00075 printf( "\nIP =[ %u | %u.%u.%u.%u ]\n", \
00076 ipname, ip1, ip2, ip3, ip4 );
00077
00078 fflush( stdout );
00079 }
|
|
|
Definition at line 101 of file UDP_Socket.cpp. Referenced by UDP_SocketClient::UDP_SocketClient(), and UDP_SocketServer::UDP_SocketServer().
00102 {
00103 printf( "\n\nHostName: %s\n", hostdata->h_name );
00104 printf( "IP address: %s\n", inet_ntoa(*((struct in_addr*) hostdata->h_addr )) );
00105
00106 option.setHostName( hostdata->h_name );
00107
00108 // PrintIP( server.sin_addr.s_addr );
00109
00110 fflush( stdout );
00111 }
|
|
|
Definition at line 81 of file UDP_Socket.cpp. Referenced by UDP_SocketClient::UDP_SocketClient(), and UDP_SocketServer::UDP_SocketServer().
00082 {
00083 if ( atoi( host) ) // Host is given by IPv4 format "x.x.x.x"
00084 {
00085 ULONG ip = inet_addr( host );
00086 hostdata = gethostbyaddr( (char*)&ip, sizeof(ip), PF_INET );
00087
00088 } else { // Host is given by name format "server.host.ca"
00089
00090 hostdata = gethostbyname( host );
00091 }
00092
00093 if ( hostdata == NULL )
00094 {
00095 printf( "Error getting host address\n" );
00096 fflush( stdout );
00097 exit( 1 );
00098 }
00099 }
|
|
|
Definition at line 14 of file UDP_Socket.cpp. 00015 {
00016 return mySocket;
00017 }
|
|
||||||||||||||||
|
Definition at line 28 of file UDP_Socket.cpp. 00030 {
00031 signed int Sent;
00032
00033 printf( "Message being sent to host %s port %u size %u \n",
00034 inet_ntoa( dest->sin_addr ),
00035 ntohs( dest->sin_port ),
00036 msgLength
00037 );
00038
00039 size_t pduLength = msgLength;
00040 if ( pduLength > 60 ) pduLength = 60;
00041 option.showChar( "Send:", (char*)msg, pduLength );
00042 Sent = sendto( mySocket, msg, msgLength, 0,
00043 (struct sockaddr *)dest,
00044 sizeof( struct sockaddr_in )
00045 );
00046
00047 memset( msg, 0, msgLength );
00048 if ( Sent != msgLength )
00049 {
00050 printf( "Error sending UDP packet from listen socket\n" );
00051 fflush( stdout );
00052 return FALSE;
00053 }
00054
00055 return TRUE;
00056 }
|
|
||||||||||||
|
Reimplemented in UDP_SocketClient, and UDP_SocketServer. Referenced by UDP_SocketServer::send(), and UDP_SocketClient::send().
|
|
|
Definition at line 9 of file UDP_Socket.cpp. 00010 {
00011 mySocket = socket;
00012 }
|
|
|
Definition at line 37 of file UDP_Socket.hpp. Referenced by UDP_SocketServer::ListenThread(), and UDP_SocketClient::ListenThread().
|
|
|
Definition at line 35 of file UDP_Socket.hpp. |
|
|
Definition at line 32 of file UDP_Socket.hpp. Referenced by UDP_SocketServer::ListenThread(), and UDP_SocketClient::ListenThread().
|
|
|
Definition at line 38 of file UDP_Socket.hpp. Referenced by UDP_SocketClient::ListenThread().
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001