From 37ec046bf4cdab96a1e9bddd60e8b76b36bcf64a Mon Sep 17 00:00:00 2001 From: laforge Date: Sun, 20 May 2001 13:51:46 +0000 Subject: included --with-log-ip-as-string option removed ./configure (run autoconf) autoconf now adds -I/usr/src/linux/include to CFLAGS --- ulogd/mysql/ulogd_MYSQL.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'ulogd/mysql/ulogd_MYSQL.c') diff --git a/ulogd/mysql/ulogd_MYSQL.c b/ulogd/mysql/ulogd_MYSQL.c index 1dcd3c4..e158814 100644 --- a/ulogd/mysql/ulogd_MYSQL.c +++ b/ulogd/mysql/ulogd_MYSQL.c @@ -1,15 +1,22 @@ -/* ulogd_MYSQL.c, Version $Revision: 1.2 $ +/* ulogd_MYSQL.c, Version $Revision: 1.3 $ * * ulogd output plugin for logging to a MySQL database * * (C) 2000 by Harald Welte * This software is distributed under the terms of GNU GPL * - * $Id: ulogd_MYSQL.c,v 1.2 2001/02/16 18:07:52 laforge Exp $ + * $Id: ulogd_MYSQL.c,v 1.3 2001/05/17 15:06:58 laforge Exp $ * - * 15.5.2001, Alex Janssen : + * 15 May 2001, Alex Janssen : * Added a compability option for older MySQL-servers, which * don't support mysql_real_escape_string + * + * 17 May 2001, Alex Janssen : + * Added the --with-mysql-log-ip-as-string feature. This will log + * IP's as string rather than an unsigned long integer to the database. + * See ulogd/doc/mysql.table.ipaddr-as-string as an example. + * BE WARNED: This has _WAY_ less performance during table searches. + * */ #include @@ -85,6 +92,8 @@ static int _mysql_output(ulog_iret_t *result) struct _field *f; ulog_iret_t *res; + char *tmpstr; + stmt_ins = stmt_val; for (f = fields; f; f = f->next) { @@ -122,6 +131,23 @@ static int _mysql_output(ulog_iret_t *result) sprintf(stmt_ins, "%u,", res->value.ui16); break; case ULOGD_RET_IPADDR: +#ifdef IP_AS_STRING + *stmt_ins++ = '\''; + tmpstr = inet_ntoa(ntohl(res->value.ui32)); +#ifdef OLD_MYSQL + mysql_escape_string(stmt_ins, tmpstr, + strlen(tmpstr)); +#else + mysql_real_escape_string(dbh, stmt_ins, + tmpstr, + strlen(tmpstr)); +#endif /* OLD_MYSQL */ + stmt_ins = stmt + strlen(stmt); + sprintf(stmt_ins, "',"); + break; +#endif /* IP_AS_STRING */ + /* EVIL: fallthrough when logging IP as + * u_int32_t */ case ULOGD_RET_UINT32: sprintf(stmt_ins, "%u,", res->value.ui32); break; -- cgit v1.2.3