| 2 |
|
|
| 3 |
|
SubNet::~SubNet(){ |
| 4 |
|
|
| 5 |
+ |
// free up any allocated memory |
| 6 |
|
delete socket; |
| 7 |
|
delete udp; |
| 8 |
|
|
| 11 |
|
SubNet::SubNet(string host, int port){ |
| 12 |
|
// constructor |
| 13 |
|
|
| 13 |
– |
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 |
< |
int size = 8192; |
| 43 |
> |
int size = 1024; |
| 44 |
|
char buf[size]; |
| 45 |
|
|
| 46 |
|
(*socket) << text.c_str() << "\n" << flush; // |
| 47 |
|
|
| 48 |
< |
(*socket).getline (buf, size-1); |
| 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 |
< |
int udpSize; |
| 53 |
< |
udpSize = 8129; // 8kb in bits (8192*8) |
| 54 |
< |
|
| 55 |
< |
udp = new osockinet(sockbuf::sock_dgram); |
| 56 |
< |
(*udp)->setopt(sockbuf::so_sndbuf , &udpSize, sizeof(udpSize), sockbuf::sol_socket); |
| 57 |
< |
|
| 58 |
< |
(*udp)->connect (host.c_str(), port); |
| 59 |
< |
(*udp) << message.c_str() << flush; |
| 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 |
|
|
| 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 |