Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

UnixSocketSender Class Reference

#include <UnixSocketSender.hpp>

List of all members.

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


Constructor & Destructor Documentation

UnixSocketSender::UnixSocketSender char *    SendMsg_Host,
short    SendMsg_Port
 

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 }

UnixSocketSender::~UnixSocketSender  
 

Definition at line 30 of file UnixSocketSender.cpp.

00030 { }


Member Function Documentation

bool UnixSocketSender::SendMsg char *    Msg,
size_t    msgLen
 

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 }

void UnixSocketSender::getHostData char *    SendMsg_Host [private]
 

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 }

void UnixSocketSender::setSocket int    fdSocketNo [inline]
 

Definition at line 32 of file UnixSocketSender.cpp.

Referenced by main().

00032                                                            {
00033   ListenSocket = fdSocketNo;  
00034 }


Member Data Documentation

int UnixSocketSender::ListenSocket [private]
 

Definition at line 23 of file UnixSocketSender.hpp.

struct sockaddr_in UnixSocketSender::dest [private]
 

Definition at line 25 of file UnixSocketSender.hpp.

hostent* UnixSocketSender::hostdata [private]
 

Definition at line 24 of file UnixSocketSender.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:50:23 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001