+
+int sockaddr_get_port_net_order(const struct sockaddr *client_addr)
+{
+ if (client_addr->sa_family == AF_INET) {
+ return ((struct sockaddr_in *)client_addr)->sin_port;
+ }
+#ifdef HAVE_IPV6
+ else {
+ return ((struct sockaddr_in6 *)client_addr)->sin6_port;
+ }
+#endif
+ return -1;
+}
+
+int sockaddr_get_port(const struct sockaddr *client_addr)
+{
+ if (client_addr->sa_family == AF_INET) {
+ return ntohs(((struct sockaddr_in *)client_addr)->sin_port);
+ }
+#ifdef HAVE_IPV6
+ else {
+ return ntohs(((struct sockaddr_in6 *)client_addr)->sin6_port);
+ }
+#endif
+ return -1;
+}
+
+
+char *sockaddr_to_ascii(const struct sockaddr *sa, char *buf, int len)
+{
+#ifdef HAVE_INET_NTOP
+ /* MA Bug 5 the problem was that i mixed up sockaddr and in_addr */
+ inet_ntop(sa->sa_family,
+# ifdef HAVE_IPV6
+ sa->sa_family == AF_INET ?
+ (void*)&(((struct sockaddr_in*)sa)->sin_addr) :
+ (void*)&(((struct sockaddr_in6*)sa)->sin6_addr),
+# else
+ (void*)&(((struct sockaddr_in*)sa)->sin_addr),
+# endif /* HAVE_IPV6 */
+ buf, len);
+#else
+ bstrncpy(buf, inet_ntoa(((struct sockaddr_in *)sa)->sin_addr), len);
+#endif
+ return buf;
+}
+
+#ifdef HAVE_OLD_SOCKOPT
+int inet_aton(const char *cp, struct in_addr *inp)
+{
+ struct in_addr inaddr;
+
+ if((inaddr.s_addr = inet_addr(cp)) != INADDR_NONE) {
+ inp->s_addr = inaddr.s_addr;
+ return 1;
+ }
+ return 0;
+}
+#endif