gpt4 book ai didi

c - 绑定(bind)失败并出现无效参数错误

转载 作者:行者123 更新时间:2023-11-30 19:22:00 30 4
gpt4 key购买 nike

这是最终的代码,没有编译错误,但我仍然收到“无效参数”错误!! =================================================== =====================

包括

using namespace std;
#include <sys/socket.h>
#include <linux/x25.h>
#include <stdio.h>

#include <sys/types.h>
#include <linux/socket.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <string.h>
#include <errno.h>



int main(int argc,char **argv,char **envp) {

int x25_socket;
struct sockaddr_x25 x25_address = {0};

char x25_host[] ="10.0.0.1";
const char name[] = "my name";

x25_address.sx25_family = AF_X25;

x25_socket = socket(AF_X25, SOCK_SEQPACKET, 0);
if (x25_socket == -1)
cout << "error in create socket" << endl;

strncpy(x25_address.sx25_addr.x25_addr, x25_host, 16);


int bindNumber = bind(x25_socket,(struct sockaddr *)&x25_address,sizeof(x25_address));
if (bindNumber == -1)
{
perror("error in bind ---");
cout << "error in bind" << endl;
}

cout << write(x25_socket, name, 2) << endl;

return 0;
}

最佳答案

试试这个:

int main(int argc, char **argv, char **envp)
{
struct sockaddr_x25 x25_address = {0};
char x25_host[] = "10.0.0.1"
const char name[] = "my name";

int x25_socket = socket(AF_X25, SOCK_SEQPACKET, 0);
if(x25_socket == -1)
{
printf(" error in create socket");
}

x25address.safamily = AF_X25;
strncpy(x25_address.sx25_addr.x25_addr, x25_host, 16);

int bindNumber = bind(x25_socket, (struct sockaddr*)&x25_address, sizeof(x25_address));
if (bindNumber == -1)
{
perror("error in bind ---");
}

return 0;
}

关于c - 绑定(bind)失败并出现无效参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18774232/

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