From b7654c181dc8d52875365b170bc3092e8e51d68f Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Wed, 24 Aug 2011 02:30:02 -0700
Subject: [PATCH] Copy constructor and assignment operator for revised
 IPAddress

---
 simgear/io/raw_socket.cxx | 24 ++++++++++++++++++++++++
 simgear/io/raw_socket.hxx |  3 +++
 2 files changed, 27 insertions(+)

diff --git a/simgear/io/raw_socket.cxx b/simgear/io/raw_socket.cxx
index 8bcae985..7fe2c688 100644
--- a/simgear/io/raw_socket.cxx
+++ b/simgear/io/raw_socket.cxx
@@ -67,6 +67,30 @@ IPAddress::IPAddress ( const char* host, int port )
   set ( host, port ) ;
 }
 
+IPAddress::IPAddress( const IPAddress& other ) :
+  addr(NULL)
+{
+  if (other.addr) {
+    addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
+    memcpy(addr, other.addr, sizeof(struct sockaddr_in));
+  }
+}
+
+const IPAddress& IPAddress::operator=(const IPAddress& other)
+{
+  if (addr) {
+    free(addr);
+    addr = NULL;
+  }
+
+  if (other.addr) {
+    addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
+    memcpy(addr, other.addr, sizeof(struct sockaddr_in));
+  }
+
+  return *this;
+}
+
 void IPAddress::set ( const char* host, int port )
 {
   addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
diff --git a/simgear/io/raw_socket.hxx b/simgear/io/raw_socket.hxx
index 6ae529f2..2b5031f3 100644
--- a/simgear/io/raw_socket.hxx
+++ b/simgear/io/raw_socket.hxx
@@ -46,6 +46,9 @@ public:
   IPAddress ( const char* host, int port ) ;
   ~IPAddress();
   
+  IPAddress( const IPAddress& other );
+  const IPAddress& operator=(const IPAddress& other);
+
   void set ( const char* host, int port ) ;
   const char* getHost () const ;
   unsigned int getPort() const ;
-- 
2.39.5