如何获取网络缓冲区并将其传递到需要 C 中的 FILE 的函数中
我希望能够通过网络套接字从 HTTP 服务器(A jpeg)下载文件。然后,我需要将下载的文件传递到 c-jpeg-steganography http://code。 google.com/p/c-jpeg-steganography/。我可以使用 libcurl 下载文件,然后将文件名传递到库中,但如果不需要,我宁愿不这样做。我可以下载该文件,然后轻松地将其直接传递到 c-jpeg-steganography 中吗?有没有一种简单的方法可以修改 c-jpeg-steganography 库以使其工作?写入临时文件不是一个坏方法吗?
我是个 C 菜鸟……请放轻松。我的大部分经验都是使用那些让我作弊并为我完成所有工作的语言。
I am looking to be able to download a file over a network socket from an HTTP server (A jpeg). I then need to pass the downloaded file into c-jpeg-steganography http://code.google.com/p/c-jpeg-steganography/ . I can use libcurl to download the file and then pass the filename into the library, but I would prefer to not do that if I don't have to. Can I download the file and then pass it directly into c-jpeg-steganography easily? Is there an easy way to modify the c-jpeg-steganography libraries to work? Is the writing to a temporary file not a bad way to do this?
I am very much a C noob... please go easy. Most of my experience is with languages that let me cheat and do all the work for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
隐写术网站没有提供 AFAICS 的 API 详细信息,这很麻烦。
但是,从您的问题来看,似乎有一个隐写函数需要一个打开的 FILE * (您永远无法处理 FILE * ),其中包含未修改的图像,大概是您试图在图像中隐藏的信息。在这种情况下,您可以安排通过 libcurl 将文件下载到打开的文件中(可能没有名称);然后您可以倒回该 FILE * 并将其传递给隐写库。
下载该库
后,提供的两个主要函数是:
steganolab_encode
steganolab_decode
由于函数需要文件名,因此您必须提供文件名。或者您将不得不重写代码以获取您想要的任何内容 - 缓冲区或打开的文件流。
(旁白:代码坚持使用古老的非标准标头
来获取size_t
的定义。如果您替换每个,它会编译为对象使用
引用
(或"malloc.h"
),理论上可以编译;如果唯一需要的声明是size_t
,则使用
。)The steganography site doesn't give the API details AFAICS, which is a nuisance.
However, judging from your question, it appears that there is a steganographic function that takes an open
FILE *
(you never get to deal withFILE
) which contains the unmodified image, and presumably the information you are trying to conceal in the image. In that case, you can arrange to download the file vialibcurl
into an open file (which may not have a name); you can then rewind thatFILE *
and pass it to the steganography library.Having downloaded the library, the two main functions provided are:
steganolab_encode
steganolab_decode
Since the functions expect file names, you will have to provide file names. Or you will have to rewrite the code to take whatever it is you have in mind - a buffer or an open file stream.
(Aside: the code insists on using the archaic and non-standard header
<malloc.h>
to obtain a definition ofsize_t
. It compiles to object if you replace each reference to<malloc.h>
(or"malloc.h"
) with<stdlib.h>
; it might in theory compile with<stddef.h>
if the only needed declaration issize_t
.)没有标准方法可以假装内存缓冲区是一个文件,因此您实际上仅限于您提出的两种解决方案之一:
我知道我最初会这样做,这是第一个选择。这是最简单的方法(如最快上市)。
从对源代码的检查来看,将其更改为进程内存而不是文件所涉及的工作并不简单。
encode
、decode
和estimate
函数都调用一个worker
超级函数,该函数接收文件名、打开反过来,它又将文件句柄传递给其他函数。这是可行的,但工作量比仅使用临时文件要大得多(尽管请记住,它只需要完成一次,然后生成的代码将可供全世界使用)。
There's no standard way to pretend that a memory buffer is a file so you really are limited to one of the two solutions you posit:
I know the way I'd initially do it, that's the first option. That's the easiest way (as in quickest-to-market).
From examination of the source, the work involved in changing it to process memory rather than a file is non-trivial.
The
encode
,decode
andestimate
functions all call a singleworker
uber-function which receives the file name, opens it and, in turn, passes the file handle around quite a bit to other functions.It's doable but the effort is substantially larger than just using a temporary file (although keep in mind it would only have to be done once, and the resultant code would then be available for all the world to use).