Implement the copy constructor for the Address structure.
[swifty.git] / src / libswift / swift.h
index dfe85f1..288238a 100644 (file)
@@ -103,10 +103,16 @@ namespace swift {
        //{    inet_aton(ipv4_str,&(addr.sin_addr));    }
        void clear () {
                addr = (struct sockaddr_mptp *)calloc(1, sizeof(struct sockaddr_mptp) + sizeof(struct mptp_dest));
+               addr->count = 1;
        }
        Address() {
            clear();
        }
+       Address(const Address &b) {
+           clear();
+               addr->dests[0].addr = b.addr->dests[0].addr;
+               addr->dests[0].port = b.addr->dests[0].port;
+       }
        Address(const char* ip, uint16_t port)  {
            clear();
            set_ipv4(ip);
@@ -124,6 +130,7 @@ namespace swift {
            set_port(port);
        }
        Address(const struct sockaddr_in& address) {
+               clear();
                addr->dests[0].addr = address.sin_addr.s_addr;
                addr->dests[0].port = address.sin_port;
        }
@@ -132,6 +139,15 @@ namespace swift {
        }
        uint32_t ipv4 () const { return ntohl(addr->dests[0].addr); }
        uint16_t port () const { return ntohs(addr->dests[0].port); }
+       Address& operator = (const Address& b) {
+               if (this != &b) {
+                       free(addr);
+                       clear();
+                       addr->dests[0].addr = b.addr->dests[0].addr;
+                       addr->dests[0].port = b.addr->dests[0].port;
+               }
+               return *this;
+       }
        bool operator == (const Address& b) const {
            return addr->count == b.addr->count &&
                addr->dests[0].port==b.addr->dests[0].port &&