C++ - read and write pcapng files without libpcap - pcap-ng

I'm interested in reading and writing pcapng files without using libpcap or WinPcap. Anyone knows how to do it?

I can recommend a C-library which does that, it's called LightPcapNg and apparently PcapPlusPlus is using it to have a cleaner C++ wrapper.
Since you're interested in C++, here is a code snippet of how to read a pcap-ng file using PcapPlusPlus:
#include <PcapFileDevice.h>
void readAndWritePcapNg(char* inputFileName, char* outputFileName)
{
// reader instance
PcapNgFileReaderDevice readerDev(inputFileName);
// writer instance
PcapNgFileWriterDevice writerDev(outputFileName);
// open reader and writer
readerDev.open();
writerDev.open();
RawPacket rawPacket;
// read packets from file
while (readerDev.getNextPacket(rawPacket))
{
Packet packet(&rawPacket);
// do whatever you want with the packet
....
....
// write the packet to the output file
writerDev.writePacket(rawPacket);
}
// close reader and writer
readerDev.close();
writerDev.close();
}

Related

file handling in capl programming

please give me some hint how to perform File handling in CAPL programming.
How to open and how to access the file , what and which types of functions are available for file handling.
give some suggestion regarding this topics.
Thank you.
CAPL syntax provides you with some functions. To open a file stream for reading, use openFileRead();.
You may use function fileGetString() to read lines from such file. A code snippet might look like
char input[30] = "test.txt"
int bufferLength = 256;
char buffer[bufferLength];
dword fh;
fh = openFileRead(input,0);
while(fileGetString(buffer,bufferLength,fh)!=0) {
// do whatever
}
Please put some more effort next time: this is not how StackOverflow works.

How do I use the CLI interface of FFMpeg from a static build?

