[Pkg-privacy-commits] [onioncat] 99/340: replaced ether_ntoa by ether_ntoa_r added some comments

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 d7fd046a5dec6054637d25b9afde49a2355636de
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date:   Fri Dec 12 14:16:07 2008 +0000

    replaced ether_ntoa by ether_ntoa_r
    added some comments
    
    
    git-svn-id: http://www.cypherpunk.at/svn/onioncat/trunk@392 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
 config.h.in     |  3 +++
 configure       |  3 ++-
 configure.ac    |  2 +-
 src/ocat.c      |  4 ++--
 src/ocat.h      |  3 +++
 src/ocateth.c   | 27 +++++++++++++++++++++++----
 src/ocatlog.c   | 23 +++++++++++++++++++++++
 src/ocatsetup.c |  6 ++++--
 8 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/config.h.in b/config.h.in
index e681ab5..a1b8bd2 100644
--- a/config.h.in
+++ b/config.h.in
@@ -12,6 +12,9 @@
 /* Define to 1 if you have the <endian.h> header file. */
 #undef HAVE_ENDIAN_H
 
+/* Define to 1 if you have the `ether_ntoa_r' function. */
+#undef HAVE_ETHER_NTOA_R
+
 /* Define to 1 if you have the `pthread' library (-lpthread). */
 #undef HAVE_LIBPTHREAD
 
diff --git a/configure b/configure
index 9185f94..19a7447 100755
--- a/configure
+++ b/configure
@@ -3952,7 +3952,8 @@ fi
 #AC_CHECK_FUNCS([clock_gettime memset select socket strchr strerror])
 
 
