#include <time.h>
#include <errno.h>
#include <inttypes.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
#include <ulogd/ulogd.h>
#include <ulogd/conffile.h>
},
};
-#define NIPQUAD(addr) \
- ((unsigned char *)&addr)[0], \
- ((unsigned char *)&addr)[1], \
- ((unsigned char *)&addr)[2], \
- ((unsigned char *)&addr)[3]
-
static int gprint_interp(struct ulogd_pluginstance *upi)
{
struct gprint_priv *opi = (struct gprint_priv *) &upi->private;
rem -= ret;
size += ret;
break;
- case ULOGD_RET_IPADDR:
+ case ULOGD_RET_IPADDR: {
+ struct in_addr ipv4addr;
+
ret = snprintf(buf+size, rem, "%s=", key->name);
if (ret < 0)
break;
rem -= ret;
size += ret;
- ret = snprintf(buf+size, rem, "%u.%u.%u.%u,",
- NIPQUAD(key->u.value.ui32));
- if (ret < 0)
+ ipv4addr.s_addr = key->u.value.ui32;
+ if (!inet_ntop(AF_INET, &ipv4addr, buf + size, rem))
break;
+ ret = strlen(buf + size);
+
rem -= ret;
size += ret;
break;
+ }
default:
/* don't know how to interpret this key. */
break;
#include <string.h>
#include <errno.h>
#include <inttypes.h>
+#include <arpa/inet.h>
+#include <netinet/in.h>
#include <ulogd/ulogd.h>
#include <ulogd/conffile.h>
#define ULOGD_OPRINT_DEFAULT "/var/log/ulogd_oprint.log"
#endif
-#define NIPQUAD(addr) \
- ((unsigned char *)&addr)[0], \
- ((unsigned char *)&addr)[1], \
- ((unsigned char *)&addr)[2], \
- ((unsigned char *)&addr)[3]
-
-#define HIPQUAD(addr) \
- ((unsigned char *)&addr)[3], \
- ((unsigned char *)&addr)[2], \
- ((unsigned char *)&addr)[1], \
- ((unsigned char *)&addr)[0]
-
struct oprint_priv {
FILE *of;
};
if (!ret)
ulogd_log(ULOGD_NOTICE, "no result for %s ?!?\n",
upi->input.keys[i].name);
-
+
if (!IS_VALID(*ret))
continue;
case ULOGD_RET_UINT64:
fprintf(opi->of, "%" PRIu64 "\n", ret->u.value.ui64);
break;
- case ULOGD_RET_IPADDR:
- fprintf(opi->of, "%u.%u.%u.%u\n",
- HIPQUAD(ret->u.value.ui32));
+ case ULOGD_RET_IPADDR: {
+ char addrbuf[INET_ADDRSTRLEN + 1] = "";
+ struct in_addr ipv4addr;
+
+ ipv4addr.s_addr = ret->u.value.ui32;
+ if (!inet_ntop(AF_INET, &ipv4addr, addrbuf,
+ sizeof(addrbuf)))
+ break;
+
+ fprintf(opi->of, "%s\n", addrbuf);
break;
+ }
case ULOGD_RET_NONE:
fprintf(opi->of, "<none>\n");
break;