On Wed, 3 Jan 2001, Pekka Savola wrote:

> On Tue, 2 Jan 2001, Guy Harris wrote:
> > On Mon, Jan 01, 2001 at 02:07:05AM +0200, Pekka Savola wrote:
> > > I see that savestr is used in a few locations.  I don't see any need for
> > > this, it's just a lousy replacement for strdup.
> >
> > Do all platforms on which tcpdump works support "strdup()"?  There are
> > some fairly old platforms on which I think it worked at some point,
> > although I don't know if it still works there (libpcap includes support
> > for capture mechanisms on SunOS 3.x and, I think, the AIX on the IBM RT
> > PC).
>
> Why not create a configure macro to check this and if it doesn't exist,
> define strdup -> savestr ?

Does this look ok?

Does anyone actually have access to a system to test these kind of
changes? ;-)

-- 
Pekka Savola                  "Tell me of difficulties surmounted,
Netcore Oy                    not those you stumble over and fall"
Systems. Networks. Security.   -- Robert Jordan: A Crown of Swords
diff -uNr tcpdump/addrtoname.c tcpdump.savestr/addrtoname.c
--- tcpdump/addrtoname.c        Sat Oct  7 08:33:25 2000
+++ tcpdump.savestr/addrtoname.c        Wed Jan  3 20:06:29 2001
@@ -56,7 +56,6 @@
 #include "interface.h"
 #include "addrtoname.h"
 #include "llc.h"
-#include "savestr.h"
 #include "setsignal.h"
 
 /* Forwards */
@@ -208,7 +207,7 @@
                        if (hp) {
                                char *dotp;
 
-                               p->name = savestr(hp->h_name);
+                               p->name = strdup(hp->h_name);
                                if (Nflag) {
                                        /* Remove domain qualifications */
                                        dotp = strchr(p->name, '.');
@@ -219,7 +218,7 @@
                        }
                }
        }
-       p->name = savestr(intoa(addr));
+       p->name = strdup(intoa(addr));
        return (p->name);
 }
 
@@ -271,7 +270,7 @@
                        if (hp) {
                                char *dotp;
 
-                               p->name = savestr(hp->h_name);
+                               p->name = strdup(hp->h_name);
                                if (Nflag) {
                                        /* Remove domain qualifications */
                                        dotp = strchr(p->name, '.');
@@ -283,7 +282,7 @@
                }
        }
        cp = (char *)inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf));
-       p->name = savestr(cp);
+       p->name = strdup(cp);
        return (p->name);
 }
 #endif /* INET6 */
@@ -407,7 +406,7 @@
        if (!nflag) {
                char buf[128];
                if (ether_ntohost(buf, (struct ether_addr *)ep) == 0) {
-                       tp->e_name = savestr(buf);
+                       tp->e_name = strdup(buf);
                        return (tp->e_name);
                }
        }
@@ -423,7 +422,7 @@
                *cp++ = hex[*ep++ & 0xf];
        }
        *cp = '\0';
-       tp->e_name = savestr(buf);
+       tp->e_name = strdup(buf);
        return (tp->e_name);
 }
 
@@ -449,7 +448,7 @@
        *cp++ = hex[port >> 4 & 0xf];
        *cp++ = hex[port & 0xf];
        *cp++ = '\0';
-       tp->name = savestr(buf);
+       tp->name = strdup(buf);
        return (tp->name);
 }
 
@@ -476,7 +475,7 @@
                *cp++ = hex[*pi++ & 0xf];
        }
        *cp = '\0';
-       tp->p_name = savestr(buf);
+       tp->p_name = strdup(buf);
        return (tp->p_name);
 }
 
@@ -495,7 +494,7 @@
        tp->nxt = newhnamemem();
 
        snprintf(buf, sizeof(buf), "sap %02x", sap & 0xff);
-       tp->name = savestr(buf);
+       tp->name = strdup(buf);
        return (tp->name);
 }
 
@@ -539,7 +538,7 @@
        tp->nxt = newhnamemem();
 
        (void)snprintf(buf, sizeof(buf), "%u", i);
-       tp->name = savestr(buf);
+       tp->name = strdup(buf);
        return (tp->name);
 }
 
@@ -558,7 +557,7 @@
        tp->nxt = newhnamemem();
 
        (void)snprintf(buf, sizeof(buf), "%u", i);
-       tp->name = savestr(buf);
+       tp->name = strdup(buf);
        return (tp->name);
 }
 
@@ -584,9 +583,9 @@
                        table = table->nxt;
                if (nflag) {
                        (void)snprintf(buf, sizeof(buf), "%d", port);
-                       table->name = savestr(buf);
+                       table->name = strdup(buf);
                } else
