Bug #307 » 0001-Introduce-PrintInet-function.patch
| src/util-print.c | ||
|---|---|---|
|
fprintf(fp, "\n");
|
||
|
}
|
||
|
static const char *PrintInetIPv6(const void *src, char *dst, socklen_t size)
|
||
|
{
|
||
|
struct in6_addr * insrc = (struct in6_addr *) src;
|
||
|
int i;
|
||
|
char s_part[6];
|
||
|
/* current IPv6 format is fixed size */
|
||
|
if (size < 8 * 5) {
|
||
|
SCLogWarning(SC_ERR_ARG_LEN_LONG, "Too small buffer to write IPv6 address");
|
||
|
return NULL;
|
||
|
}
|
||
|
memset(dst, 0, size);
|
||
|
for(i = 0; i < 8; i++) {
|
||
|
snprintf(s_part, 6, "%04x:", htons(insrc->s6_addr16[i]));
|
||
|
strlcat(dst, s_part, size);
|
||
|
}
|
||
|
/* suppress last ':' */
|
||
|
dst[strlen(dst) - 1] = 0;
|
||
|
return dst;
|
||
|
}
|
||
|
const char *PrintInet(int af, const void *src, char *dst, socklen_t size)
|
||
|
{
|
||
|
switch (af) {
|
||
|
case AF_INET:
|
||
|
return inet_ntop(af, src, dst, size);
|
||
|
case AF_INET6:
|
||
|
/* Format IPv6 without deleting zeroes */
|
||
|
return PrintInetIPv6(src, dst, size);
|
||
|
default:
|
||
|
SCLogError(SC_ERR_INVALID_VALUE, "Unsupported protocol: %d", af);
|
||
|
}
|
||
|
return NULL;
|
||
|
}
|
||
| src/util-print.h | ||
|---|---|---|
|
void PrintRawUriFp(FILE *, uint8_t *, uint32_t);
|
||
|
void PrintRawDataFp(FILE *, uint8_t *, uint32_t);
|
||
|
void PrintRawLineHexBuf(char *, uint32_t, uint8_t *, uint32_t );
|
||
|
const char *PrintInet(int , const void *, char *, socklen_t);
|
||
|
#endif /* __UTIL_PRINT_H__ */
|
||