equal
deleted
inserted
replaced
|
1 /* |
|
2 * $Id: PacketWriter.cpp 54 2008-01-10 00:24:52Z mbroeker $ |
|
3 * $URL: http://localhost/svn/cpp/qMonitor/trunk/PacketWriter.cpp $ |
|
4 */ |
|
5 |
|
6 #include <PacketWriter.h> |
|
7 |
|
8 extern "C" { |
|
9 #include <sys/socket.h> |
|
10 #include <netinet/in.h> |
|
11 #include <arpa/inet.h> |
|
12 #include <netdb.h> |
|
13 } PacketWriter::PacketWriter (char *hostname, int port) |
|
14 { |
|
15 unsigned int size; |
|
16 unsigned int fd; |
|
17 struct hostent *host = gethostbyname (hostname); |
|
18 |
|
19 if (host == NULL) { |
|
20 perror ("GETHOSTBYNAME"); |
|
21 exit (0); |
|
22 } |
|
23 |
|
24 ca.sin_family = PF_INET; |
|
25 ca.sin_addr = *((struct in_addr *)host->h_addr_list[0]); |
|
26 ca.sin_port = htons (port); |
|
27 |
|
28 size = sizeof (ca); |
|
29 fd = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); |
|
30 p_socket = connect (fd, (sockaddr *) & ca, size); |
|
31 } |
|
32 |
|
33 PacketWriter::~PacketWriter () |
|
34 { |
|
35 close (p_socket); |
|
36 } |
|
37 |
|
38 void PacketWriter::write (char s[], int len) |
|
39 { |
|
40 int c; |
|
41 |
|
42 c =::write (p_socket, s, len); |
|
43 } |
|
44 |
|
45 bool PacketWriter::ready () |
|
46 { |
|
47 return true; |
|
48 } |