Topic: Unable to create valid client side socket file descriptor
On page 129 of the WOLFSSL manual is the following:
Before the SSL_connect() can be issued, the user must supply wolfSSL with a valid socket file descriptor, sockfd in the example above. sockfd is typically the result of the TCP function socket() which is later established using TCP connect(). The following creates a valid client side socket descriptor for use with a local wolfSSL server on port 11111, error handling is omitted for simplicity.
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(11111);
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
connect(sockfd, (const sockaddr*)&servaddr, sizeof(servaddr));
How do you issue a connect without the server IP address? The code above supplies an IP address of “127.0.0.1”. Well, what if you only have the common name of the server? Is there a routine to get the ip address so that it can be plugged into inet_addr(“ “)?
I have been getting a return of -1 from connect and I can’t figure out what is going wrong.
Thanks