From 2dc0670266e5dab449e776aed9bf3b9e373cdd1e Mon Sep 17 00:00:00 2001 From: wangyu- Date: Tue, 24 Jul 2018 05:55:59 -0500 Subject: [PATCH] added function from_addres_t() --- common.cpp | 17 +++++++++++++++++ common.h | 2 ++ main.cpp | 26 ++------------------------ 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/common.cpp b/common.cpp index 064740e..a22e8ac 100644 --- a/common.cpp +++ b/common.cpp @@ -299,6 +299,23 @@ char * my_ip_t::get_str2() const } return res; } + +int my_ip_t::from_address_t(address_t tmp_addr) +{ + if(tmp_addr.get_type()==raw_ip_version&&raw_ip_version==AF_INET) + { + v4=tmp_addr.inner.ipv4.sin_addr.s_addr; + } + else if(tmp_addr.get_type()==raw_ip_version&&raw_ip_version==AF_INET6) + { + v6=tmp_addr.inner.ipv6.sin6_addr; + } + else + { + assert(0==1); + } + return 0; +} /* int my_ip_t::from_str(char * str) { diff --git a/common.h b/common.h index 36978b3..13ef814 100644 --- a/common.h +++ b/common.h @@ -248,6 +248,8 @@ union my_ip_t //just a simple version of address_t,stores ip only char * get_str1() const; char * get_str2() const; + int from_address_t(address_t a); + }; struct not_copy_able_t diff --git a/main.cpp b/main.cpp index 80fed9e..3011f06 100755 --- a/main.cpp +++ b/main.cpp @@ -81,18 +81,7 @@ int client_on_timer(conn_info_t &conn_info) //for client. called when a timer is tmp_addr=source_addr; } - if(tmp_addr.get_type()==raw_ip_version&&raw_ip_version==AF_INET) - { - send_info.new_src_ip.v4=tmp_addr.inner.ipv4.sin_addr.s_addr; - } - else if(tmp_addr.get_type()==raw_ip_version&&raw_ip_version==AF_INET6) - { - send_info.new_src_ip.v6=tmp_addr.inner.ipv6.sin6_addr; - } - else - { - assert(0==1); - } + send_info.new_src_ip.from_address_t(tmp_addr); if (force_source_port == 0) { @@ -1390,18 +1379,7 @@ int client_event_loop() //init_filter(source_port); - if(remote_addr.get_type()==raw_ip_version&&raw_ip_version==AF_INET) - { - send_info.new_dst_ip.v4=remote_addr.inner.ipv4.sin_addr.s_addr; - } - else if(remote_addr.get_type()==raw_ip_version&&raw_ip_version==AF_INET6) - { - send_info.new_dst_ip.v6=remote_addr.inner.ipv6.sin6_addr; - } - else - { - assert(0==1); - } + send_info.new_dst_ip.from_address_t(remote_addr); send_info.dst_port=remote_addr.get_port();