|
@@ -1,4 +1,4 @@
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
* Copyright (c) 2001-2002 Willem Dijkstra
|
|
@@ -6,7 +6,7 @@
|
|
|
*
|
|
|
* The crc routine is from Rob Warnock <rpw3@sgi.com>, from the
|
|
|
* comp.compression FAQ.
|
|
|
- *
|
|
|
+ *
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
* are met:
|
|
@@ -32,8 +32,8 @@
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
* */
|
|
|
|
|
|
-
|
|
|
- *
|
|
|
+
|
|
|
+ *
|
|
|
* A host carrying a 'symon' is considered a 'source' of information. A single
|
|
|
* data 'stream' of information has a particular type: <cpu|mem|if|io>. A
|
|
|
* source can provide multiple 'streams' simultaniously. A source spools
|
|
@@ -51,22 +51,23 @@
|
|
|
#include "data.h"
|
|
|
#include "error.h"
|
|
|
#include "lex.h"
|
|
|
+#include "net.h"
|
|
|
#include "xmalloc.h"
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
-int bytelenvar(char);
|
|
|
-int checklen(int, int, int);
|
|
|
+int bytelenvar(char);
|
|
|
+int checklen(int, int, int);
|
|
|
struct stream *create_stream(int, char *);
|
|
|
-char *formatstrvar(char);
|
|
|
-char *rrdstrvar(char);
|
|
|
-int strlenvar(char);
|
|
|
+char *formatstrvar(char);
|
|
|
+char *rrdstrvar(char);
|
|
|
+int strlenvar(char);
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
|
- *
|
|
|
+ *
|
|
|
* Format specifications are strings of characters:
|
|
|
*
|
|
|
- * L = u_int64
|
|
|
+ * L = u_int64
|
|
|
* l = u_int32
|
|
|
* s = u_int16
|
|
|
* c = 3.2f <= u_int14 <= u_int16 (used in percentages)
|
|
@@ -76,57 +77,58 @@ struct {
|
|
|
char type;
|
|
|
char *rrdformat;
|
|
|
char *strformat;
|
|
|
- int strlen;
|
|
|
- int bytelen;
|
|
|
+ int strlen;
|
|
|
+ int bytelen;
|
|
|
u_int64_t max;
|
|
|
-} streamvar[] = {
|
|
|
- {'L', ":%llu", " %20llu", 22, sizeof(u_int64_t), (u_int64_t) 0xffffffffffffffff},
|
|
|
- {'l', ":%lu", " %10lu", 12, sizeof(u_int32_t), (u_int64_t) 0xffffffff},
|
|
|
- {'s', ":%u", " %5u", 7, sizeof(u_int16_t), (u_int64_t) 0xffff},
|
|
|
- {'c', ":%3.2f", " %3.2f", 8, sizeof(u_int16_t), (u_int64_t) 100},
|
|
|
- {'b', ":%3u", " %3u", 5, sizeof(u_int8_t), (u_int64_t) 255},
|
|
|
- {'\0', NULL, NULL, 0, 0, 0}
|
|
|
+} streamvar[] = {
|
|
|
+ { 'L', ":%llu", " %20llu", 22, sizeof(u_int64_t), (u_int64_t) 0xffffffffffffffff },
|
|
|
+ { 'l', ":%lu", " %10lu", 12, sizeof(u_int32_t), (u_int64_t) 0xffffffff },
|
|
|
+ { 's', ":%u", " %5u", 7, sizeof(u_int16_t), (u_int64_t) 0xffff },
|
|
|
+ { 'c', ":%3.2f", " %3.2f", 8, sizeof(u_int16_t), (u_int64_t) 100 },
|
|
|
+ { 'b', ":%3u", " %3u", 5, sizeof(u_int8_t), (u_int64_t) 255 },
|
|
|
+ { '\0', NULL, NULL, 0, 0, 0 }
|
|
|
};
|
|
|
|
|
|
struct {
|
|
|
int type;
|
|
|
char *form;
|
|
|
-} streamform[] = {
|
|
|
- {MT_IO, "LLL"},
|
|
|
- {MT_CPU, "ccccc"},
|
|
|
- {MT_MEM, "lllll"},
|
|
|
- {MT_IF, "llllllllll"},
|
|
|
- {MT_PF, "LLLLLLLLLLLLLLLLLLLLLL"},
|
|
|
- {MT_EOT, ""}
|
|
|
+} streamform[] = {
|
|
|
+ { MT_IO, "LLL" },
|
|
|
+ { MT_CPU, "ccccc" },
|
|
|
+ { MT_MEM, "lllll" },
|
|
|
+ { MT_IF, "llllllllll" },
|
|
|
+ { MT_PF, "LLLLLLLLLLLLLLLLLLLLLL" },
|
|
|
+ { MT_DEBUG, "llllllllllllllllllll" },
|
|
|
+ { MT_EOT, "" }
|
|
|
};
|
|
|
|
|
|
struct {
|
|
|
int type;
|
|
|
int token;
|
|
|
-} streamtoken[] = {
|
|
|
- {MT_IO, LXT_IO},
|
|
|
- {MT_CPU, LXT_CPU},
|
|
|
- {MT_MEM, LXT_MEM},
|
|
|
- {MT_IF, LXT_IF},
|
|
|
- {MT_PF, LXT_PF},
|
|
|
- {MT_EOT, LXT_BADTOKEN}
|
|
|
+} streamtoken[] = {
|
|
|
+ { MT_IO, LXT_IO },
|
|
|
+ { MT_CPU, LXT_CPU },
|
|
|
+ { MT_MEM, LXT_MEM },
|
|
|
+ { MT_IF, LXT_IF },
|
|
|
+ { MT_PF, LXT_PF },
|
|
|
+ { MT_DEBUG, LXT_DEBUG },
|
|
|
+ { MT_EOT, LXT_BADTOKEN }
|
|
|
};
|
|
|
|
|
|
-u_int32_t
|
|
|
+u_int32_t
|
|
|
crc32_table[256];
|
|
|
|
|
|
-
|
|
|
|
|
|
const int
|
|
|
token2type(const int token)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
- for (i=0; streamtoken[i].type < MT_EOT; i++)
|
|
|
- if (streamtoken[i].token == token)
|
|
|
+ for (i = 0; streamtoken[i].type < MT_EOT; i++)
|
|
|
+ if (streamtoken[i].token == token)
|
|
|
return streamtoken[i].type;
|
|
|
|
|
|
- fatal("%s:%d: internal error: token (%d) could not be translated into a stream type",
|
|
|
+ fatal("%s:%d: internal error: token (%d) could not be translated into a stream type",
|
|
|
__FILE__, __LINE__, token);
|
|
|
|
|
|
|
|
@@ -138,11 +140,11 @@ type2str(const int streamtype)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
- for (i=0; streamtoken[i].type < MT_EOT; i++)
|
|
|
- if (streamtoken[i].type == streamtype)
|
|
|
+ for (i = 0; streamtoken[i].type < MT_EOT; i++)
|
|
|
+ if (streamtoken[i].type == streamtype)
|
|
|
return parse_opcode(streamtoken[i].token);
|
|
|
|
|
|
- fatal("%s:%d: internal error: type (%d) could not be translated into ascii representation",
|
|
|
+ fatal("%s:%d: internal error: type (%d) could not be translated into ascii representation",
|
|
|
__FILE__, __LINE__, streamtype);
|
|
|
|
|
|
|
|
@@ -150,7 +152,7 @@ type2str(const int streamtype)
|
|
|
}
|
|
|
|
|
|
int
|
|
|
-strlentype(int type)
|
|
|
+strlentype(int type)
|
|
|
{
|
|
|
int i = 0;
|
|
|
int sum = 0;
|
|
@@ -166,13 +168,13 @@ strlenvar(char var)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
- for (i=0; streamvar[i].type > '\0'; i++)
|
|
|
+ for (i = 0; streamvar[i].type > '\0'; i++)
|
|
|
if (streamvar[i].type == var)
|
|
|
return streamvar[i].strlen;
|
|
|
-
|
|
|
- fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
|
|
|
+
|
|
|
+ fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
|
|
|
__FILE__, __LINE__, var);
|
|
|
-
|
|
|
+
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -182,13 +184,13 @@ bytelenvar(char var)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
- for (i=0; streamvar[i].type > '\0'; i++)
|
|
|
+ for (i = 0; streamvar[i].type > '\0'; i++)
|
|
|
if (streamvar[i].type == var)
|
|
|
return streamvar[i].bytelen;
|
|
|
-
|
|
|
- fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
|
|
|
+
|
|
|
+ fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
|
|
|
__FILE__, __LINE__, var);
|
|
|
-
|
|
|
+
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -198,13 +200,13 @@ formatstrvar(char var)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
- for (i=0; streamvar[i].type > '\0'; i++)
|
|
|
+ for (i = 0; streamvar[i].type > '\0'; i++)
|
|
|
if (streamvar[i].type == var)
|
|
|
return streamvar[i].strformat;
|
|
|
-
|
|
|
- fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
|
|
|
+
|
|
|
+ fatal("%s:%d: internal error: type spefication for stream var '%c' not found",
|
|
|
__FILE__, __LINE__, var);
|
|
|
-
|
|
|
+
|
|
|
|
|
|
return "";
|
|
|
}
|
|
@@ -214,29 +216,30 @@ rrdstrvar(char var)
|
|
|
{
|
|
|
int i;
|
|
|
|
|
|
- for (i=0; streamvar[i].type > '\0'; i++)
|
|
|
+ for (i = 0; streamvar[i].type > '\0'; i++)
|
|
|
if (streamvar[i].type == var)
|
|
|
return streamvar[i].rrdformat;
|
|
|
-
|
|
|
+
|
|
|
fatal("internal error: type spefication for stream var '%c' not found", var);
|
|
|
-
|
|
|
+
|
|
|
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
int
|
|
|
-checklen(int maxlen, int current, int extra)
|
|
|
+checklen(int maxlen, int current, int extra)
|
|
|
{
|
|
|
if ((current + extra) < maxlen) {
|
|
|
return 0;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
warning("buffer overflow: max=%d, current=%d, extra=%d",
|
|
|
maxlen, current, extra);
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
int
|
|
|
-setheader(char *buf, struct symonpacketheader *hph)
|
|
|
+setheader(char *buf, struct symonpacketheader *hph)
|
|
|
{
|
|
|
struct symonpacketheader nph;
|
|
|
char *p;
|
|
@@ -248,37 +251,45 @@ setheader(char *buf, struct symonpacketheader *hph)
|
|
|
|
|
|
p = buf;
|
|
|
|
|
|
- bcopy(&nph.crc, p, sizeof(u_int32_t)); p += sizeof(u_int32_t);
|
|
|
- bcopy(&nph.timestamp, p, sizeof(u_int64_t)); p += sizeof(u_int64_t);
|
|
|
- bcopy(&nph.length, p, sizeof(u_int16_t)); p += sizeof(u_int16_t);
|
|
|
- bcopy(&nph.symon_version, p, sizeof(u_int8_t)); p += sizeof(u_int8_t);
|
|
|
+ bcopy(&nph.crc, p, sizeof(u_int32_t));
|
|
|
+ p += sizeof(u_int32_t);
|
|
|
+ bcopy(&nph.timestamp, p, sizeof(u_int64_t));
|
|
|
+ p += sizeof(u_int64_t);
|
|
|
+ bcopy(&nph.length, p, sizeof(u_int16_t));
|
|
|
+ p += sizeof(u_int16_t);
|
|
|
+ bcopy(&nph.symon_version, p, sizeof(u_int8_t));
|
|
|
+ p += sizeof(u_int8_t);
|
|
|
|
|
|
return (p - buf);
|
|
|
}
|
|
|
-int
|
|
|
+int
|
|
|
getheader(char *buf, struct symonpacketheader *hph)
|
|
|
{
|
|
|
char *p;
|
|
|
|
|
|
p = buf;
|
|
|
|
|
|
- bcopy(p, &hph->crc, sizeof(u_int32_t)); p += sizeof(u_int32_t);
|
|
|
- bcopy(p, &hph->timestamp, sizeof(u_int64_t)); p += sizeof(u_int64_t);
|
|
|
- bcopy(p, &hph->length, sizeof(u_int16_t)); p += sizeof(u_int16_t);
|
|
|
- bcopy(p, &hph->symon_version, sizeof(u_int8_t)); p += sizeof(u_int8_t);
|
|
|
+ bcopy(p, &hph->crc, sizeof(u_int32_t));
|
|
|
+ p += sizeof(u_int32_t);
|
|
|
+ bcopy(p, &hph->timestamp, sizeof(u_int64_t));
|
|
|
+ p += sizeof(u_int64_t);
|
|
|
+ bcopy(p, &hph->length, sizeof(u_int16_t));
|
|
|
+ p += sizeof(u_int16_t);
|
|
|
+ bcopy(p, &hph->symon_version, sizeof(u_int8_t));
|
|
|
+ p += sizeof(u_int8_t);
|
|
|
|
|
|
hph->timestamp = ntohq(hph->timestamp);
|
|
|
hph->crc = ntohl(hph->crc);
|
|
|
hph->length = ntohs(hph->length);
|
|
|
-
|
|
|
+
|
|
|
return (p - buf);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
* Pack multiple arguments of a MT_TYPE into a network order bytestream.
|
|
|
- * snpack returns the number of bytes actually stored.
|
|
|
+ * snpack returns the number of bytes actually stored.
|
|
|
*/
|
|
|
int
|
|
|
-snpack(char *buf, int maxlen, char *id, int type, ...)
|
|
|
+snpack(char *buf, int maxlen, char *id, int type,...)
|
|
|
{
|
|
|
va_list ap;
|
|
|
u_int16_t b;
|
|
@@ -294,32 +305,36 @@ snpack(char *buf, int maxlen, char *id, int type, ...)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- if ( maxlen < 2 ) {
|
|
|
+ if (maxlen < 2) {
|
|
|
fatal("%s:%d: maxlen too small", __FILE__, __LINE__);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
buf[offset++] = type & 0xff;
|
|
|
}
|
|
|
|
|
|
if (id) {
|
|
|
if ((strlen(id) + 1) >= maxlen) {
|
|
|
return 0;
|
|
|
- } else {
|
|
|
- strncpy(&buf[offset], id, maxlen-1);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ strncpy(&buf[offset], id, maxlen - 1);
|
|
|
offset += strlen(id);
|
|
|
}
|
|
|
}
|
|
|
buf[offset++] = '\0';
|
|
|
-
|
|
|
+
|
|
|
va_start(ap, type);
|
|
|
- while (streamform[type].form[i] != '\0'){
|
|
|
+ while (streamform[type].form[i] != '\0') {
|
|
|
|
|
|
if (checklen(maxlen, offset, bytelenvar(streamform[type].form[i])))
|
|
|
return offset;
|
|
|
-
|
|
|
-
|
|
|
- stack. This is to ensure that we get the correct value, if the
|
|
|
- compiler decided to upgrade our short to a 32bit int. -- cheers
|
|
|
- dhartmei@ */
|
|
|
+
|
|
|
+
|
|
|
+ * all values smaller than 32 bytes are transferred using ints on the
|
|
|
+ * stack. This is to ensure that we get the correct value, if the
|
|
|
+ * compiler decided to upgrade our short to a 32bit int. -- cheers
|
|
|
+ * dhartmei@
|
|
|
+ */
|
|
|
switch (streamform[type].form[i]) {
|
|
|
case 'b':
|
|
|
b = va_arg(ap, int);
|
|
@@ -340,14 +355,14 @@ snpack(char *buf, int maxlen, char *id, int type, ...)
|
|
|
offset += sizeof(u_int16_t);
|
|
|
break;
|
|
|
|
|
|
- case 'l':
|
|
|
+ case 'l':
|
|
|
l = va_arg(ap, u_int32_t);
|
|
|
l = htonl(l);
|
|
|
bcopy(&l, buf + offset, sizeof(u_int32_t));
|
|
|
offset += sizeof(u_int32_t);
|
|
|
break;
|
|
|
|
|
|
- case 'L':
|
|
|
+ case 'L':
|
|
|
q = va_arg(ap, u_int64_t);
|
|
|
q = htonq(q);
|
|
|
bcopy(&q, buf + offset, sizeof(u_int64_t));
|
|
@@ -364,25 +379,25 @@ snpack(char *buf, int maxlen, char *id, int type, ...)
|
|
|
|
|
|
return offset;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
* Unpack a packedstream in buf into a struct packetstream. Returns the number
|
|
|
- * of bytes actually read.
|
|
|
- *
|
|
|
+ * of bytes actually read.
|
|
|
+ *
|
|
|
* Note that this function does "automatic" bounds checking; it uses a
|
|
|
* description of the packedstream (streamform) to parse the actual bytes. This
|
|
|
* description corresponds to the amount of bytes that will fit inside the
|
|
|
* packedstream structure. */
|
|
|
int
|
|
|
-sunpack(char *buf, struct packedstream *ps)
|
|
|
+sunpack(char *buf, struct packedstream * ps)
|
|
|
{
|
|
|
char *in, *out;
|
|
|
- int i=0;
|
|
|
+ int i = 0;
|
|
|
int type;
|
|
|
u_int16_t s;
|
|
|
u_int16_t c;
|
|
|
u_int32_t l;
|
|
|
u_int64_t q;
|
|
|
-
|
|
|
+
|
|
|
bzero(ps, sizeof(struct packedstream));
|
|
|
|
|
|
in = buf;
|
|
@@ -396,53 +411,54 @@ sunpack(char *buf, struct packedstream *ps)
|
|
|
in++;
|
|
|
if ((*in) != '\0') {
|
|
|
strncpy(ps->args, in, sizeof(ps->args));
|
|
|
- ps->args[sizeof(ps->args)-1]='\0';
|
|
|
+ ps->args[sizeof(ps->args) - 1] = '\0';
|
|
|
in += strlen(ps->args);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
ps->args[0] = '\0';
|
|
|
}
|
|
|
|
|
|
in++;
|
|
|
|
|
|
- out = (char *)(&ps->data);
|
|
|
+ out = (char *) (&ps->data);
|
|
|
|
|
|
while (streamform[type].form[i] != '\0') {
|
|
|
switch (streamform[type].form[i]) {
|
|
|
case 'b':
|
|
|
- bcopy((void *)in, (void *)out, sizeof(u_int8_t));
|
|
|
+ bcopy((void *) in, (void *) out, sizeof(u_int8_t));
|
|
|
in++;
|
|
|
out++;
|
|
|
break;
|
|
|
|
|
|
case 'c':
|
|
|
- bcopy((void *)in, &c, sizeof(u_int16_t));
|
|
|
+ bcopy((void *) in, &c, sizeof(u_int16_t));
|
|
|
c = ntohs(c);
|
|
|
- bcopy(&c, (void *)out, sizeof(u_int16_t));
|
|
|
- in += sizeof(u_int16_t);
|
|
|
+ bcopy(&c, (void *) out, sizeof(u_int16_t));
|
|
|
+ in += sizeof(u_int16_t);
|
|
|
out += sizeof(u_int16_t);
|
|
|
break;
|
|
|
|
|
|
case 's':
|
|
|
- bcopy((void *)in, &s, sizeof(u_int16_t));
|
|
|
+ bcopy((void *) in, &s, sizeof(u_int16_t));
|
|
|
s = ntohs(s);
|
|
|
- bcopy(&s, (void *)out, sizeof(u_int16_t));
|
|
|
- in += sizeof(u_int16_t);
|
|
|
+ bcopy(&s, (void *) out, sizeof(u_int16_t));
|
|
|
+ in += sizeof(u_int16_t);
|
|
|
out += sizeof(u_int16_t);
|
|
|
break;
|
|
|
|
|
|
- case 'l':
|
|
|
- bcopy((void *)in, &l, sizeof(u_int32_t));
|
|
|
+ case 'l':
|
|
|
+ bcopy((void *) in, &l, sizeof(u_int32_t));
|
|
|
l = ntohl(l);
|
|
|
- bcopy(&l, (void *)out, sizeof(u_int32_t));
|
|
|
- in += sizeof(u_int32_t);
|
|
|
+ bcopy(&l, (void *) out, sizeof(u_int32_t));
|
|
|
+ in += sizeof(u_int32_t);
|
|
|
out += sizeof(u_int32_t);
|
|
|
break;
|
|
|
|
|
|
- case 'L':
|
|
|
- bcopy((void *)in, &q, sizeof(u_int64_t));
|
|
|
+ case 'L':
|
|
|
+ bcopy((void *) in, &q, sizeof(u_int64_t));
|
|
|
q = ntohq(q);
|
|
|
- bcopy(&q, (void *)out, sizeof(u_int64_t));
|
|
|
- in += sizeof(u_int64_t);
|
|
|
+ bcopy(&q, (void *) out, sizeof(u_int64_t));
|
|
|
+ in += sizeof(u_int64_t);
|
|
|
out += sizeof(u_int64_t);
|
|
|
break;
|
|
|
|
|
@@ -456,7 +472,7 @@ sunpack(char *buf, struct packedstream *ps)
|
|
|
}
|
|
|
|
|
|
int
|
|
|
-ps2strn(struct packedstream *ps, char *buf, const int maxlen, int pretty)
|
|
|
+ps2strn(struct packedstream * ps, char *buf, const int maxlen, int pretty)
|
|
|
{
|
|
|
float f;
|
|
|
u_int16_t b;
|
|
@@ -464,19 +480,19 @@ ps2strn(struct packedstream *ps, char *buf, const int maxlen, int pretty)
|
|
|
u_int16_t c;
|
|
|
u_int64_t q;
|
|
|
u_int32_t l;
|
|
|
- int i=0;
|
|
|
+ int i = 0;
|
|
|
char *formatstr;
|
|
|
char *in, *out;
|
|
|
char vartype;
|
|
|
-
|
|
|
- in = (char *)(&ps->data);
|
|
|
- out = (char *)buf;
|
|
|
+
|
|
|
+ in = (char *) (&ps->data);
|
|
|
+ out = (char *) buf;
|
|
|
|
|
|
while ((vartype = streamform[ps->type].form[i]) != '\0') {
|
|
|
|
|
|
- if (checklen(maxlen, (out-buf), strlenvar(vartype)))
|
|
|
+ if (checklen(maxlen, (out - buf), strlenvar(vartype)))
|
|
|
return 0;
|
|
|
-
|
|
|
+
|
|
|
switch (pretty) {
|
|
|
case PS2STR_PRETTY:
|
|
|
formatstr = formatstrvar(vartype);
|
|
@@ -492,33 +508,33 @@ ps2strn(struct packedstream *ps, char *buf, const int maxlen, int pretty)
|
|
|
switch (vartype) {
|
|
|
case 'b':
|
|
|
bcopy(in, &b, sizeof(u_int8_t));
|
|
|
- snprintf(out, strlenvar(vartype), formatstr, b);
|
|
|
+ snprintf(out, strlenvar(vartype), formatstr, b);
|
|
|
in++;
|
|
|
- break;
|
|
|
+ break;
|
|
|
|
|
|
case 'c':
|
|
|
bcopy(in, &c, sizeof(u_int16_t));
|
|
|
- f = (float)c / 10.0;
|
|
|
- snprintf(out, strlenvar(vartype), formatstr, f);
|
|
|
- in += sizeof(u_int16_t);
|
|
|
+ f = (float) c / 10.0;
|
|
|
+ snprintf(out, strlenvar(vartype), formatstr, f);
|
|
|
+ in += sizeof(u_int16_t);
|
|
|
break;
|
|
|
|
|
|
case 's':
|
|
|
bcopy(in, &s, sizeof(u_int16_t));
|
|
|
- snprintf(out, strlenvar(vartype), formatstr, s);
|
|
|
- in += sizeof(u_int16_t);
|
|
|
+ snprintf(out, strlenvar(vartype), formatstr, s);
|
|
|
+ in += sizeof(u_int16_t);
|
|
|
break;
|
|
|
|
|
|
- case 'l':
|
|
|
+ case 'l':
|
|
|
bcopy(in, &l, sizeof(u_int32_t));
|
|
|
- snprintf(out, strlenvar(vartype), formatstr, l);
|
|
|
- in += sizeof(u_int32_t);
|
|
|
+ snprintf(out, strlenvar(vartype), formatstr, l);
|
|
|
+ in += sizeof(u_int32_t);
|
|
|
break;
|
|
|
|
|
|
- case 'L':
|
|
|
+ case 'L':
|
|
|
bcopy(in, &q, sizeof(u_int64_t));
|
|
|
- snprintf(out, strlenvar(vartype), formatstr, q);
|
|
|
- in += sizeof(u_int64_t);
|
|
|
+ snprintf(out, strlenvar(vartype), formatstr, q);
|
|
|
+ in += sizeof(u_int64_t);
|
|
|
break;
|
|
|
|
|
|
default:
|
|
@@ -538,18 +554,18 @@ create_stream(int type, char *args)
|
|
|
if (type < 0 || type >= MT_EOT)
|
|
|
fatal("%s:%d: internal error: stream type unknown", __FILE__, __LINE__);
|
|
|
|
|
|
- p = (struct stream *)xmalloc(sizeof(struct stream));
|
|
|
+ p = (struct stream *) xmalloc(sizeof(struct stream));
|
|
|
bzero(p, sizeof(struct stream));
|
|
|
p->type = type;
|
|
|
|
|
|
if (args != NULL)
|
|
|
p->args = xstrdup(args);
|
|
|
-
|
|
|
+
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
struct stream *
|
|
|
-find_source_stream(struct source *source, int type, char *args)
|
|
|
+find_source_stream(struct source * source, int type, char *args)
|
|
|
{
|
|
|
struct stream *p;
|
|
|
|
|
@@ -557,8 +573,8 @@ find_source_stream(struct source *source, int type, char *args)
|
|
|
return NULL;
|
|
|
|
|
|
SLIST_FOREACH(p, &source->sl, streams) {
|
|
|
- if ((p->type == type)
|
|
|
- && (((void *)args != (void *)p != NULL)
|
|
|
+ if ((p->type == type)
|
|
|
+ && (((void *) args != (void *) p != NULL)
|
|
|
&& strncmp(args, p->args, _POSIX2_LINE_MAX) == 0))
|
|
|
return p;
|
|
|
}
|
|
@@ -567,7 +583,7 @@ find_source_stream(struct source *source, int type, char *args)
|
|
|
}
|
|
|
|
|
|
struct stream *
|
|
|
-add_source_stream(struct source *source, int type, char *args)
|
|
|
+add_source_stream(struct source * source, int type, char *args)
|
|
|
{
|
|
|
struct stream *p;
|
|
|
|
|
@@ -585,7 +601,7 @@ add_source_stream(struct source *source, int type, char *args)
|
|
|
}
|
|
|
|
|
|
struct stream *
|
|
|
-find_mux_stream(struct mux *mux, int type, char *args)
|
|
|
+find_mux_stream(struct mux * mux, int type, char *args)
|
|
|
{
|
|
|
struct stream *p;
|
|
|
|
|
@@ -593,8 +609,8 @@ find_mux_stream(struct mux *mux, int type, char *args)
|
|
|
return NULL;
|
|
|
|
|
|
SLIST_FOREACH(p, &mux->sl, streams) {
|
|
|
- if ((p->type == type)
|
|
|
- && (((void *)args != (void *)p != NULL)
|
|
|
+ if ((p->type == type)
|
|
|
+ && (((void *) args != (void *) p != NULL)
|
|
|
&& strncmp(args, p->args, _POSIX2_LINE_MAX) == 0))
|
|
|
return p;
|
|
|
}
|
|
@@ -603,7 +619,7 @@ find_mux_stream(struct mux *mux, int type, char *args)
|
|
|
}
|
|
|
|
|
|
struct stream *
|
|
|
-add_mux_stream(struct mux *mux, int type, char *args)
|
|
|
+add_mux_stream(struct mux * mux, int type, char *args)
|
|
|
{
|
|
|
struct stream *p;
|
|
|
|
|
@@ -621,7 +637,7 @@ add_mux_stream(struct mux *mux, int type, char *args)
|
|
|
}
|
|
|
|
|
|
struct source *
|
|
|
-find_source(struct sourcelist *sol, char *name)
|
|
|
+find_source(struct sourcelist * sol, char *name)
|
|
|
{
|
|
|
struct source *p;
|
|
|
|
|
@@ -629,8 +645,8 @@ find_source(struct sourcelist *sol, char *name)
|
|
|
return NULL;
|
|
|
|
|
|
SLIST_FOREACH(p, sol, sources) {
|
|
|
- if (((void *)name != (void *)p != NULL)
|
|
|
- && strncmp(name, p->name, _POSIX2_LINE_MAX) == 0)
|
|
|
+ if (((void *) name != (void *) p != NULL)
|
|
|
+ && strncmp(name, p->addr, _POSIX2_LINE_MAX) == 0)
|
|
|
return p;
|
|
|
}
|
|
|
|
|
@@ -638,7 +654,7 @@ find_source(struct sourcelist *sol, char *name)
|
|
|
}
|
|
|
|
|
|
struct source *
|
|
|
-find_source_ip(struct sourcelist *sol, u_int32_t ip)
|
|
|
+find_source_sockaddr(struct sourcelist * sol, struct sockaddr * addr)
|
|
|
{
|
|
|
struct source *p;
|
|
|
|
|
@@ -646,7 +662,7 @@ find_source_ip(struct sourcelist *sol, u_int32_t ip)
|
|
|
return NULL;
|
|
|
|
|
|
SLIST_FOREACH(p, sol, sources) {
|
|
|
- if (p->ip == ip)
|
|
|
+ if (cmpsock_addr((struct sockaddr *) & p->sockaddr, addr))
|
|
|
return p;
|
|
|
}
|
|
|
|
|
@@ -654,9 +670,9 @@ find_source_ip(struct sourcelist *sol, u_int32_t ip)
|
|
|
}
|
|
|
|
|
|
struct source *
|
|
|
-add_source(struct sourcelist *sol, char *name)
|
|
|
+add_source(struct sourcelist * sol, char *name)
|
|
|
{
|
|
|
- struct source* p;
|
|
|
+ struct source *p;
|
|
|
|
|
|
if (sol == NULL)
|
|
|
return NULL;
|
|
@@ -664,16 +680,17 @@ add_source(struct sourcelist *sol, char *name)
|
|
|
if (find_source(sol, name) != NULL)
|
|
|
return NULL;
|
|
|
|
|
|
- p = (struct source *)xmalloc(sizeof(struct source));
|
|
|
+ p = (struct source *) xmalloc(sizeof(struct source));
|
|
|
bzero(p, sizeof(struct source));
|
|
|
- p->name = xstrdup(name);
|
|
|
+ p->addr = xstrdup(name);
|
|
|
+
|
|
|
SLIST_INSERT_HEAD(sol, p, sources);
|
|
|
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
struct mux *
|
|
|
-find_mux(struct muxlist *mul, char *name)
|
|
|
+find_mux(struct muxlist * mul, char *name)
|
|
|
{
|
|
|
struct mux *p;
|
|
|
|
|
@@ -681,7 +698,7 @@ find_mux(struct muxlist *mul, char *name)
|
|
|
return NULL;
|
|
|
|
|
|
SLIST_FOREACH(p, mul, muxes) {
|
|
|
- if (((void *)name != (void *)p != NULL)
|
|
|
+ if (((void *) name != (void *) p != NULL)
|
|
|
&& strncmp(name, p->name, _POSIX2_LINE_MAX) == 0)
|
|
|
return p;
|
|
|
}
|
|
@@ -690,9 +707,9 @@ find_mux(struct muxlist *mul, char *name)
|
|
|
}
|
|
|
|
|
|
struct mux *
|
|
|
-add_mux(struct muxlist *mul, char *name)
|
|
|
+add_mux(struct muxlist * mul, char *name)
|
|
|
{
|
|
|
- struct mux* p;
|
|
|
+ struct mux *p;
|
|
|
|
|
|
if (mul == NULL)
|
|
|
return NULL;
|
|
@@ -700,16 +717,17 @@ add_mux(struct muxlist *mul, char *name)
|
|
|
if (find_mux(mul, name) != NULL)
|
|
|
return NULL;
|
|
|
|
|
|
- p = (struct mux *)xmalloc(sizeof(struct mux));
|
|
|
+ p = (struct mux *) xmalloc(sizeof(struct mux));
|
|
|
bzero(p, sizeof(struct mux));
|
|
|
p->name = xstrdup(name);
|
|
|
SLIST_INSERT_HEAD(mul, p, muxes);
|
|
|
+ SLIST_INIT(&p->sol);
|
|
|
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
struct mux *
|
|
|
-rename_mux(struct muxlist *mul, struct mux *mux, char *name)
|
|
|
+rename_mux(struct muxlist * mul, struct mux * mux, char *name)
|
|
|
{
|
|
|
if (mul == NULL || mux == NULL)
|
|
|
return NULL;
|
|
@@ -725,61 +743,77 @@ rename_mux(struct muxlist *mul, struct mux *mux, char *name)
|
|
|
return mux;
|
|
|
}
|
|
|
void
|
|
|
-free_muxlist(struct muxlist *mul)
|
|
|
+free_muxlist(struct muxlist * mul)
|
|
|
{
|
|
|
struct mux *p, *np;
|
|
|
+ int i;
|
|
|
|
|
|
if (mul == NULL || SLIST_EMPTY(mul))
|
|
|
return;
|
|
|
|
|
|
p = SLIST_FIRST(mul);
|
|
|
|
|
|
- while ( p ) {
|
|
|
+ while (p) {
|
|
|
np = SLIST_NEXT(p, muxes);
|
|
|
|
|
|
- if (p->name != NULL) xfree(p->name);
|
|
|
+ if (p->name != NULL)
|
|
|
+ xfree(p->name);
|
|
|
+ if (p->addr != NULL)
|
|
|
+ xfree(p->addr);
|
|
|
+ if (p->port != NULL)
|
|
|
+ xfree(p->port);
|
|
|
+
|
|
|
close(p->clientsocket);
|
|
|
- close(p->symonsocket);
|
|
|
+ close(p->symuxsocket);
|
|
|
+ for (i = 0; i < AF_MAX; i++)
|
|
|
+ if (p->symonsocket[i])
|
|
|
+ close(p->symonsocket[i]);
|
|
|
+
|
|
|
free_streamlist(&p->sl);
|
|
|
+ free_sourcelist(&p->sol);
|
|
|
xfree(p);
|
|
|
|
|
|
p = np;
|
|
|
}
|
|
|
}
|
|
|
void
|
|
|
-free_streamlist(struct streamlist *sl)
|
|
|
+free_streamlist(struct streamlist * sl)
|
|
|
{
|
|
|
struct stream *p, *np;
|
|
|
|
|
|
if (sl == NULL || SLIST_EMPTY(sl))
|
|
|
return;
|
|
|
-
|
|
|
+
|
|
|
p = SLIST_FIRST(sl);
|
|
|
|
|
|
- while ( p ) {
|
|
|
+ while (p) {
|
|
|
np = SLIST_NEXT(p, streams);
|
|
|
|
|
|
- if (p->args != NULL) xfree(p->args);
|
|
|
- if (p->file != NULL) xfree(p->file);
|
|
|
+ if (p->args != NULL)
|
|
|
+ xfree(p->args);
|
|
|
+ if (p->file != NULL)
|
|
|
+ xfree(p->file);
|
|
|
xfree(p);
|
|
|
|
|
|
p = np;
|
|
|
}
|
|
|
}
|
|
|
void
|
|
|
-free_sourcelist(struct sourcelist *sol)
|
|
|
+free_sourcelist(struct sourcelist * sol)
|
|
|
{
|
|
|
struct source *p, *np;
|
|
|
|
|
|
if (sol == NULL || SLIST_EMPTY(sol))
|
|
|
return;
|
|
|
-
|
|
|
+
|
|
|
p = SLIST_FIRST(sol);
|
|
|
|
|
|
- while ( p ) {
|
|
|
+ while (p) {
|
|
|
np = SLIST_NEXT(p, sources);
|
|
|
|
|
|
- if (p->name != NULL) xfree(p->name);
|
|
|
+ if (p->addr != NULL)
|
|
|
+ xfree(p->addr);
|
|
|
+
|
|
|
free_streamlist(&p->sl);
|
|
|
xfree(p);
|
|
|
|
|
@@ -788,19 +822,20 @@ free_sourcelist(struct sourcelist *sol)
|
|
|
}
|
|
|
|
|
|
int
|
|
|
-calculate_churnbuffer(struct sourcelist *sol) {
|
|
|
- struct source *source;
|
|
|
- struct stream *stream;
|
|
|
+calculate_churnbuffer(struct sourcelist * sol)
|
|
|
+{
|
|
|
+ struct source *source;
|
|
|
+ struct stream *stream;
|
|
|
int prefixlen;
|
|
|
int maxlen;
|
|
|
- int len;
|
|
|
+ int len;
|
|
|
int n;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- prefixlen = (sizeof(time_t)*3) + strlen(":") + 15 + strlen(":");
|
|
|
-
|
|
|
- len = n = 0;
|
|
|
- source = NULL;
|
|
|
+ prefixlen = (sizeof(time_t) * 3) + strlen(":") + 15 + strlen(":");
|
|
|
+
|
|
|
+ len = n = 0;
|
|
|
+ source = NULL;
|
|
|
stream = NULL;
|
|
|
maxlen = 0;
|
|
|
|
|
@@ -812,7 +847,8 @@ calculate_churnbuffer(struct sourcelist *sol) {
|
|
|
len += strlentype(stream->type);
|
|
|
n++;
|
|
|
}
|
|
|
- if (len > maxlen) maxlen = len;
|
|
|
+ if (len > maxlen)
|
|
|
+ maxlen = len;
|
|
|
}
|
|
|
return maxlen;
|
|
|
}
|
|
@@ -820,9 +856,9 @@ calculate_churnbuffer(struct sourcelist *sol) {
|
|
|
u_int32_t
|
|
|
crc32(const void *buf, unsigned int len)
|
|
|
{
|
|
|
- u_int8_t *p;
|
|
|
+ u_int8_t *p;
|
|
|
u_int32_t crc;
|
|
|
-
|
|
|
+
|
|
|
crc = 0xffffffff;
|
|
|
for (p = (u_int8_t *) buf; len > 0; ++p, --len)
|
|
|
crc = (crc << 8) ^ crc32_table[(crc >> 24) ^ *p];
|
|
@@ -830,7 +866,7 @@ crc32(const void *buf, unsigned int len)
|
|
|
return ~crc;
|
|
|
}
|
|
|
|
|
|
-void
|
|
|
+void
|
|
|
init_crc32()
|
|
|
{
|
|
|
unsigned int i, j;
|