Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Assign value to sockaddr_in struct (https://www.warriorforum.com/programming/1078397-assign-value-sockaddr_in-struct.html)

sarakarla 28th May 2015 02:47 AM

Assign value to sockaddr_in struct
 
Hi,
I recently bought shared hosting at asphostportal.com. Now, I have little problem. Could you help me please? I seem to be having a bit of a weird problem with sockaddr / sockaddr_in structs. I want to manually assign the value of an IP address to the sockaddr_in struct, and I've been using memcpy

memcpy (&(mIp4sa->sin_addr.s_addr), "127.0.0.1", INET_ADDRSTRLEN);
But when I go to print out the IP address from the sockaddr_in struct using cout and inet_ntoa, I don't get the same address - in this case, I always seem to get 49.50.53.49 or something similiar :S

I've tried casting a char* with the ip address to void* and using it in memcpy and the same thing happens. Is this just something thats not possible or am I doing it wrong?

Thanks in advance for any help :)

KirkMcD 28th May 2015 04:54 AM

Re: Assign value to sockaddr_in struct
 
Quote:

Originally Posted by sarakarla (Post 10084154)
Hi,
I always seem to get 49.50.53.49 or something similiar :S

That's the ascii value of the string 127.

Why would you try to do it as a memcpy and not just assigning the values like you normally would?


All times are GMT -6. The time now is 02:45 PM.