#include <UnixSocketSender.hpp>
Public Methods | |
| UnixSocketSender (char *SendMsg_Host, short SendMsg_Port) | |
| ~UnixSocketSender () | |
| bool | SendMsg (char *msg, size_t msgLen) |
| void | setSocket (int fdSocketNo) |
Private Methods | |
| void | getHostData (char *SendMsg_Host) |
Private Attributes | |
| int | ListenSocket |
| hostent * | hostdata |
| sockaddr_in | dest |
|
||||||||||||
|
Definition at line 3 of file UnixSocketSender.cpp. 00005 {
00006 ListenSocket = INVALID_SOCKET;
00007
00008 memset( &dest, 0, sizeof( struct sockaddr_in ) );
00009
00010 getHostData( SendMsg_Host );
00011
00012 dest.sin_family = PF_INET;
00013 dest.sin_addr = *(in_addr*)( hostdata->h_addr_list[0] );
00014 dest.sin_port = htons( SendMsg_Port );
00015 }
|
|
|
Definition at line 30 of file UnixSocketSender.cpp. 00030 { }
|
|
||||||||||||
|
Definition at line 36 of file UnixSocketSender.cpp. Referenced by main().
00037 {
00038 signed int Sent;
00039
00040 printf( "Message being sent to host %s port %i\n",
00041 inet_ntoa( dest.sin_addr ),
00042 ntohs( dest.sin_port )
00043 );
00044
00045 Sent = sendto( ListenSocket, Msg, msgLen, 0,
00046 (struct sockaddr *)&dest,
00047 sizeof( struct sockaddr_in )
00048 );
00049
00050 if ( Sent != msgLen )
00051 {
00052 printf("Error sending UDP packet from listen socket\n");
00053 fflush(0);
00054 return false;
00055 }
00056
00057 return true;
00058 }
|
|
|
Definition at line 60 of file UnixSocketSender.cpp. Referenced by UnixSocketSender().
00061 {
00062 if ( atoi( SendMsg_Host) ) // Host is given by IPv4 format "x.x.x.x"
00063 {
00064 ULONG ip = inet_addr( SendMsg_Host );
00065 hostdata = gethostbyaddr( (char*)&ip, sizeof(ip), PF_INET );
00066
00067 } else { // Host is given by name format "server.host.ca"
00068
00069 hostdata = gethostbyname( SendMsg_Host );
00070 }
00071
00072 if ( hostdata == NULL )
00073 {
00074 printf( "Error getting host address\n" );
00075 fflush( 0 );
00076 exit( 1 );
00077 }
00078 }
|
|
|
Definition at line 32 of file UnixSocketSender.cpp. Referenced by main().
00032 {
00033 ListenSocket = fdSocketNo;
00034 }
|
|
|
Definition at line 23 of file UnixSocketSender.hpp. |
|
|
Definition at line 25 of file UnixSocketSender.hpp. |
|
|
Definition at line 24 of file UnixSocketSender.hpp. |
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001