Hello!
I know how to use connect, bind, accept, but I have no idea how they work!
For example connect(); takes three arguments:
int connect(int sockfd, const struct sockaddr *servaddr, socklen_t addrlen);
For example this is how it would look in the code:
connect(sock_fd, (struct sockaddr *)&server, sizeof(struct sockaddr))
I understand the first argument! The second argument is memory address of the sockaddr structure? or is it memory address of the object server? And if its memory address of the object server, why can't I just write &server, instead of(struct sockaddr *)&server? And does * mean that it has to do something with pointers?
The last argument is size of the sockaddr structure! But why sockaddr structure? I use sockaddr_in NOT sockaddr structure!!
And when I do this:
cout << sizeof(struct sockaddr_in) << endl;
and this:
cout << sizeof(struct sockaddr) << endl;
Both structure size is 16! What does 16 mean? Size of all variables in the structures or what?
And last question! What do all thous headers mean?
For example <sys/socket.h> contains socket(); connect(); etc...
But what about <sys/types.h>; <netinet/in.h> and <arpa/inet.h>? Thank you!