1 |
/* |
2 |
* i-scream central monitoring system |
3 |
* Copyright (C) 2000-2002 i-scream |
4 |
* |
5 |
* This program is free software; you can redistribute it and/or |
6 |
* modify it under the terms of the GNU General Public License |
7 |
* as published by the Free Software Foundation; either version 2 |
8 |
* of the License, or (at your option) any later version. |
9 |
* |
10 |
* This program is distributed in the hope that it will be useful, |
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
* GNU General Public License for more details. |
14 |
* |
15 |
* You should have received a copy of the GNU General Public License |
16 |
* along with this program; if not, write to the Free Software |
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
*/ |
19 |
|
20 |
#include "SubNet.h" |
21 |
|
22 |
SubNet::~SubNet(){ |
23 |
|
24 |
// free up any allocated memory |
25 |
delete socket; |
26 |
delete udp; |
27 |
|
28 |
} // ~SubNet |
29 |
|
30 |
SubNet::SubNet(string host, int port){ |
31 |
// constructor |
32 |
|
33 |
// create a pointer to the object |
34 |
socket = new iosockinet(sockbuf::sock_stream); |
35 |
|
36 |
// make the actual connection |
37 |
connect = (*socket).rdbuf()->connect(host.c_str(), port); |
38 |
|
39 |
} // SubNet |
40 |
|
41 |
int SubNet::isConnected(){ |
42 |
|
43 |
return connect; |
44 |
|
45 |
} // isConnected |
46 |
|
47 |
|
48 |
SubNet::SubNet(){ |
49 |
// no arg constructor |
50 |
|
51 |
// connect to any socket on the local machine with the |
52 |
// intention of getting sys information |
53 |
socket = new iosockinet(sockbuf::sock_stream); |
54 |
(*socket).rdbuf()->bind(); |
55 |
|
56 |
return; |
57 |
|
58 |
} // SubNet |
59 |
|
60 |
string SubNet::sendTCP(string text){ |
61 |
|
62 |
int size = 1024; |
63 |
char buf[size]; |
64 |
|
65 |
(*socket) << text.c_str() << "\n" << flush; // |
66 |
|
67 |
(*socket).getline(buf, size-1); |
68 |
|
69 |
return buf; |
70 |
|
71 |
} // sendTCP |
72 |
|
73 |
|
74 |
void SubNet::sendUPDPacket( string host, int port, string message ){ |
75 |
|
76 |
int udpSize = sizeof(message.c_str()); |
77 |
|
78 |
udp = new osockinet(sockbuf::sock_dgram); |
79 |
(*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); |
80 |
|
81 |
(*udp)->connect (host.c_str(), port); |
82 |
(*udp) << message.c_str() << flush; |
83 |
|
84 |
delete udp; |
85 |
|
86 |
return; |
87 |
|
88 |
} // sendUPDPacket |
89 |
|