1 |
|
#include "SubNet.h" |
2 |
|
|
3 |
+ |
SubNet::~SubNet(){ |
4 |
+ |
|
5 |
+ |
// free up any allocated memory |
6 |
+ |
delete socket; |
7 |
+ |
delete udp; |
8 |
+ |
|
9 |
+ |
} // ~SubNet |
10 |
+ |
|
11 |
|
SubNet::SubNet(string host, int port){ |
12 |
|
// constructor |
13 |
|
|
6 |
– |
socket = new iosockinet(sockbuf::sock_stream); |
14 |
|
// create a pointer to the object |
15 |
< |
|
15 |
> |
socket = new iosockinet(sockbuf::sock_stream); |
16 |
> |
|
17 |
> |
// make the actual connection |
18 |
|
connect = (*socket).rdbuf()->connect(host.c_str(), port); |
19 |
|
|
20 |
|
} // SubNet |
27 |
|
|
28 |
|
|
29 |
|
SubNet::SubNet(){ |
30 |
+ |
// no arg constructor |
31 |
|
|
32 |
+ |
// connect to any socket on the local machine with the |
33 |
+ |
// intention of getting sys information |
34 |
|
socket = new iosockinet(sockbuf::sock_stream); |
35 |
|
(*socket).rdbuf()->bind(); |
36 |
|
|
40 |
|
|
41 |
|
string SubNet::sendTCP(string text){ |
42 |
|
|
43 |
< |
char buf[1024]; |
43 |
> |
int size = 1024; |
44 |
> |
char buf[size]; |
45 |
|
|
46 |
|
(*socket) << text.c_str() << "\n" << flush; // |
47 |
|
|
48 |
< |
(*socket).getline (buf, 1024); |
48 |
> |
(*socket).getline(buf, size-1); |
49 |
|
|
50 |
|
return buf; |
51 |
|
|
53 |
|
|
54 |
|
|
55 |
|
void SubNet::sendUPDPacket( string host, int port, string message ){ |
56 |
< |
|
57 |
< |
/* |
45 |
< |
host = "raptor.ukc.ac.uk"; |
46 |
< |
port = 7776; |
47 |
< |
*/ |
48 |
< |
|
49 |
< |
int udpSize; |
50 |
< |
udpSize = 65536; // 8kb in bits (8192*8) |
51 |
< |
|
52 |
< |
udp = new osockinet(sockbuf::sock_dgram); |
53 |
< |
(*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); |
54 |
< |
|
55 |
< |
// int sndBufSize = (*udp)->sendbufsz(udpSize); |
56 |
< |
|
57 |
< |
(*udp)->connect (host.c_str(), port); |
58 |
< |
(*udp) << message.c_str() << endl; |
56 |
> |
|
57 |
> |
int udpSize = sizeof(message.c_str()); |
58 |
|
|
59 |
< |
delete udp; |
59 |
> |
udp = new osockinet(sockbuf::sock_dgram); |
60 |
> |
(*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); |
61 |
> |
|
62 |
> |
(*udp)->connect (host.c_str(), port); |
63 |
> |
(*udp) << message.c_str() << flush; |
64 |
> |
|
65 |
> |
delete udp; |
66 |
|
|
67 |
|
return; |
68 |
|
|
69 |
|
} // sendUPDPacket |
70 |
|
|
66 |
– |
string SubNet::getIPfromHost(string hostname){ |
67 |
– |
return ""; |
68 |
– |
|
69 |
– |
} // getIPFromHost |
70 |
– |
|
71 |
– |
string SubNet::getHostName(){ |
72 |
– |
|
73 |
– |
string myHost = (*socket)->localhost(); |
74 |
– |
delete socket; |
75 |
– |
return myHost; |
76 |
– |
|
77 |
– |
|
78 |
– |
} // getHostName |
79 |
– |
|
80 |
– |
string SubNet::getHostIP(){ |
81 |
– |
return ""; |
82 |
– |
|
83 |
– |
} // getHostIP |