diff options
author | Felix Fietkau <nbd@openwrt.org> | 2014-04-07 21:11:58 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2014-04-07 21:11:58 +0200 |
commit | cb7867a867e45949950e03de0ea845e483ffc6eb (patch) | |
tree | f3c3987753d5cd6b53d023144fcf3f2a19b7a166 /uclient.c | |
parent | 316bcc8c62e195a892813b050a922ebd3935eba2 (diff) | |
download | uclient-cb7867a867e45949950e03de0ea845e483ffc6eb.tar.gz |
add support for querying local/remote address
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'uclient.c')
-rw-r--r-- | uclient.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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) { |