-1

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

包括

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;
}
4

2 回答 2

1

试试这个:

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;
}
于 2013-09-12T21:54:54.723 回答
0

假设这是 C(正如@Doorknob 指出的(+1)),这有几个编译错误。请修复它们。例如,您在同一个变量名的两个部分之间有一个空格。因此,以下几行:

   int x25 socket;
   struct sockaddr x25 address;
   int x25 length;
   char x25 host[] 

应该:

   int x25_socket;
   struct sockaddr_x25 x25_address;
   int x25_length;
   char x25_host[] 

除此之外,我没有看到 bind() 本身有任何逻辑缺陷。

于 2013-09-12T21:25:35.047 回答