小编Roh*_*hit的帖子

libssh:简单实现中丢失了内存

我正在尝试一个非常简单的实现,libssh但valgrind显示内存泄漏.

代码是:

#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main()
{
        ssh_session my_ssh_session = ssh_new();
        int port = 22;
        int rc, state;
        const char *ip = "192.168.125.241";
        char *password;
        if (my_ssh_session == NULL)
                exit(-1);
        ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, ip);
        ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
        rc = ssh_connect(my_ssh_session);
        if (rc != SSH_OK)
        {
                fprintf(stderr, "Error connecting to localhost: %s\n",
                ssh_get_error(my_ssh_session));
                exit(-1);
        }

        state = ssh_is_server_known(my_ssh_session);
        if(state == SSH_SERVER_KNOWN_OK)
                printf("already added\n");
        else
                printf("require addition\n");

        rc = ssh_userauth_password(my_ssh_session, "rohit", "password");
        if …
Run Code Online (Sandbox Code Playgroud)

c c++ valgrind memory-leaks libssh

5
推荐指数
1
解决办法
337
查看次数

将 Excel 中的所有列设置为文本

我正在 VB.NET 上开发一个非常基本的应用程序。

功能:导入一个分隔的TXT文件,并执行“TextToColumn”,Column-AutoFit,将所有列的格式设置为TEXT,最后另存为Excel。

我面临的挑战:我能够对所有内容进行编码,除了所有列都未格式化为文本。因此,包含 16 位数字的列将以科学记数法保存。

代码:

Imports Excel = Microsoft.Office.Interop.Excel
Imports System.IO
Public Class Form1
    Dim xlApp As New Excel.Application
    Dim xlWorkBook As Excel.Workbook
    Dim xlWorkSheet As Excel.Worksheet
    Dim style As Microsoft.Office.Interop.Excel.Style
    Dim strFileName As String
    Dim pathFile As String
    Dim FileNameOnly As String
    Dim saveAsPath As String
    Dim delimiterType As String
    Dim fd As OpenFileDialog = New OpenFileDialog()
    Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Button2.Text = "Browse A Delimited File"
        Button1.Text = "Format …
Run Code Online (Sandbox Code Playgroud)

vb.net excel

2
推荐指数
1
解决办法
3万
查看次数

套接字编程:connect() 因 IP 不存在而挂起

以下是创建套接字连接的代码,如果 IP 存在,则返回正套接字描述符,而如果 IP 不存在,则它会卡在例程中connect()

Connection::Connection(string& ip) : sock(0), status(0), conn(0){
    struct sockaddr_in sin;

    sock = socket(AF_INET, SOCK_STREAM, 0);//socket() returns -1 on failure.
    sin.sin_family = AF_INET;
    sin.sin_port = htons(22);
    sin.sin_addr.s_addr = inet_addr(ip.c_str());
    cout << "sock: " << sock << endl;
    //fcntl(sock, F_SETFL, O_NONBLOCK);
    if(sock != -1){
        conn = connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in));
        cout << "conn: " << conn << endl;
        if ( conn != 0){
            status = -2;
        }
    }
    else{
        status = -1;
    }
}
Run Code Online (Sandbox Code Playgroud)

出于调试目的,我已将和放在 …

c++ sockets network-programming

1
推荐指数
1
解决办法
2838
查看次数

标签 统计

c++ ×2

c ×1

excel ×1

libssh ×1

memory-leaks ×1

network-programming ×1

sockets ×1

valgrind ×1

vb.net ×1