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 57
|
/*
* Network accounting
* utils.c - utility routines *
* (C) 1994 Ulrich Callmeier
*/
#include <stdio.h>
#include <stdlib.h>
#include "netacct.h"
char *intoa(unsigned long addr)
{
static char buff[18];
char *p;
p = (char *) &addr;
sprintf(buff, "%d.%d.%d.%d",
(p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
return(buff);
}
static char hex[] = "0123456789abcdef";
char * etheraddr_string(unsigned char *ep)
{
unsigned int i, j;
char *cp, *s;
s = cp = (char *)malloc(sizeof("00:00:00:00:00:00"));
if ((j = *ep >> 4) != 0)
*cp++ = hex[j];
*cp++ = hex[*ep++ & 0xf];
for (i = 5; (int)--i >= 0;) {
*cp++ = ':';
if ((j = *ep >> 4) != 0)
*cp++ = hex[j];
*cp++ = hex[*ep++ & 0xf];
}
*cp = '\0';
return (s);
}
char *ip_proto_name(unsigned char proto)
{
switch(proto)
{
case IPPROTO_ICMP:
return "ICMP";
case IPPROTO_TCP:
return "TCP";
case IPPROTO_UDP:
return "UDP";
}
return "?";
}
|