クライアントとサーバー間の接続を作成する C プログラムに取り組んでいます。既に作成したソケットで接続を実行すると、無効な引数を渡しているというエラーが表示され続けます。
どんな助けでも素晴らしいでしょう!
void client(char* ipAddress, char* serverPort){
//code for setting up the IP address and socket information from Beej's Guide to Network Programming
//Need to setup two addrinfo structs. One for the client and one for the server that the connection will be going to
int status;
//client addrinfo
struct addrinfo hints, *res; // will point to the results
//server addrinfo
int socketDescriptor;
int addressLength;
memset(&hints, 0, sizeof hints); // make sure the struct is empty
hints.ai_family = AF_UNSPEC; // don't care IPv4 or IPv6
hints.ai_socktype = SOCK_STREAM; // TCP stream sockets
hints.ai_flags = AI_PASSIVE; // fill in my IP for me
//setup client socket
if ((status = getaddrinfo(ipAddress, serverPort, &hints, &res)) != 0) {
printf("%s \n", "This error above");
fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
exit(1);
}
if((socketDescriptor = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) ==-1){
perror("client: socket");
}
addressLength = sizeof hints;
if(connect(socketDescriptor, res->ai_addr, addressLength)==-1){
close(socketDescriptor);
perror("client: connect");
}
}