gpt4 book ai didi

c - 如何通过 ssl 和套接字发送目标文件 .o

转载 作者:太空宇宙 更新时间:2023-11-04 03:04:04 25 4
gpt4 key购买 nike

我需要从我的客户端向服务器程序发送一个对象文件。我尝试读取文件,将其存储到缓冲区中,通过 ssl 发送缓冲区并写入服务器程序中的文件。这不适用于 .o 文件。这是输出的 ELF。

这是我的一些代码

读取文件

void readFile(char filename[])  
{
FILE *input_file;
char line[BUFSIZ];

input_file = fopen(filename, "r");

if(input_file == NULL){
printf("cannot open input_file '%s'\n", filename );
exit(EXIT_FAILURE);
}

while (fgets(line,sizeof line, input_file) != NULL) {

for(int i = 0; i<strlen(line); i++){
current_file[i] = line[i];
}
}}

客户端发送文件

    readFile(filename);
ctx = InitCTX();
server = OpenConnection(hostname, atoi(portnum));
ssl = SSL_new(ctx); /* create new SSL connection state */
SSL_set_fd(ssl, server); /* attach the socket descriptor */
if ( SSL_connect(ssl) == FAIL ) /* perform the connection */
ERR_print_errors_fp(stderr);
else
{

printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
ShowCerts(ssl); /* get any certs */
SSL_write(ssl, current_file, strlen(current_file));

是否可以读取目标文件,然后将其存储在缓冲区中?

还有其他方法可以发送这些文件吗?

最佳答案

.o 文件没有任何“特殊”之处,它只是存储在磁盘上的一系列字节,并分配有文件名和扩展名。

我的猜测是您需要以不同于现有文件的方式处理文件,因为它将是二进制数据。它不会有您当前正在阅读的行的“通常”概念。

我会看看以下内容: http://www.linuxquestions.org/questions/programming-9/c-howto-read-binary-file-into-buffer-172985/

尝试先在本地读取然后写入文件,以检查文件是否在传输过程中或在本地 I/O 例程中损坏?

关于c - 如何通过 ssl 和套接字发送目标文件 .o,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7903447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com