summaryrefslogtreecommitdiff
path: root/uclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'uclient.c')
-rw-r--r--uclient.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/uclient.c b/uclient.c
index 82553a5..bcb7357 100644
--- a/uclient.c
+++ b/uclient.c
@@ -15,11 +15,38 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <arpa/inet.h>
#include <libubox/ustream-ssl.h>
#include "uclient.h"
#include "uclient-utils.h"
#include "uclient-backend.h"
+char *uclient_get_addr(char *dest, int *port, union uclient_addr *a)
+{
+ int portval;
+ void *ptr;
+
+ switch(a->sa.sa_family) {
+ case AF_INET:
+ ptr = &a->sin.sin_addr;
+ portval = a->sin.sin_port;
+ break;
+ case AF_INET6:
+ ptr = &a->sin6.sin6_addr;
+ portval = a->sin6.sin6_port;
+ break;
+ default:
+ return strcpy(dest, "Unknown");
+ }
+
+ inet_ntop(a->sa.sa_family, ptr, dest, INET6_ADDRSTRLEN);
+ if (port)
+ *port = ntohs(portval);
+
+ return dest;
+}
+
+
struct uclient_url __hidden *
uclient_get_url(const char *url_str, const char *auth_str)
{