1 #ifndef __JSYSTEM__JNETWORK__
2 #define __JSYSTEM__JNETWORK__
21 namespace JPP {
using namespace JSYSTEM; }
34 class JCompareEndian {
40 endian(ntohs(0x1234) == 0x1234)
49 bool operator()()
const
79 const size_t MAXIMUM_LENGTH = 256;
80 char buffer[MAXIMUM_LENGTH];
82 if (gethostname(buffer, MAXIMUM_LENGTH) == 0)
83 return std::string(buffer);
102 hostent* p = gethostbyaddr(&buffer,
sizeof(in_addr), AF_INET);
105 return std::string(p->h_name);
121 std::string buffer = host_name;
123 if (buffer ==
"" || buffer ==
"localhost") {
127 const hostent* hp = gethostbyname(buffer.c_str());
130 memcpy((
char *) &ip, hp->h_addr,
sizeof(
int));
156 std::ostringstream os;
159 os << ((ip >> 24) & 0xFF) <<
'.'
160 << ((ip >> 16) & 0xFF) <<
'.'
161 << ((ip >> 8) & 0xFF) <<
'.'
162 << ((ip >> 0) & 0xFF);
164 os << ((ip >> 0) & 0xFF) <<
'.'
165 << ((ip >> 8) & 0xFF) <<
'.'
166 << ((ip >> 16) & 0xFF) <<
'.'
167 << ((ip >> 24) & 0xFF);
193 return (
unsigned short) (ip & 0x0000FFFF);
195 return (
unsigned short) (((ip & 0xFF000000) >> 24) |
196 ((ip & 0x00FF0000) >> 8) );
220 const size_t MAXIMUM_LENGTH = 256;
221 char buffer[MAXIMUM_LENGTH];
225 struct ifaddrs *p = NULL;
227 if (getifaddrs(&p) == 0) {
229 for ( ; p != NULL; p = p->ifa_next) {
231 if (p->ifa_addr != NULL) {
233 if (p->ifa_addr->sa_family == AF_INET ||
234 p->ifa_addr->sa_family == AF_INET6) {
236 if (getnameinfo( p->ifa_addr,
237 (p->ifa_addr->sa_family == AF_INET) ?
sizeof(
struct sockaddr_in) :
sizeof(
struct sockaddr_in6),
238 buffer, MAXIMUM_LENGTH,
239 NULL, 0, NI_NUMERICHOST) == 0) {
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.
std::vector< std::string > getListOfIPaddresses()
Get list of IP address (decimal-dot notation).
Exception for system call.