I don't know what this error means and what to do to fix it.
I've been following the Sock)et Programming Tutorials In C For Beginners | Part 2 by Eduonix on Youtube but I haven't been able to run anything from this guy, the code is from his tutorial.
If someone could help me understand what this error means and what to do to fix it?
Here is the error:
inet_aton(address, &remote_address.sin_addr.s_addr);
^
[1007:1003 0:6758] 09:30:39 Wed May 29 [kristjan@Kundrum:pts/5 +1] ~/C_Programming
$ gcc http_client_tcp.c -o http_client_tcp
http_client_tcp.c: In function ‘main’:
http_client_tcp.c:24:24: warning: passing argument 2 of ‘inet_aton’ from incompatible pointer type [-Wincompatible-pointer-types]
inet_aton(address, &remote_address.sin_addr.s_addr);
^
In file included from http_client_tcp.c:8:0:
/usr/include/arpa/inet.h:73:12: note: expected ‘struct in_addr *’ but argument is of type ‘in_addr_t * {aka unsigned int *}’
extern int inet_aton (const char *__cp, struct in_addr *__inp) __THROW;
^~~~~~~~~
I'm using Debian Linux 9.9 stretch and coding in Visual Studio Code but the error doesn't come in the Visual Code editor/debugger only if I compile in the shell.
Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h> // for close
int main(int argc, char *argv[])
{
char *address;
address = argv[1];
int client_socket;
client_socket = socket(AF_INET, SOCK_STREAM, 0);
// connect to an address
struct sockaddr_in remote_address;
remote_address.sin_family = AF_INET;
remote_address.sin_port = htons(80);
inet_aton(address, &remote_address.sin_addr.s_addr);
connect(client_socket, (struct sockaddr *) &remote_address, sizeof(remote_address));
char request[] = "GET / HTTP/1.1\r\n\r\n";
char response[4096];
send(client_socket, request, sizeof(request), 0);
recv(client_socket, &response, sizeof(response), 0);
printf("response from server: %s\n", response);
close(client_socket);
return 0;
}