1 #ifndef __JSYSTEM__JNETWORK__
2 #define __JSYSTEM__JNETWORK__
19 namespace JPP {
using namespace JSYSTEM; }
32 class JCompareEndian {
38 endian(ntohs(0x1234) == 0x1234)
47 bool operator()()
const
77 const size_t MAXIMUM_LENGTH = 256;
78 char buffer[MAXIMUM_LENGTH];
80 if (gethostname(buffer, MAXIMUM_LENGTH) == 0)
81 return std::string(buffer);
100 hostent* p = gethostbyaddr(&buffer,
sizeof(in_addr), AF_INET);
103 return std::string(p->h_name);
119 std::string buffer = host_name;
121 if (buffer ==
"" || buffer ==
"localhost")
124 const hostent* hp = gethostbyname(buffer.c_str());
127 memcpy((
char *) &ip, hp->h_addr,
sizeof(
int));
152 std::ostringstream os;
155 os << ((ip >> 24) & 0xFF) <<
'.'
156 << ((ip >> 16) & 0xFF) <<
'.'
157 << ((ip >> 8) & 0xFF) <<
'.'
158 << ((ip >> 0) & 0xFF);
160 os << ((ip >> 0) & 0xFF) <<
'.'
161 << ((ip >> 8) & 0xFF) <<
'.'
162 << ((ip >> 16) & 0xFF) <<
'.'
163 << ((ip >> 24) & 0xFF);
188 if (ntohs(0x1234) == 0x1234)
189 return (
unsigned short) (ip & 0x0000FFFF);
191 return (
unsigned short) (((ip & 0xFF000000) >> 24) |
192 ((ip & 0x00FF0000) >> 8) );
int getIPnumber(const std::string &host_name)
Get IP number.
std::string getIPaddress(const int ip)
Get IP address (decimal-dot notation).
unsigned short getSubaddress(const int ip)
Get host identifier within network.
static const JCompareEndian compareEndian
Function object operator.
std::string getHostname()
Get host name.
Exception for system call.