00001 /** @file 00002 00003 A brief file description 00004 00005 @section license License 00006 00007 Licensed to the Apache Software Foundation (ASF) under one 00008 or more contributor license agreements. See the NOTICE file 00009 distributed with this work for additional information 00010 regarding copyright ownership. The ASF licenses this file 00011 to you under the Apache License, Version 2.0 (the 00012 "License"); you may not use this file except in compliance 00013 with the License. You may obtain a copy of the License at 00014 00015 http://www.apache.org/licenses/LICENSE-2.0 00016 00017 Unless required by applicable law or agreed to in writing, software 00018 distributed under the License is distributed on an "AS IS" BASIS, 00019 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 See the License for the specific language governing permissions and 00021 limitations under the License. 00022 */ 00023 00024 #include "I_NetVConnection.h" 00025 00026 TS_INLINE sockaddr const* 00027 NetVConnection::get_remote_addr() 00028 { 00029 if (!got_remote_addr) { 00030 set_remote_addr(); 00031 got_remote_addr = true; 00032 } 00033 return &remote_addr.sa; 00034 } 00035 00036 TS_INLINE in_addr_t 00037 NetVConnection::get_remote_ip() 00038 { 00039 sockaddr const* addr = this->get_remote_addr(); 00040 return ats_is_ip4(addr) 00041 ? ats_ip4_addr_cast(addr) 00042 : 0; 00043 } 00044 00045 00046 /// @return The remote port in host order. 00047 TS_INLINE uint16_t 00048 NetVConnection::get_remote_port() 00049 { 00050 return ats_ip_port_host_order(this->get_remote_addr()); 00051 } 00052 00053 TS_INLINE sockaddr const* 00054 NetVConnection::get_local_addr() 00055 { 00056 if (!got_local_addr) { 00057 set_local_addr(); 00058 if ( 00059 (ats_is_ip(&local_addr) && ats_ip_port_cast(&local_addr)) // IP and has a port. 00060 || (ats_is_ip4(&local_addr) && INADDR_ANY != ats_ip4_addr_cast(&local_addr)) // IPv4 00061 || (ats_is_ip6(&local_addr) && !IN6_IS_ADDR_UNSPECIFIED(&local_addr.sin6.sin6_addr)) 00062 ) { 00063 got_local_addr = 1; 00064 } 00065 } 00066 return &local_addr.sa; 00067 } 00068 00069 TS_INLINE in_addr_t 00070 NetVConnection::get_local_ip() 00071 { 00072 sockaddr const* addr = this->get_local_addr(); 00073 return ats_is_ip4(addr) 00074 ? ats_ip4_addr_cast(addr) 00075 : 0; 00076 } 00077 00078 /// @return The local port in host order. 00079 TS_INLINE uint16_t 00080 NetVConnection::get_local_port() 00081 { 00082 return ats_ip_port_host_order(this->get_local_addr()); 00083 }