00001 /** 00002 Licensed to the Apache Software Foundation (ASF) under one 00003 or more contributor license agreements. See the NOTICE file 00004 distributed with this work for additional information 00005 regarding copyright ownership. The ASF licenses this file 00006 to you under the Apache License, Version 2.0 (the 00007 "License"); you may not use this file except in compliance 00008 with the License. You may obtain a copy of the License at 00009 00010 http://www.apache.org/licenses/LICENSE-2.0 00011 00012 Unless required by applicable law or agreed to in writing, software 00013 distributed under the License is distributed on an "AS IS" BASIS, 00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 See the License for the specific language governing permissions and 00016 limitations under the License. 00017 */ 00018 00019 /** 00020 * @file utils.h 00021 * @brief Contains utility functions available to users of the api. 00022 * 00023 */ 00024 00025 #pragma once 00026 #ifndef ATSCPPAPI_UTILS_H_ 00027 #define ATSCPPAPI_UTILS_H_ 00028 00029 #include <string> 00030 #include <netinet/in.h> 00031 #include <arpa/inet.h> 00032 #include <stdint.h> 00033 00034 #ifndef ATSCPPAPI_UNUSED 00035 #ifdef __GNUC__ 00036 #define ATSCPPAPI_UNUSED __attribute__ ((unused)) 00037 #else 00038 #define ATSCPPAPI_UNUSED 00039 #endif 00040 #endif 00041 00042 namespace atscppapi { 00043 namespace utils { 00044 00045 /** 00046 * @brief Returns a pretty printed string of a sockaddr * 00047 * 00048 * @param sockaddr* A pointer to a sockaddr * 00049 * @return a string which is the pretty printed address 00050 */ 00051 std::string getIpString(const sockaddr *); 00052 00053 /** 00054 * @brief Returns just the port portion of the sockaddr * 00055 * 00056 * @param sockaddr* A pointer to a sockaddr * 00057 * @return a uint16_t which is the port from the sockaddr * 00058 */ 00059 uint16_t getPort(const sockaddr *); 00060 00061 /** 00062 * @brief Returns a pretty printed string of a sockaddr * including port 00063 * 00064 * @param sockaddr* A pointer to a sockaddr * 00065 * @return a string which is the pretty printed address including port 00066 */ 00067 std::string getIpPortString(const sockaddr *); 00068 00069 } 00070 } 00071 00072 #endif /* ATSCPPAPI_UTILS_H_ */