0

I am having an already existing code(cuda c++) which I want to debug and this uses sockets in c++, I am quite not sure what exactly it's trying to do and how will be able to link to a particular address? Please help me with understanding what are ai_family,ai_socktype,ai_protocol and other means?

int sockfd = socket(host_info->ai_family, host_info->ai_socktype, host_info->ai_protocol);

    if (sockfd<0)
    {
        printf("can't create socket\n");
        return false;
    }

    if (connect(sockfd, host_info->ai_addr, host_info->ai_addrlen)<0)
    {
        printf("can't create connection\n");
        return false;
    }
talonmies
  • 70,661
  • 34
  • 192
  • 269
  • `man 2 socket` may provide some help, – Ted Lyngmo Oct 21 '19 at 11:58
  • whats `man 2 socket` ?? –  Oct 21 '19 at 12:01
  • A command. It looks like you are using a Posix system. Those often come with manual pages installed (`man`) - so by typing `man socket` or `man 2 socket` you get some help regarding the `socket` call. – Ted Lyngmo Oct 21 '19 at 12:03
  • Was able to check with man 2 socket, Please help me understand in layman terms what my program does? as I do not want to know everything. –  Oct 21 '19 at 12:06
  • It looks like it's creating a client socket and connects to a server socket. – Ted Lyngmo Oct 21 '19 at 12:09

1 Answers1

0

You can google it, MSDN has the definitions and examples of use. Linux surely has it's own help. Just look for what you need as there are quite a lot of possibilities, and only few are frequently used.

There is a large variety of options for sockets.

address version: ipv4 and ipv6. socket type: udp, tcp, and others.

I believe there are also non-network sockets, right?

Each option drastically changes what the socket needs to perform.

ALX23z
  • 4,456
  • 1
  • 11
  • 18
  • If this was an answer, it would explain what `ai_family`, `ai_socktype` and `ai_protocol` are. – nada Oct 21 '19 at 12:41