现在的位置: 首页 > 综合 > 正文

【OpenSSL】内存BIO

2019年05月15日 ⁄ 综合 ⁄ 共 806字 ⁄ 字号 评论关闭

代码

头文件

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <openssl/buffer.h>
    #include <openssl/bio.h>

#记得包含openssl/buffer.h,否则BUF_MEM定义未知

测试代码

int main(int argc, char * argv[])
{
    BIO_METHOD * memory_method = BIO_s_mem();
    BIO * mem = BIO_new(memory_method);
    BIO_puts(mem, "hello,world");
    BUF_MEM * bufptr = 0;
    BIO_get_mem_ptr(mem, &bufptr);
    printf("bufptr->data: [%s]\n", bufptr->data);
    BIO_free(mem);
    // the following code is fault, 
    // as bufptr is clear-ed already.
    // printf("bufptr->data: [%s]\n", bufptr->data);
    return 0;
}

备注

Use the printf() function.

//这里写代码片
int x = 0;
  1. BIO_f_*前缀里面的f表示filter类型的bio操作
  2. BIO_s_*前缀里面的s表示source/sink类型的bio操作

抱歉!评论已关闭.