I have added this (https://github.com/kewlbear/FFmpeg-iOS-build-script) version of ffmpeg to my project. I can't see the entry point to the library in the headers included.
How do I get access to the same text command based system that the stand alone application has, or an equivalent?
I would also be happy if someone could point me towards documentation that allows you to use FFmpeg without the command line interface.
This is what I am trying to execute (I have it working on windows and android using the CLI version of ffmpeg)
ffmpeg -framerate 30 -i snap%03d.jpg -itsoffset 00:00:03.23333 -itsoffset 00:00:05 -i soundEffect.WAV -c:v libx264 -vf fps=30 -pix_fmt yuv420p result.mp4
Actually you can build ffmpeg library including the ffmpeg binary's code (ffmpeg.c). Only thing to care about is to rename the function main(int argc, char **argv), for example, to ffmpeg_main(int argc, char **argv) - then you can call it with arguments just like you're executing ffmpeg binary. Note that argv[0] should contain program name, just "ffmpeg" should work.
The same approach was used in the library VideoKit for Android.
To do what you want, you have to use your compiled FFmpeg library in your code.
What you are looking for is exactly the code providing by FFmpeg documentation libavformat/output-example.c (that mean AVFormat and AVCodec FFmpeg's libraries in general).
Stackoverflow is not a "do it for me please" platform. So I prefer explaining here what you have to do, and I will try to be precise and to answer all your questions.
I assume that you already know how to link your compiled (static or shared) library to your Xcode project, this is not the topic here.
So, let's talk about this code. It creates a video (containing video stream and audio stream randomly generated) based on a duration. You want to create a video based on a picture list and sound file. Perfect, there are only three main modifications you have to do:
The end condition is not reaching a duration, but reaching the end of your file list (In code there is already a #define STREAM_NB_FRAMES you can use to iterate over all you frames).
Replace the dummy void fill_yuv_image by your own method that load and decode image buffer from file.
Replace the dummy void write_audio_frame by your own method that load and decode the audio buffer from your file.
(you can find "how to load audio file content" example on documentation starting at line 271, easily adaptable for video content regarding documentation)
In this code, comparing to your CLI, you can figure out that:
const char *filename; in the main should be you output file "result.mp4".
#define STREAM_FRAME_RATE 25 (replace it by 30).
For MP4 generation, video frames will be encoded in H.264 by default (in this code, the GOP is 12). So no need to precise libx264.
#define STREAM_PIX_FMT PIX_FMT_YUV420P represents your desired yuv420p decoding format.
Now, with these official examples and related documentation, you can achieve what you desire. Be careful that there is some differences between FFmpeg's version in these examples and current FFmpeg's version. For example:
st = av_new_stream(oc, 1); // line 60
Could be replaced by:
st = avformat_new_stream(oc, NULL);
st->id = 1;
Or:
if (avcodec_open(c, codec) < 0) { // line 97
Could be replaced by:
if (avcodec_open2(c, codec, NULL) < 0) {
Or again:
dump_format(oc, 0, filename, 1); // line 483
Could be replaced by:
av_dump_format(oc, 0, filename, 1);
Or CODEC_ID_NONE by AV_CODEC_ID_NONE... etc.
Ask your questions, but you got all the keys! :)
MobileFFMpeg is an easy to use pod for the purpose. Instructions on how to use MobileFFMpeg at: https://stackoverflow.com/a/59325680/1466453
MobileFFMpeg gives a very simple method for translating ffmpeg commands to your IOS objective-c program.
Virtually all ffmpeg commands and switches are supported. However you have to get the pod with appropriate license. e.g min-gpl will not give you features of libiconv. libiconv is convered in vidoe, gpl and full-gpl licenses.
Please highlight if you have specific issues regarding use of MobileFFMpeg

How to generate multiple reports in Grails using Export plugin?

I am using the Export plugin in Grails for generating PDF/Excel report. I am able to generate single report on PDF/Excel button click. But, now I want to generate multiple reports on single button click. I tried for loop, method calls but no luck.
Reference links are ok. I don't expect entire code, needs reference only.
If you take a look at the source code for the ExportService in the plugin you will notice there are various export methods. Two of which support OutputStreams. Using either of these methods (depending on your requirements for the other parameters) will allow you to render a report to an output stream. Then using those output streams you can create a zip file which you can deliver to the HTTP client.
Here is a very rough example, which was written off the top of my head so it's really just an idea rather than working code:
// Assumes you have a list of maps.
// Each map will have two keys.
// outputStream and fileName
List files = []
// call the exportService and populate your list of files
// ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
// exportService.export('pdf', outputStream, ...)
// files.add([outputStream: outputStream, fileName: 'whatever.pdf'])
// ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream()
// exportService.export('pdf', outputStream2, ...)
// files.add([outputStream: outputStream2, fileName: 'another.pdf'])
// create a tempoary file for the zip file
File tempZipFile = File.createTempFile("temp", "zip")
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tempZipFile))
// set the compression ratio
out.setLevel(Deflater.BEST_SPEED);
// Iterate through the list of files adding them to the ZIP file
files.each { file ->
// Associate an input stream for the current file
ByteArrayInputStream input = new ByteArrayInputStream(file.outputStream.toByteArray())
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(file.fileName))
// Transfer bytes from the current file to the ZIP file
org.apache.commons.io.IOUtils.copy(input, out);
// Close the current entry
out.closeEntry()
// Close the current input stream
input.close()
}
// close the ZIP file
out.close()
// next you need to deliver the zip file to the HTTP client
response.setContentType("application/zip")
response.setHeader("Content-disposition", "attachment;filename=WhateverFilename.zip")
org.apache.commons.io.IOUtils.copy((new FileInputStream(tempZipFile), response.outputStream)
response.outputStream.flush()
response.outputStream.close()
That should give you an idea of how to approach this. Again, the above is just for demonstration purposes and isn't production ready code, nor have I even attempted to compile it.

FTP client code in BlackBerry

I have been trying to download a file from an FTP server to the sdcard of the simulator through a FTP client. I have not been able to find a reference for how to code an FTP client. Can anyone please help or provide me a link where I can get a sample code of how to download a file using FTP? When I was working in an Android environment, I made use of an external jar file for FTP, but in Blackberry that same jar file is of no use.
Here is a sample code..
public final class UploadScreen extends MainScreen
{
File f;
public UploadScreen()
{
setTitle("File Upload");
SimpleFTP ftp=new SimpleFTP();
try {
ftp.connect("14.97.146.41/xml/", 21);
ftp.bin();
f=new File("asd");
boolean a=ftp.stor(f);
if(a)
{
Dialog.alert("Done");
}
else
{
Dialog.alert("Fail");
}
ftp.disconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Here simpleftp is a jar file that i have downloaded from "http://www.jibble.org/simpleftp/"
Now here when i run this prog. it doesn't even run and crashes saying Module "SimpleFTP" not found.I have added external jar file to the project but still its not working. I read about preverfiying the jar files but when i try to do that from command prompt, it says
Error preverifying class org.jibble.simpleftp.SimpleFTP
java/lang/NoClassDefFoundError: java/lang/Object
Please help this code is fro uploading but i have same problems for downloading
BlackBerry devices use Java-ME, and not Java-SE. This is in contrast to Android devices, which are able to make use of unmodified Java-SE libraries.
At the language level, Java-ME requires Java 1.3 language compliance - this means no generics, no assert, no enums. Most modern Java libraries use at least one of those features, but maybe you got lucky with SimpleFTP.
At the API level, Java-ME does not use the standard networking classes from Java-SE. Instead you will have to use Connector and cast the result to a StreamConnection. This is substantially different than what a Java-SE library will be doing.

Blackberry - Programmatically extract/open zip file

I have looked online with mixed results, but is there a way to programmatically extract a zip file on the BB? Very basic my app will display different encrypted file types, and those files are delivered in a zip file. My idea was to have the user browse to the file on their SDCard, select it, and I extract what i need as a stream from the file. is this possible?
Use GZIPInputStream
Example:
try
{
InputStream inputStream = httpConnection.openInputStream();
GZIPInputStream gzis = new GZIPInputStream(inputStream);
StringBuffer sb = new StringBuffer();
char c;
while ((c = (char)gzis.read()) != -1)
{
sb.append(c);
}
String data = sb.toString();
gzis.close();
}
catch(IOException ioe)
{
}
Just two things:
In BB API there are only GZip and ZLib support, and no multiple files compression support, so it's not possible to compress several files and extract only one of them.
Up to my experience, such functionality will fly on simulator, but may be really performance-killing on real device
See How to retrieve data from a attached zip file in Blackberry application?
PS Actually you can implement custom multi-entries stream and parse it after decompress, but that seems to be useless, if you want this archive format to be supported in other applications.

Resources