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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
08-07-2012, 02:13 AM
|
#31
|
|
Member
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 76
Original Poster
Rep: 
|
can you help me with the c code for the above algo?
|
|
|
|
08-07-2012, 02:21 AM
|
#32
|
|
Member
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 76
Original Poster
Rep: 
|
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?
|
|
|
|
08-07-2012, 02:26 AM
|
#33
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,038
|
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).
|
|
|
|
08-07-2012, 02:28 AM
|
#34
|
|
Member
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 76
Original Poster
Rep: 
|
i want to write to separate file later on but at present i simply want to store ip address and print it
|
|
|
|
08-07-2012, 02:35 AM
|
#35
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,038
|
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?
|
|
|
|
08-07-2012, 02:42 AM
|
#36
|
|
Member
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 76
Original Poster
Rep: 
|
thanku
Last edited by Balvinder87; 08-08-2012 at 01:33 AM.
|
|
|
|
08-07-2012, 03:24 AM
|
#37
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,038
|
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.
|
|
|
|
08-07-2012, 04:11 AM
|
#38
|
|
Member
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 76
Original Poster
Rep: 
|
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
|
|
|
|
08-09-2012, 12:35 AM
|
#39
|
|
Member
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 76
Original Poster
Rep: 
|
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.
|
|
|
|
08-09-2012, 02:14 AM
|
#40
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,038
|
|
|
|
|
08-09-2012, 05:56 AM
|
#41
|
|
Member
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 76
Original Poster
Rep: 
|
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);
|
|
|
|
08-09-2012, 10:56 PM
|
#42
|
|
Member
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 76
Original Poster
Rep: 
|
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?
|
|
|
|
08-09-2012, 11:21 PM
|
#43
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,038
|
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.
|
|
|
|
08-09-2012, 11:44 PM
|
#44
|
|
Member
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 76
Original Poster
Rep: 
|
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.
|
|
|
|
08-10-2012, 02:26 AM
|
#45
|
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,038
|
Indeed, it does.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:16 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|