LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-03-2012, 07:04 AM   #16
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,948

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524

> i want to write a routine that can read ip address from the peerbuf

You may, but why? (Use inet_aton if you want to convert it to binary format.)

> and log to a different log file

You have already been given code for that.

> ??

What is the question?

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

Original Poster
Rep: Reputation: Disabled
my question is where is this code ?
in which file??
ssize_t recvfrom (int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen);

---------- Post added 08-04-12 at 06:46 PM ----------

my question is where is this code ?
in which file??
ssize_t recvfrom (int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen);

---------- Post added 08-04-12 at 06:46 PM ----------

my question is where is this code ?
in which file??
ssize_t recvfrom (int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen);
 
Old 08-04-2012, 09:17 AM   #18
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
my question is where is this code ?
in which file??
ssize_t recvfrom (int sockfd, void *buf, size_t len, int flags,
struct sockaddr *src_addr, socklen_t *addrlen);
 
Old 08-04-2012, 10:30 AM   #19
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,948

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
That's what 'grep -r' is good for (note: bind/named consists of dozens (or hundreds) of source files)... but please try to understand: you don't need it at all, you only have to use the bit of code I gave you yesterday.
 
Old 08-04-2012, 12:56 PM   #20
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
In the log_write funcion I want to see the contents of category and pick up ip address from category buffer
so that i can log to different files using ip address .peerbuf is an array that holds the client information.this client information will have ip address.Your code is not picking the ip it is simply writing to a file

Last edited by Balvinder87; 08-05-2012 at 01:00 AM.
 
Old 08-05-2012, 06:07 AM   #21
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,948

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
The name of the file is constructed from a static part and the IP-address.
Code:
{
    char filename [512];
    FILE *f;

    sprintf (filename, "/var/log/bind-%s", peerbuff);
    f= fopen (filename, "a");
    if (f) {
        fpintf (f, "client %s%s%s%s%s%s%s%s: %s",
                peerbuf, sep1, signer, sep2, qname, sep3,
                sep4, viewname, msgbuf);
        fclose (f);
    }
}
 
Old 08-05-2012, 07:55 AM   #22
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
peerbuf is an array with other values other than ip address
we want to know the ip part only
because there are different clients configured.based on their respective ips and thier logs i want to write to different files?
so i need to know from where the ip is passed to peerbuf array?
 
Old 08-05-2012, 08:10 AM   #23
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,948

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
> peerbuf is an array with other values other than ip address

It is a character-array (aka string). The IP-address is delimited by a #hashmark. Use strchr to find it in the string.

Code:
{
    char filename [512];
    FILE *f;
    const char *p;
    size_t plen;

    p= strchr (peerbuff, '#');
    if (p) plen= p-peerbuff;
    else   plen= strlen (peerbuff);
    sprintf (filename, "/var/log/bind-%.*s", (int)plen, peerbuff);
    f= fopen (filename, "a");
    if (f) {
        fpintf (f, "client %s%s%s%s%s%s%s%s: %s",
                peerbuf, sep1, signer, sep2, qname, sep3,
                sep4, viewname, msgbuf);
        fclose (f);
    }
}

Last edited by NevemTeve; 08-05-2012 at 08:15 AM.
 
Old 08-05-2012, 08:41 AM   #24
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
thanks for the reply It was a great learning experience as i am new to linux and programming world
thanks once again will talk to you tomorrow after implementing this code.
 
Old 08-06-2012, 02:58 AM   #25
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Can we do the changes in the log_write function in order to pickup the ip address from the category buffer
and print the logs based on the respective ids
isc_log_write(ns_g_lctx, category, module, level,
"client %s%s%s: %s", peerbuf, sep, name, msgbuf);
}
 
Old 08-06-2012, 03:50 AM   #26
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,948

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
Perhaps, but a variable called 'category' is not likely to hold the IP-address.
BTW: What version of bind are you using? Tha latest is 9.9.1-P2, it doesn't have function called log_write.
 
Old 08-06-2012, 07:27 AM   #27
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
yes everything working perfectly as of now
i made a program sample.c
I Hard coded a global variable peerbuff to
char *peerbuff = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

get_ipstring ()
{
/* The code you submitted goes here */
{
char filename [512];
FILE *f;
const char *p;
size_t plen;

p= strchr (peerbuff, '#');
if (p) plen= p-peerbuff;
else plen= strlen (peerbuff);
sprintf (filename, "/var/log/bind-%.*s", (int)plen, peerbuff);
f= fopen (filename, "a");
if (f) {
fpintf (f, "client %s%s%s%s%s%s%s%s: %s",
peerbuf, sep1, signer, sep2, qname, sep3,
sep4, viewname, msgbuf);
fclose (f);
}
}

}

main ()
{
get_ipstring();
}


i need to remove the filename from my program . Just store the ip address in another string and return it and simply call the program
just help me with the way we return the string to a function and changes needed to return the ip only
Thanks in advance
Balvinder Singh
 
Old 08-06-2012, 09:39 AM   #28
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,948

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
Something like this (untested):
Code:
/* getprefix.c */

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

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 outbuff [16];

    getprefix (outbuff, sizeof (outbuff), "10.20.30.40#other", '#');
    printf ("Test1: out='%s'\n", outbuff);

    getprefix (outbuff, sizeof (outbuff), "255.255.255.255", '#');
    printf ("Test2: out='%s'\n", outbuff);

    return 0;
}
 
Old 08-07-2012, 01:28 AM   #29
Balvinder87
Member
 
Registered: Jun 2012
Location: India
Distribution: debian
Posts: 77
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
hii nevem i just tested the code it is giving the output based on your code as
Test1: out='192.168.2.4'
Test2: out='255.255.255.255'
our log output is like this way
"02-Aug-2012 16:02:54.189 client 192.168.2.4#53554: query: account.thequestionsnetwork.org IN A + (192.168.2.4)
we have to pass the string this way
"02-Aug-2012 16:02:17.941 client 192.168.2.4#37492:
based on this input the code is just printing the date and half time

Test1: out='02-Aug-2012 16:'
Test2: out='255.255.255.255'
i have another algo please help me write code for this
1.use a char *start to point to the start of the string.
2.use another char *sep to point to the start of the string
3.moving sep character by character start of the string till we reach your separator i.e. #
like this way(may be i have doubt)
while (*sep != #) {
sep++;
if (*sep = " ") { start = sep }
}
that way start will point to the last space before the #
and sep will point to the separator #
by the time the while is over r copy those contents.. to the output buff
Waiting for the C code for this
thanks
balvinder

Last edited by Balvinder87; 08-07-2012 at 02:05 AM.
 
Old 08-07-2012, 03:10 AM   #30
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,948

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
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).

PS: Why is it so bloody hard to remember using &#91;code] and &#91;/code] when pasting source?
 
  


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 10:59 AM
bind dns configuration from source in centos 5.5 rath_pan Linux - Server 2 11-19-2011 01:37 AM
Bind IP address with MAC address in squid 3 ( Source baced) gulnawaz Linux - Server 3 01-14-2010 02:25 AM
how to make bind-9.6.01 work after compiling from source code win281 Linux - Newbie 2 05-11-2009 05:33 PM
How To Install BIND From Source Giena Linux - Server 1 07-16-2007 09:23 PM


All times are GMT -5. The time now is 04:31 PM.

Main Menu
Advertisement
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