MOOS 0.2375
|
00001 00002 // 00003 // MOOS - Mission Oriented Operating Suite 00004 // 00005 // A suit of Applications and Libraries for Mobile Robotics Research 00006 // Copyright (C) 2001-2005 Massachusetts Institute of Technology and 00007 // Oxford University. 00008 // 00009 // This software was written by Paul Newman at MIT 2001-2002 and Oxford 00010 // University 2003-2005. email: pnewman@robots.ox.ac.uk. 00011 // 00012 // This file is part of a MOOS Core Component. 00013 // 00014 // This program is free software; you can redistribute it and/or 00015 // modify it under the terms of the GNU General Public License as 00016 // published by the Free Software Foundation; either version 2 of the 00017 // License, or (at your option) any later version. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 // General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00029 // The XPC classes in MOOS are modified versions of the source provided 00030 // in "Making UNIX and Windows NT Talk" by Mark Nadelson and Thomas Haga 00031 // 00033 #include "XPCGetHostInfo.h" 00034 00035 00036 XPCGetHostInfo::XPCGetHostInfo(const char *_sHost, hostType _type) 00037 { 00038 #ifdef UNIX 00039 cIteratorFlag = 0; 00040 #endif 00041 if (_type == NAME) 00042 { 00043 // Retrieve host by name 00044 hostPtr = gethostbyname(_sHost); 00045 if (hostPtr == NULL) 00046 { 00047 XPCException exceptObject("Error Getting Host By Name"); 00048 throw exceptObject; 00049 return; 00050 } 00051 } 00052 else if (_type == ADDRESS) 00053 { 00054 // Retrieve host by address 00055 // 00056 in_addr_t netAddr = inet_addr(_sHost); 00057 if (netAddr == INADDR_NONE) 00058 { 00059 XPCException exceptObject("Error Getting Host By Address"); 00060 throw exceptObject; 00061 return; 00062 } 00063 00064 hostPtr = gethostbyaddr((char *)&netAddr, sizeof(netAddr), AF_INET); 00065 if (hostPtr == NULL) 00066 { 00067 XPCException exceptObject("Error Getting Host By Address"); 00068 throw exceptObject; 00069 return; 00070 } 00071 } 00072 else 00073 { 00074 XPCException exceptObject("Parameter Error Constructing XPCGetHostInfo"); 00075 throw exceptObject; 00076 return; 00077 } 00078 } 00079 00080 XPCGetHostInfo::XPCGetHostInfo(in_addr_t *_netAddr) 00081 { 00082 if (*_netAddr == INADDR_NONE) 00083 { 00084 XPCException exceptObject("Error Getting Host By Address"); 00085 throw exceptObject; 00086 return; 00087 } 00088 00089 hostPtr = gethostbyaddr((char *)_netAddr, sizeof(*_netAddr), AF_INET); 00090 if (hostPtr == NULL) 00091 { 00092 XPCException exceptObject("Error Getting Host By Address"); 00093 throw exceptObject; 00094 return; 00095 } 00096 } 00097 00098 #ifdef UNIX 00099 char XPCGetHostInfo::cGetNextHost() 00100 { 00101 // Get the next host from the database 00102 if (cIteratorFlag == 1) 00103 { 00104 if ((hostPtr = gethostent()) == NULL) 00105 return 0; 00106 else 00107 return 1; 00108 } 00109 return 0; 00110 } 00111 #endif