X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=common-src%2Fsockaddr-util.c;h=ffbc32ecf18fc7b10fc1014b93631baa532f6418;hb=b116e9366c7b2ea2c2eb53b0a13df4090e176235;hp=e58ffb39a8b65cd4ac1cc01380604aa6b5fc2906;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e;p=debian%2Famanda diff --git a/common-src/sockaddr-util.c b/common-src/sockaddr-util.c index e58ffb3..ffbc32e 100644 --- a/common-src/sockaddr-util.c +++ b/common-src/sockaddr-util.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007,2008 Zmanda, Inc. All Rights Reserved. + * Copyright (c) 2007, 2008, 2010 Zmanda, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published @@ -23,6 +23,7 @@ * Utility routines for handling sockaddrs */ +#include "amanda.h" #include "sockaddr-util.h" void @@ -90,6 +91,28 @@ str_sockaddr( return mystr_sockaddr; } +int +str_to_sockaddr( + const char *src, + sockaddr_union *dst) +{ + int result; + + g_debug("parsing %s", src); + /* try AF_INET first */ + SU_INIT(dst, AF_INET); + if ((result = inet_pton(AF_INET, src, &dst->sin.sin_addr)) == 1) + return result; + + /* otherwise try AF_INET6, if supported */ +#ifdef WORKING_IPV6 + SU_INIT(dst, AF_INET6); + return inet_pton(AF_INET6, src, &dst->sin6.sin6_addr); +#else + return result; +#endif +} + /* Unmap a V4MAPPED IPv6 address into its equivalent IPv4 address. The location * TMP is used to store the rewritten address, if necessary. Returns a pointer * to the unmapped address.