LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-07-2012, 02:13 AM   #31
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled

can you help me with the c code for the above algo?
 
Old 08-07-2012, 02:21 AM   #32
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Help me write the code for above algo i know the logic but i am learning the syntax please give me the code for that?
 
Old 08-07-2012, 02:26 AM   #33
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,776

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Can you answer my previous question:

It's still about writing into separate log-files from bind, or it's about something else (like processing bind-log with a separate program)? If the former, then simply check what the content of 'peerbuff' is (my guess is: IP#port, eg 192.168.2.4#59526, 192.168.2.4#46998), then you will know how to get the IP from it (the part before the hashmark).
 
Old 08-07-2012, 02:28 AM   #34
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
i want to write to separate file later on but at present i simply want to store ip address and print it
 
Old 08-07-2012, 02:35 AM   #35
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,776

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Very good. Now let's see the concrete specification: you have a string like '02-Aug-2012 16:02:54.189 client 192.168.2.4#53554: query: account.thequestionsnetwork.org IN A + (192.168.2.4)' and you want to cut out the IP-address. There are programming tools for that like 'cut' -- are your sure you want it in C?
 
Old 08-07-2012, 02:42 AM   #36
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
thanku

Last edited by Balvinder87; 08-08-2012 at 01:33 AM.
 
Old 08-07-2012, 03:24 AM   #37
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,776

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Code:
/* parselog.c */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

size_t getfield (char *to, size_t tomaxsize, const char *from, int nfld)
{
    int state;
    const char *p, *plim;
    const char *fldbeg;
    size_t fldlen;
    int fldfound;

    *to= '\0';

    if (!from || !*from || nfld<0) return 0;

    p= from;
    plim= from + strlen (from);
    state= 'A';
    fldfound= 0;
    fldbeg= NULL;
    fldlen= 0;

    for (; fldfound<nfld && p<plim; ++p) {
	int c= *p;

	if (state=='A') {
	    if (!isspace (c)) {
		fldbeg= p;
		state= 'B';
	    }
	} else {
	    if (isspace (c)) {
		fldlen= p-fldbeg;
		++fldfound;
		state= 'A';
	    }
	}
    }
    if (state=='B') {
	fldlen= p-fldbeg;
	++fldfound;
    }

    if (fldfound != nfld) {
	return EOF;

    } else {
	if (fldlen>tomaxsize-1) fldlen= tomaxsize-1;

	memcpy (to, fldbeg, fldlen);
	to[fldlen]= '\0';
	return 0;
    }
}

size_t getprefix (char *to, size_t tomaxsize, const char *from, char separator)
{
    const char *p;
    size_t plen;

    *to= '\0';

    if (!from || !*from) return 0;

    p= strchr (from, separator);
    if (p) plen= p-from;
    else plen= strlen (from);

    if (plen>tomaxsize-1) plen= tomaxsize-1;

    memcpy (to, from, plen);
    to[plen]= '\0';
    return plen;
}

int main (void)
{
    char tmpbuff [24];
    char outbuff [16];

    getfield (tmpbuff, sizeof (tmpbuff)
	, "2-Aug-2012 16:02:54.189 client 192.168.2.4#53554: query: account.thequestionsnetwork.org IN A + (192.168.2.4)"
	, 4);
    getprefix (outbuff, sizeof (outbuff), tmpbuff, '#');
    printf ("Test1: out='%s'\n", outbuff);

    getfield (tmpbuff, sizeof (tmpbuff)
	, "18-Jul-2012 17:18:01.909 client 192.168.2.4#46998: query: apis.google.com IN A + (192.168.2.4)"
	, 4);
    getprefix (outbuff, sizeof (outbuff), tmpbuff, '#');
    printf ("Test2: out='%s'\n", outbuff);

    return 0;
}
It consists of two functions: first 'getfield' cuts the specified field (#4: IP#port) from the line into tmpbuff, then 'getprefix' gets to 'IP' into outbuff.

Note: It was an honor to be allowed to write your programs, but sadly I don't have more free-time to do that, so you are on your own from now.

Last edited by NevemTeve; 08-07-2012 at 04:00 AM.
 
Old 08-07-2012, 04:11 AM   #38
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
it was really a great experience learning from you sir i will not ask you to write the full programs in future but will put my doubts and hope you will reply soon
 
Old 08-09-2012, 12:35 AM   #39
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
can you tell me which file in bin/named is responsible for logging to the /var/log/filename
now i need to append the ip address to the log file name

if the log file is named_query.log.I need to have the file as named_query.log.192.168.132.1 and it should be created in the same place i.e. in /var/log/
in client.c they call isc_log_write so we need to see what that calls internally and see how that maps to log_write
then in isc_log_write in logconf.c, when we get peerbuf as one of the parameters, we need to call getip and log to a different file.
How can we do that any hint?

Last edited by Balvinder87; 08-09-2012 at 12:36 AM.
 
Old 08-09-2012, 02:14 AM   #40
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,776

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Check these msgs:
http://www.linuxquestions.org/questi...0/#post4743976
http://www.linuxquestions.org/questi...ml#post4746345
 
Old 08-09-2012, 05:56 AM   #41
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
will you please elaborate the behaviour of the isc__log_write function?
how this functin is writing logs?
this is the function?

isc_log_write(ns_g_lctx, category, module, level,
"client %s%s%s%s%s%s%s%s: %s",
peerbuf, sep1, signer, sep2, qname, sep3,
sep4, viewname, msgbuf);
 
Old 08-09-2012, 10:56 PM   #42
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
hey nevem its really important for me to complete this task by today.i have added a plugin in bind9 source which gets the ip address from the output string now in the final string.based on this ip i need to append it to filename( if my file name is named_querylog then the cooresponding logs of the ip will be in the file name as named_query.log.192.168.132.1
so i need to find out the behaviour of isc_log_write can you help me find out what is happening in this function?
what context it passes to log_write in the case where it logs peerbuf?
i am using bind 9.7.3 please reply its really important?
 
Old 08-09-2012, 11:21 PM   #43
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,776

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
You don't have to trace and modify the existing function, just add a few line to create client-specific file-name, open it, write the log-record, then close the file. And, as it happens, you are already given code to do that.
http://www.linuxquestions.org/questi...ml#post4746345
That's what you have to add after/before the calling of isc_log_write.
 
Old 08-09-2012, 11:44 PM   #44
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
I guess the code that you have given is writing the logs of clients to different files
i need to pick up the ip address from peerbuf and based on that ip i need to write the log in the files as
filename.ipaddress?
will your code behave that way?

Last edited by Balvinder87; 08-09-2012 at 11:56 PM.
 
Old 08-10-2012, 02:26 AM   #45
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,776

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Indeed, it does.
 
  


Reply

Tags
bind


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dns bind source Balvinder87 Programming 1 08-02-2012 09:59 AM
bind dns configuration from source in centos 5.5 rath_pan Linux - Server 2 11-19-2011 12:37 AM
Bind IP address with MAC address in squid 3 ( Source baced) gulnawaz Linux - Server 3 01-14-2010 01:25 AM
how to make bind-9.6.01 work after compiling from source code win281 Linux - Newbie 2 05-11-2009 04:33 PM
How To Install BIND From Source Giena Linux - Server 1 07-16-2007 08:23 PM


All times are GMT -5. The time now is 09:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration