[Pkg-privacy-commits] [onioncat] 108/340: introduced struct sockaddr_str and inet_ntops()
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:04:29 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch debian
in repository onioncat.
commit 3c289d87edac0167df7bf91a7c0ce8186d79ce85
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date: Sun Jan 4 21:41:56 2009 +0000
introduced struct sockaddr_str and inet_ntops()
git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@417 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
src/ocat.h | 8 ++++++++
src/ocatsetup.c | 62 ++++++++++++--------------------------------------------
src/ocatv6conv.c | 33 ++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 49 deletions(-)
diff --git a/src/ocat.h b/src/ocat.h
index 6b2289a..a7a12ae 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -374,6 +374,13 @@ typedef struct ndp6
//struct nd_opt_hdr ndp_opt;
} __attribute__((packed)) ndp6_t;
+struct sockaddr_str
+{
+ sa_family_t sstr_family;
+ uint16_t sstr_port;
+ char sstr_addr[INET6_ADDRSTRLEN];
+};
+
/*
// next header value for ocat internal use (RFC3692)
#define OCAT_NEXT_HEADER 254
@@ -452,6 +459,7 @@ int oniontipv6(const char *, struct in6_addr *);
int oniontipv4(const char *, struct in_addr *, int);
int has_tor_prefix(const struct in6_addr *);
void rand_onion(char *);
+const char *inet_ntops(const struct sockaddr *, struct sockaddr_str *);
/*
#define IN6_HAS_TOR_PREFIX(a) ((((__const uint32_t *) (a))[0] == ((__const uint32_t*)(TOR_PREFIX))[0]) \
&& (((__const uint16_t*)(a))[2] == ((__const uint16_t*)(TOR_PREFIX))[2]))
diff --git a/src/ocatsetup.c b/src/ocatsetup.c
index c0cb6b5..3f36553 100644
--- a/src/ocatsetup.c
+++ b/src/ocatsetup.c
@@ -100,8 +100,9 @@ void init_setup(void)
void print_setup_struct(FILE *f)
{
- char ip[SBUF], nm[SBUF], ip6[SBUF], logf[SBUF], hw[SBUF], rp[SBUF], sk[SBUF];
+ char *c, ip[SBUF], nm[SBUF], ip6[SBUF], logf[SBUF], hw[SBUF], rp[SBUF];
int i, t;
+ struct sockaddr_str sas;
inet_ntop(AF_INET, &setup_.ocat_addr4, ip, SBUF);
inet_ntop(AF_INET, &setup_.ocat_addr4_mask, nm, SBUF);
@@ -180,58 +181,21 @@ void print_setup_struct(FILE *f)
for (i = 0; i < ROOT_PEERS; i++)
if (inet_ntop(AF_INET6, &setup_.root_peer[i], rp, SBUF))
- fprintf(f, "root_peer[%d] = %s\n", i, rp);
+ fprintf(f, "root_peer[%d] = %s\n", i, rp);
- if (setup_.socks_dst->sin_family == AF_INET)
+ if (inet_ntops((struct sockaddr*) setup_.socks_dst, &sas))
{
- inet_ntop(setup_.socks_dst->sin_family, &setup_.socks_dst->sin_addr, sk, SBUF);
+ c = sas.sstr_family == AF_INET6 ? "6" : "";
fprintf(f,
- "socks_dst.sin_family = %04x\n"
- "socks_dst.sin_port = %d\n"
- "socks_dst.sin_addr = %s\n",
- setup_.socks_dst->sin_family,
- ntohs(setup_.socks_dst->sin_port),
- sk
- );
+ "socks_dst%s.sin_family = 0x%04x\n"
+ "socks_dst%s.sin_port = %d\n"
+ "socks_dst%s.sin_addr = %s\n",
+ c, sas.sstr_family,
+ c, ntohs(sas.sstr_port),
+ c, sas.sstr_addr);
}
else
- {
- inet_ntop(setup_.socks_dst6->sin6_family, &setup_.socks_dst6->sin6_addr, sk, SBUF);
- fprintf(f,
- "socks_dst6.sin6_family = %04x\n"
- "socks_dst6.sin6_port = %d\n"
- "socks_dst6.sin6_addr = %s\n",
- setup_.socks_dst6->sin6_family,
- ntohs(setup_.socks_dst6->sin6_port),
- sk
- );
- }
-
- /*
- if (setup_.oc_listen->sin_family == AF_INET)
- {
- inet_ntop(setup_.oc_listen->sin_family, &setup_.oc_listen->sin_addr, sk, SBUF);
- fprintf(f,
- "socks_dst.sin_family = %04x\n"
- "socks_dst.sin_port = %d\n"
- "socks_dst.sin_addr = %s\n",
- setup_.oc_listen->sin_family,
- ntohs(setup_.oc_listen->sin_port),
- sk
- );
- }
- else
- {
- inet_ntop(setup_.oc_listen6->sin6_family, &setup_.oc_listen6->sin6_addr, sk, SBUF);
- fprintf(f,
- "oc_listen6.sin6_family = %04x\n"
- "oc_listen6.sin6_port = %d\n"
- "oc_listen6.sin6_addr = %s\n",
- setup_.oc_listen6->sin6_family,
- ntohs(setup_.oc_listen6->sin6_port),
- sk
- );
- }
- */
+ log_msg(LOG_WARNING, "could not convert struct sockaddr: \"%s\"", strerror(errno));
+
}
diff --git a/src/ocatv6conv.c b/src/ocatv6conv.c
index 2b37410..3bb2d0d 100644
--- a/src/ocatv6conv.c
+++ b/src/ocatv6conv.c
@@ -135,3 +135,36 @@ void rand_onion(char *onion)
*onion = '\0';
}
+
+/*! Convert struct sockaddr to stuct sockaddr_str which holds the address
+ * in string representation.
+ * @param saddr Const pointer to source of type struct sockaddr-
+ * @param sas Pointer to destination of type struct sockaddr_str.
+ * @return Pointer to string (sas->sstr_addr) or NULL on error. In the
+ * latter case errno will be set correctly.
+ */
+const char *inet_ntops(const struct sockaddr *saddr, struct sockaddr_str *sas)
+{
+ char *src;
+
+ switch (saddr->sa_family)
+ {
+ case AF_INET:
+ src = (char*) &((struct sockaddr_in*) saddr)->sin_addr;
+ sas->sstr_port = ((struct sockaddr_in*) saddr)->sin_port;
+ break;
+
+ case AF_INET6:
+ src = (char*) &((struct sockaddr_in6*) saddr)->sin6_addr;
+ sas->sstr_port = ((struct sockaddr_in6*) saddr)->sin6_port;
+ break;
+
+ default:
+ errno = EAFNOSUPPORT;
+ return NULL;
+ }
+
+ sas->sstr_family = saddr->sa_family;
+ return inet_ntop(saddr->sa_family, src, sas->sstr_addr, sizeof(sas->sstr_addr));
+}
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onioncat.git
More information about the Pkg-privacy-commits
mailing list