1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
/* David Leonard, 2002. Public domain. */
/* $Id: tag.c 1193 2007-08-30 10:33:24Z d $ */
#if HAVE_CONFIG_H
# include "config.h"
#endif
#if STDC_HEADERS
# include <stdio.h>
# include <string.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "type.h"
#include "main.h"
#include "tag.h"
#include "flow.h"
#include "abbrev.h"
/*
* Combine source and dest to make a combined tag unless -c flag given
* What combining means is that we sometimes have flows which are not
* uni-directional. So we convert a->b and b->a tags to get a<->b. The left and
* right sides are ordered lexicographically, so that we get only a<->b and
* not also b<->a.
* XXX the ordering should be biased to have the local host/net on the left
* of combined flows.
*/
const char *
tag_combine(src, dst)
const char *src;
const char *dst;
{
static char buf[TAGLEN];
static char buf2[TAGLEN];
const char *res;
if (cflag) {
snprintf(buf, sizeof buf, "%s -> %s", src, dst);
res = abbrev_tag(buf);
} else {
snprintf(buf, sizeof buf, "%s <-> %s", src, dst);
res = abbrev_tag(buf);
if (res == buf) {
/* The abbreviations could match a reverse combine: */
snprintf(buf2, sizeof buf2, "%s <-> %s", dst, src);
res = abbrev_tag(buf2);
if (res == buf2)
if (strcmp(src, dst) < 0)
res = buf;
}
}
return res;
}
|