/*
* $Id: PacketWriter.cpp 54 2008-01-10 00:24:52Z mbroeker $
* $URL: http://localhost/svn/cpp/qMonitor/trunk/PacketWriter.cpp $
*/
#include <PacketWriter.h>
#include <cstdlib>
extern "C" {
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
};
PacketWriter::PacketWriter (char *hostname, int port)
{
unsigned int size;
unsigned int fd;
struct hostent *host = gethostbyname (hostname);
if (host == NULL) {
perror ("GETHOSTBYNAME");
exit (0);
}
ca.sin_family = PF_INET;
ca.sin_addr = *((struct in_addr *)host->h_addr_list[0]);
ca.sin_port = htons (port);
size = sizeof (ca);
fd = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP);
p_socket = connect (fd, (sockaddr *) & ca, size);
}
PacketWriter::~PacketWriter ()
{
close (p_socket);
}
void PacketWriter::write (char s[], int len)
{
int c;
c =::write (p_socket, s, len);
}
bool PacketWriter::ready ()
{
return true;
}