Assign value to sockaddr_in struct

1 replies
I recently bought shared hosting at 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), "", 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 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
#assign #sockaddrin #struct
  • Profile picture of the author KirkMcD
    Originally Posted by sarakarla View Post

    I always seem to get 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?
    {{ DiscussionBoard.errors[10084303].message }}

Trending Topics