-                       table->name = savestr(sv->s_name);
+                       table->name = strdup(sv->s_name);
                table->addr = port;
                table->nxt = newhnamemem();
        }
@@ -635,7 +634,7 @@
 
                memcpy((char *)&protoid[3], (char *)&etype, 2);
                tp = lookup_protoid(protoid);
-               tp->p_name = savestr(eproto_db[i].s);
+               tp->p_name = strdup(eproto_db[i].s);
        }
 }
 
@@ -677,7 +676,7 @@
        if (fp != NULL) {
                while ((ep = pcap_next_etherent(fp)) != NULL) {
                        tp = lookup_emem(ep->addr);
-                       tp->e_name = savestr(ep->name);
+                       tp->e_name = strdup(ep->name);
                }
                (void)fclose(fp);
        }
@@ -693,7 +692,7 @@
 #ifdef HAVE_ETHER_NTOHOST
                 /* Use yp/nis version of name if available */
                 if (ether_ntohost(name, (struct ether_addr *)el->addr) == 0) {
-                        tp->e_name = savestr(name);
+                        tp->e_name = strdup(name);
                        continue;
                }
 #endif
diff -uNr tcpdump/config.h.in tcpdump.savestr/config.h.in
--- tcpdump/config.h.in Wed Jan  3 02:03:27 2001
+++ tcpdump.savestr/config.h.in Wed Jan  3 20:11:26 2001
@@ -146,6 +146,9 @@
 /* Define if you have the strcasecmp function.  */
 #undef HAVE_STRCASECMP
 
+/* Define if you have the strdup function.  */
+#undef HAVE_STRDUP
+
 /* Define if you have the strlcat function.  */
 #undef HAVE_STRLCAT
 
diff -uNr tcpdump/configure.in tcpdump.savestr/configure.in
--- tcpdump/configure.in        Wed Jan  3 02:03:28 2001
+++ tcpdump.savestr/configure.in        Wed Jan  3 20:04:06 2001
@@ -460,6 +460,8 @@
        AC_DEFINE(USE_GETIPNODEBY)
 fi
 
+AC_CHECK_FUNCS(strdup)
+
 needsnprintf=no
 AC_CHECK_FUNCS(vsnprintf snprintf,,
        [needsnprintf=yes])
diff -uNr tcpdump/interface.h tcpdump.savestr/interface.h
--- tcpdump/interface.h Wed Jan  3 02:03:29 2001
+++ tcpdump.savestr/interface.h Wed Jan  3 20:09:25 2001
@@ -55,6 +55,11 @@
 extern size_t strlcpy (char *, const char *, size_t);
 #endif
 
+#ifndef HAVE_STRDUP
+# define strdup(x) savestr(x)
+# include "savestr.h"
+#endif
+
 struct tok {
        int v;                  /* value */
        char *s;                /* string */
diff -uNr tcpdump/print-atalk.c tcpdump.savestr/print-atalk.c
--- tcpdump/print-atalk.c       Mon Oct 30 08:22:14 2000
+++ tcpdump.savestr/print-atalk.c       Wed Jan  3 20:06:29 2001
@@ -46,7 +46,6 @@
 #include "ethertype.h"
 #include "extract.h"                   /* must come after interface.h */
 #include "appletalk.h"
-#include "savestr.h"
 
 static struct tok type2str[] = {
        { ddpRTMP,              "rtmp" },
@@ -542,7 +541,7 @@
                                ;
                        tp->addr = i3;
                        tp->nxt = newhnamemem();
-                       tp->name = savestr(nambuf);
+                       tp->name = strdup(nambuf);
                }
                fclose(fp);
        }
@@ -559,7 +558,7 @@
                        tp->nxt = newhnamemem();
                        (void)snprintf(nambuf, sizeof(nambuf), "%s.%d",
                            tp2->name, athost);
-                       tp->name = savestr(nambuf);
+                       tp->name = strdup(nambuf);
                        return (tp->name);
                }
 
@@ -571,7 +570,7 @@
        else
                (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8,
                    atnet & 0xff);
-       tp->name = savestr(nambuf);
+       tp->name = strdup(nambuf);
 
        return (tp->name);
 }
diff -uNr tcpdump/print-decnet.c tcpdump.savestr/print-decnet.c
--- tcpdump/print-decnet.c      Thu Sep 28 09:42:57 2000
+++ tcpdump.savestr/print-decnet.c      Wed Jan  3 20:06:29 2001
@@ -753,7 +753,7 @@
 
        dna.a_len = sizeof(short);
        memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short));
-       return (savestr(dnet_htoa(&dna)));
+       return (strdup(dnet_htoa(&dna)));
 #else
        return(dnnum_string(dnaddr));   /* punt */
 #endif

Reply via email to