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 |
|
|
6 |
– |
socket = new iosockinet(sockbuf::sock_stream); |
33 |
|
// create a pointer to the object |
34 |
< |
|
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 |
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 |
|
|
60 |
|
string SubNet::sendTCP(string text){ |
61 |
|
|
62 |
|
int size = 1024; |
63 |
< |
char buf[size]; |
63 |
> |
char buf[size]; |
64 |
|
|
65 |
|
(*socket) << text.c_str() << "\n" << flush; // |
66 |
|
|
67 |
< |
(*socket).getline (buf, size-1); |
67 |
> |
(*socket).getline(buf, size-1); |
68 |
|
|
69 |
|
return buf; |
70 |
|
|
72 |
|
|
73 |
|
|
74 |
|
void SubNet::sendUPDPacket( string host, int port, string message ){ |
75 |
< |
|
76 |
< |
/* |
46 |
< |
host = "raptor.ukc.ac.uk"; |
47 |
< |
port = 7776; |
48 |
< |
*/ |
49 |
< |
|
50 |
< |
int udpSize; |
51 |
< |
udpSize = 65536; // 8kb in bits (8192*8) |
52 |
< |
|
53 |
< |
udp = new osockinet(sockbuf::sock_dgram); |
54 |
< |
(*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); |
55 |
< |
|
56 |
< |
// int sndBufSize = (*udp)->sendbufsz(udpSize); |
57 |
< |
|
58 |
< |
(*udp)->connect (host.c_str(), port); |
59 |
< |
(*udp) << message.c_str() << flush << endl; |
75 |
> |
|
76 |
> |
int udpSize = sizeof(message.c_str()); |
77 |
|
|
78 |
< |
delete udp; |
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 |
|
|
67 |
– |
string SubNet::getIPfromHost(string hostname){ |
68 |
– |
return ""; |
69 |
– |
|
70 |
– |
} // getIPFromHost |
71 |
– |
|
72 |
– |
string SubNet::getHostName(){ |
73 |
– |
|
74 |
– |
string myHost = (*socket)->localhost(); |
75 |
– |
delete socket; |
76 |
– |
return myHost; |
77 |
– |
|
78 |
– |
|
79 |
– |
} // getHostName |
80 |
– |
|
81 |
– |
string SubNet::getHostIP(){ |
82 |
– |
return ""; |
83 |
– |
|
84 |
– |
} // getHostIP |