Following a tutorial, I built a small sample program that uses winsock. It compiles, but there are a few different places I'm not sure what's happening with the pointers. Full source is available here
struct hostent *host;
As near as I can tell, this creates a pointer to a memory address holding an instance of the "hostent" struct and refers to it as "host." What I can't figure out is why
hostent h; host = *h;
wouldn't accomplish the same thing, as hostent is already an existing struct in the winsock2 header.
socket_address.sin_addr.s_addr = *((unsigned long*)host->h_addr);
The right side, I find utterly baffling. For the "*" inside the parenthesis and to the right of "unsigned long" I can't figure out the significance. As for the one directly to the left of the parentheses, does this just mean the right side provides a pointer to a memory address holding an unsigned long int?
if(connect(server_socket,(SOCKADDR*)(&socket_address), sizeof(socket_address)) != 0)
The second argument the connect function expects is, according to msn's documentation, "[a] pointer to the sockaddr structure to which the connection should be established." As such, it stands to reason that the second argument provided here takes the "SOCKADDR_IN" instance "socket_address" and provides a pointer to it. What I can't understand is the reasoning behind why this syntax does that, and even trying to explain what little I thought I had figured out confused me to the point that whatever logical progress I thought I had made on the matter ceased to make any sense to me.
Thanks in advance.
Edited 3 Years Ago by oscargrower11: finished title