Obtain filenames from a directory (Pcap program)

unix

    Next

  • 1. Localization & Internationalization for C Application on UNIX
    Hi, What are the options available for Localization & Internationalization for C applications on UNIX platform? I came across getcats & gettext and none of them is POSIX compliant and not even standardized. Which of these is the preferred once? Thanks, Amit
  • 2. Difference between memcpy and strncpy
    Dear Friends Can you explain the difference between memcpy and strncpy function Actually , please classify function by usage Thanks
  • 3. Link C++ and C object files together
    I have a small cross-platform networking library which I wrote in C. I wrote it in C because I want it to be as portable as possible (I'll be using it on a microcontroller eventually). Anyway, I'm writing a program that uses the networking library, and the program will be a fancy GUI program written in C++ using wxWidgets. I'd like to ask if I'm going the correct way about compiling my entire program: First make object files: gcc -c *.c g++ -c *.cpp Then to link the object files: g++ *.o -o my_prog Does that look OK?
  • 4. Getting time of creating shared memory segment
    Hi, The structure shmid_ds contains the following members: --------------------------------------- .... time_t shm_atime last shmat time time_t shm_dtime time of last shmdt time_t shm_ctime time of last change by shmctl ---------------------------------------- That strucrure doesn't contain time of creating shared memory segment. Is there any way to get time of creating shared memory segment.? Thanks, Alex Vinokur

Obtain filenames from a directory (Pcap program)

Postby lancer6238@yahoo.com » Thu, 20 Nov 2008 10:11:10 GMT

Hi all,
I'm writing a program using libpcap, and I have multiple pcap files in
a folder that I want to capture.

I currently have

handle = pcap_open_offline("/data/traffic/pcap1.pcap", errbuf");

which works fine since pcap_open_offline() takes in a filename.
However, I want to process multiple pcap files from the directory /
data/traffic/ at once. Is there a way to do that?

Thank you.

Regards,
Rayne

Re: Obtain filenames from a directory (Pcap program)

Postby Barry Margolin » Thu, 20 Nov 2008 13:27:06 GMT

In article 
< XXXX@XXXXX.COM >,




Like I just said in comp.protocols.tcp-ip:

man -s 3 glob

-- 
Barry Margolin,  XXXX@XXXXX.COM 
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: Obtain filenames from a directory (Pcap program)

Postby lancer6238@yahoo.com » Thu, 20 Nov 2008 15:52:19 GMT

The glob function does give me the filenames of all the files in the
directory, but I still have trouble getting pcap_open_offline to read
from all the pcap files.

I now have

glob_t globbuf;
glob("/data/traffic/*.pcap", GLOB_ERR, NULL, &globbuf);
handle = pcap_open_offline(*(globbuf.gl_pathv), errbuf);

However, pcap_open_offline would only process the first pcap file in
the globbuf.gl_pathv list. How do I get pcap_open_offline to process
all files in the directory? Or do I need to use another function?

Thank you.

Re: Obtain filenames from a directory (Pcap program)

Postby Giorgos Keramidas » Fri, 21 Nov 2008 09:04:57 GMT

On Tue, 18 Nov 2008 17:11:10 -0800 (PST),



Let the shell do the 'work' for you:

    int
    main(int argc, char *argv[])
    {
        int k;

        for (k = 1; k < argc; k++)
            dostuff(argv[k]);
        return 0;
    }

If you don't have a particularly good reason for iterating through the
directory tree in C, then it should be both fine and easier to make
things like

    ./a.out /home/keramida/capfiles/*

and iterating through argv[] is a good way to do that :D


Re: Obtain filenames from a directory (Pcap program)

Postby Barry Margolin » Fri, 21 Nov 2008 14:02:08 GMT

In article 
< XXXX@XXXXX.COM >,




globbuf.gl_pathv is an array of filenames, you have to write a loop:

for (char **path = globbuf.gl_pathv; path++; *path) {
  handle = pcap_open_offline(*path, errbuf);
  ...
}

-- 
Barry Margolin,  XXXX@XXXXX.COM 
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Similar Threads:

1.Obtain filenames from a directory (Pcap program)

Hi all,
I'm writing a program using libpcap, and I have multiple pcap files in
a folder that I want to capture.

I currently have

handle = pcap_open_offline("/data/traffic/pcap1.pcap", errbuf");

which works fine since pcap_open_offline() takes in a filename.
However, I want to process multiple pcap files from the directory /
data/traffic/ at once. Is there a way to do that?

Thank you.

Regards,
Rayne

2.Call AcuCobol Program in Unix from Windows and obtain the output

Hi, sorry for my english and my Cobol skills. I have a little question,
can i run an Acucobol Program what resides in a Unix Server from a
command line of a PC running windows 2000, and obtain/view the output (
like a DOS command, but using some Cobol Exe ) ?


Thanks, 

Mart Olivares
Cdoba - Argentina

3.Want to find duplicate file entries in two directories - by filename only

Anonymous wrote:
> "RG" == Robert Glueck < XXXX@XXXXX.COM >:
> RG> I have two directories, dir A (6000 entries) and dir B (1000 
> RG> entries).  Some of the entries in dir B are duplicates of 
> RG> entries in dir A (by name only, creation dates and sizes 
> RG> differ).  I want to find out which of the entries in dir B 
> RG> are duplicated in dir A and then selectively delete the 
> RG> duplicates in dir B.  How would I do this?
> 
> Michael A. Gumienny has written a perl script, called 'finddups', that
> might help you.
> 

Thanks.  I tried the finddups script but it generated a lot 
of errors.  It just doesn't seem to be suited to solving my 
particular problem.

Joe Beanfish's suggestion works perfectly for me (slightly 
amended)

ls dir1 >/tmp/dir1.lst
ls dir2 >/tmp/dir2.lst
sort /tmp/dir1.lst /tmp/dir2.lst|uniq -d >/tmp/dups.lst

but it isn't complete.  I wind up with a text file that 
lists all of the duplicate files in dir1.  I now want to 
move all of these files to a directory (e.g. /tmp/dups) from 
which I can delete them all.

Hence, I need a shell script that opens the file dups.lst 
(which contains nothing but filenames, separated by carriage 
returns) and parses the list line by line, executing 
something like

mv filename /tmp/dup

for every item in the list.  That should be very simple. 
Unfortunately, I'm totally ignorant of bash shell scripting. 
  Can anyone help?  Thanks.

Robert

4.Want to find duplicate file entries in two directories - by filename only

"RG" == Robert Glueck < XXXX@XXXXX.COM >:
RG> I have two directories, dir A (6000 entries) and dir B (1000 
RG> entries).  Some of the entries in dir B are duplicates of 
RG> entries in dir A (by name only, creation dates and sizes 
RG> differ).  I want to find out which of the entries in dir B 
RG> are duplicated in dir A and then selectively delete the 
RG> duplicates in dir B.  How would I do this?

Michael A. Gumienny has written a perl script, called 'finddups', that
might help you.

5.Want to find duplicate file entries in two directories - by filename only

I have two directories, dir A (6000 entries) and dir B (1000 
entries).  Some of the entries in dir B are duplicates of 
entries in dir A (by name only, creation dates and sizes 
differ).  I want to find out which of the entries in dir B 
are duplicated in dir A and then selectively delete the 
duplicates in dir B.  How would I do this?

Thanks for your help.

Robert

6. Want to find duplicate file entries in two directories - by filename

7. Identifying if object {filename|directoryname} is file or directory when using diff -sqdr

8. "ls" command to display only filenames without directory path



Return to unix

 

Who is online

Users browsing this forum: No registered users and 69 guest