X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fio%2Fraw_socket.cxx;h=d93d971653e15a8904d777f2bc1b7f5e3d1a27a1;hb=201cb61f842ef50a19438e3872ba22e588fa1afc;hp=cf7b20f7bf873b869ace2287e9093c3dc68c19cb;hpb=ed7f2df04e6d30cd654d816257049fa506d97f0b;p=simgear.git diff --git a/simgear/io/raw_socket.cxx b/simgear/io/raw_socket.cxx index cf7b20f7..d93d9716 100644 --- a/simgear/io/raw_socket.cxx +++ b/simgear/io/raw_socket.cxx @@ -17,7 +17,7 @@ You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H @@ -63,6 +63,8 @@ #include #include +using std::string; + namespace { class Resolver : public SGThread @@ -311,6 +313,10 @@ bool IPAddress::lookupNonblocking(const char* host, IPAddress& addr) const char* IPAddress::getHost () const { + if (!addr) { + return NULL; + } + static char buf [32]; long x = ntohl(addr->sin_addr.s_addr); sprintf(buf, "%d.%d.%d.%d", @@ -321,21 +327,37 @@ const char* IPAddress::getHost () const unsigned int IPAddress::getIP () const { + if (!addr) { + return 0; + } + return addr->sin_addr.s_addr; } unsigned int IPAddress::getPort() const { + if (!addr) { + return 0; + } + return ntohs(addr->sin_port); } void IPAddress::setPort(int port) { + if (!addr) { + return; + } + addr->sin_port = htons(port); } unsigned int IPAddress::getFamily () const { + if (!addr) { + return 0; + } + return addr->sin_family; } @@ -363,7 +385,11 @@ const char* IPAddress::getLocalHost () bool IPAddress::getBroadcast () const { - return (addr->sin_addr.s_addr == INADDR_BROADCAST); + if (!addr) { + return false; + } + + return (addr->sin_addr.s_addr == INADDR_BROADCAST); } unsigned int IPAddress::getAddrLen() const @@ -381,6 +407,11 @@ struct sockaddr* IPAddress::getAddr() const return (struct sockaddr*) addr; } +bool IPAddress::isValid() const +{ + return (addr != NULL); +} + Socket::Socket () { handle = -1 ;