-for ac_func in strlcat strlcpy
+
+for ac_func in strlcat strlcpy ether_ntoa_r
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 { echo "$as_me:$LINENO: checking for $ac_func" >&5
diff --git a/configure.ac b/configure.ac
index 3b49da1..9c12d25 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,7 +116,7 @@ AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
 #AC_FUNC_STRFTIME
 #AC_FUNC_VPRINTF
 #AC_CHECK_FUNCS([clock_gettime memset select socket strchr strerror])
-AC_CHECK_FUNCS([strlcat strlcpy])
+AC_CHECK_FUNCS([strlcat strlcpy ether_ntoa_r])
 
 AC_CONFIG_FILES([Makefile src/Makefile man/Makefile])
 AC_OUTPUT
diff --git a/src/ocat.c b/src/ocat.c
index 6809791..f30dfb1 100644
--- a/src/ocat.c
+++ b/src/ocat.c
@@ -120,7 +120,7 @@ void background(void)
 
 int main(int argc, char *argv[])
 {
-   char tunname[IFNAMSIZ] = {0}, *s, ip6addr[INET6_ADDRSTRLEN];
+   char tunname[IFNAMSIZ] = {0}, *s, ip6addr[INET6_ADDRSTRLEN], hw[20];
    int c, runasroot = 0;
    struct passwd *pwd;
    int urlconv = 0;
@@ -265,7 +265,7 @@ int main(int argc, char *argv[])
 
    memcpy(&CNF(ocat_hwaddr[3]), &CNF(ocat_addr.s6_addr[13]), 3);
    if (CNF(use_tap));
-      log_msg(LOG_INFO, "MAC address %s", ether_ntoa((struct ether_addr*) CNF(ocat_hwaddr)));
+      log_msg(LOG_INFO, "MAC address %s", ether_ntoa_r((struct ether_addr*) CNF(ocat_hwaddr), hw));
 
 #ifndef WITHOUT_TUN
    // create TUN device
diff --git a/src/ocat.h b/src/ocat.h
index d8161df..0536aba 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -488,6 +488,9 @@ void print_mac_tbl(FILE *);
 void mac_cleanup(void);
 char *mac_hw2str(const uint8_t *, char *);
 int ndp_solicit(const struct in6_addr *, const struct in6_addr *);
+#ifndef HAVE_ETHER_NTOA_R
+char *ether_ntoa_r(const struct ether_addr *, char *);
+#endif
 
 /* ocatsocks.c */
 void socks_queue(const struct in6_addr *, int);
diff --git a/src/ocateth.c b/src/ocateth.c
index e8255f6..c2bd7be 100644
--- a/src/ocateth.c
+++ b/src/ocateth.c
@@ -51,7 +51,7 @@ void print_mac_tbl(FILE *f)
 
    for (i = 0; i < mac_cnt_; i++)
    {
-      fprintf(f, "%3d %3d %s ", i, (int) (time(NULL) - mac_tbl_[i].age), ether_ntoa((struct ether_addr*) mac_tbl_[i].hwaddr));
+      fprintf(f, "%3d %3d %s ", i, (int) (time(NULL) - mac_tbl_[i].age), ether_ntoa_r((struct ether_addr*) mac_tbl_[i].hwaddr, buf));
       fprintf(f, "%s ", mac_tbl_[i].family == AF_INET6 ? "IN6" : "IN ");
       inet_ntop(mac_tbl_[i].family, &mac_tbl_[i].in6addr, buf, INET6_ADDRSTRLEN);
       fprintf(f, "%s\n", buf);
@@ -66,13 +66,14 @@ void print_mac_tbl(FILE *f)
 void mac_cleanup(void)
 {
    int i;
+   char hw[20];
 
    pthread_mutex_lock(&mac_mutex_);
 
    for (i = 0; i < mac_cnt_; i++)
       if (mac_tbl_[i].age + MAX_MAC_AGE < time(NULL))
       {
-         log_debug("mac table entry %d (%s) timed out", i, ether_ntoa((struct ether_addr*) mac_tbl_[i].hwaddr));
+         log_debug("mac table entry %d (%s) timed out", i, ether_ntoa_r((struct ether_addr*) mac_tbl_[i].hwaddr, hw));
          memmove(&mac_tbl_[i], &mac_tbl_[i + 1], sizeof(MACTable_t) * (MAX_MAC_ENTRY - i));
          mac_cnt_--;
          i--;
@@ -293,14 +294,14 @@ int ndp_soladv(char *buf, int rlen)
    ndp6_t *ndp6 = (ndp6_t*) (buf + 4);
    struct nd_opt_hdr *ohd = (struct nd_opt_hdr*) (ndp6 + 1);
    uint16_t *ckb, cksum;
-   //char mb[100];
+   char hw[20];
 
    if (ndp6->eth.ether_dhost[0] & 1)
    {
       // check for right multicast destination on ethernet
       if (ndp6->eth.ether_dhost[2] != 0xff)
       {
-         log_debug("ethernet multicast destination %s cannot be solicited node address", ether_ntoa((struct ether_addr*) ndp6->eth.ether_dhost));
+         log_debug("ethernet multicast destination %s cannot be solicited node address", ether_ntoa_r((struct ether_addr*) ndp6->eth.ether_dhost, hw));
          return -1;
       }
 
@@ -453,3 +454,21 @@ int eth_check(char *buf, int len)
    return 0;
 }
 
+
+#ifndef HAVE_ETHER_NTOA_R
+
+static pthread_mutex_t ether_ntoa_mutex_ = PTHREAD_MUTEX_INITIALIZER;
+
+char *ether_ntoa_r(const struct ether_addr *addr, char *buf)
+{
+   if (!buf)
+      return NULL;
+
+   pthread_mutex_lock(&ether_ntoa_mutex_);
+   strlcpy(buf, 18, ether_ntoa(addr));
+   pthread_mutex_unlock(&ether_ntoa_mutex_);
+   return buf;
+}
+
+#endif
+
diff --git a/src/ocatlog.c b/src/ocatlog.c
index 0024a52..4a1178a 100644
--- a/src/ocatlog.c
+++ b/src/ocatlog.c
@@ -15,6 +15,11 @@
  * along with OnionCat. If not, see <http://www.gnu.org/licenses/>.
  */
 
+/*! @file
+ *  File contains logging functions.
+ *  @author Bernhard R. Fischer
+ *  @version 2008/10/1
+ */
 
 #include "ocat.h"
 
@@ -27,6 +32,12 @@ static const char *flty_[8] = {"emerg", "alert", "crit", "err", "warning", "noti
 static FILE *clog_ = NULL;
 
 
+/*! Open connect log.
+ *  The connect log contains logging entries regarding
+ *  incoming or outgoing connections.
+ *  @param dir Name of directory which should contain the log file
+ *  @return 0 if log was opened or -1 on failure.
+ */
 int open_connect_log(const char *dir)
 {
    char buf[CBUFLEN];
@@ -59,6 +70,12 @@ int open_connect_log(const char *dir)
 }
 
 
+/*! Log a message to a file.
+ *  @param out Open FILE pointer
+ *  @param lf Logging priority (equal to syslog)
+ *  @param fmt Format string
+ *  @param ap Variable parameter list
+ */
 void vlog_msgf(FILE *out, int lf, const char *fmt, va_list ap)
 {
    struct tm *tm;
@@ -82,6 +99,12 @@ void vlog_msgf(FILE *out, int lf, const char *fmt, va_list ap)
 }
 
 
+/*! Log a message. This function automatically determines
+ *  to which streams the message is logged.
+ *  @param lf Log priority.
+ *  @param fmt Format string.
+ *  @param ... arguments
+ */
 void log_msg(int lf, const char *fmt, ...)
 {
    va_list ap;
diff --git a/src/ocatsetup.c b/src/ocatsetup.c
index beb9b47..f044da3 100644
--- a/src/ocatsetup.c
+++ b/src/ocatsetup.c
@@ -61,7 +61,7 @@ void init_setup(void)
 
 void print_setup_struct(FILE *f)
 {
-   char ip[_SB], nm[_SB], ip6[_SB], logf[_SB], rp[ROOT_PEERS][_SB];
+   char ip[_SB], nm[_SB], ip6[_SB], logf[_SB], hw[_SB], rp[ROOT_PEERS][_SB];
    int i;
 
    inet_ntop(AF_INET, &setup_.ocat_addr4, ip, _SB);
@@ -70,6 +70,8 @@ void print_setup_struct(FILE *f)
    for (i = 0; i < ROOT_PEERS; i++)
       inet_ntop(AF_INET6, &setup_.root_peer[i], rp[i], _SB);
 
+   ether_ntoa_r((struct ether_addr*) setup_.ocat_hwaddr, hw);
+
    if (setup_.logf == stderr)
       strlcpy(logf, "stderr", sizeof(logf));
    else
@@ -129,7 +131,7 @@ void print_setup_struct(FILE *f)
          setup_.config_file,
          setup_.config_read,
          setup_.use_tap,
-         ether_ntoa((struct ether_addr*) setup_.ocat_hwaddr),
+         hw,
          setup_.pid_file,
          setup_.logfn,
          logf,

-- 
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