diff --git a/src/cw/sock_addrtostr.c b/src/cw/sock_addrtostr.c
index f4972c43..5dbe6fda 100644
--- a/src/cw/sock_addrtostr.c
+++ b/src/cw/sock_addrtostr.c
@@ -1,7 +1,7 @@
/*
- This file is part of libcapwap.
+ This file is part of actube.
- libcapwap is free software: you can redistribute it and/or modify
+ actube is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
@@ -15,6 +15,17 @@
along with Foobar. If not, see .
*/
+
+/**
+ * @file
+ * @brief implements sock_addrtostr
+ */
+
+/**
+ * @addtogroup sock
+ * @{
+ */
+
#include
#include
@@ -32,40 +43,40 @@
#include "sock.h"
-/*
-void sock_hwaddrtostr(const uint8_t *haddr,int len,char *dst)
+/**
+ * Convert a struct sockaddr int to a human readable string.
+ * @param sa sockaddr to convert
+ * @param s Destination buffer
+ * @param maxlen Size of destination buffer
+ * @param addport If true then the port number wil be added to the output
+ * Works only for sockaddrs of type AF_INET, AF_INET6, AF_PACKET, AF_LINK.
+ */
+char *sock_addrtostr(const struct sockaddr *sa, char *s, size_t maxlen,int addport)
{
- int i;
- for (i=0; isa_family) {
case AF_INET:
- inet_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr), s, maxlen);
- port = ((struct sockaddr_in *)sa)->sin_port;
- if (addport)
- sprintf(s,"%s:%i",s,ntohs(port));
+ inet_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr), d, maxlen);
+ if (addport){
+ port = ((struct sockaddr_in *)sa)->sin_port;
+ sprintf(s,"%s:%i",d,ntohs(port));
+ }
else
- sprintf(s,"%s",s);
+ sprintf(s,"%s",d);
break;
case AF_INET6:
- inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sa)->sin6_addr), s, maxlen);
- break;
+ inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sa)->sin6_addr), d, maxlen);
+ if (addport){
+ port = ((struct sockaddr_in6 *)sa)->sin6_port;
+ sprintf(s,"[%s]:%i",d,ntohs(port));
+ }
+ else
+ sprintf(s,"%s",d);
+ break;
#ifdef AF_LINK
case AF_LINK:
{
@@ -99,3 +110,8 @@ char *sock_strsockaddr(const struct sockaddr *sa, char *s, size_t maxlen,int add
}
return s;
}
+
+/**
+ * @}
+ */
+