Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 28th May 2015, 02:47 AM   #1
Warrior Member
 
Join Date: 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Assign value to sockaddr_in struct
Share on: 
fb share twitter share gplus share more share

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
sarakarla is offline  
Unread 28th May 2015, 04:54 AM   #2
VIP Warrior
War Room Member
 
Join Date: 2006
Location: , , USA.
Posts: 1,795
Thanks: 70
Thanked 287 Times in 259 Posts
Default
Re: Assign value to sockaddr_in struct
Share on: 
fb share twitter share gplus share more share

Originally Posted by sarakarla View Post

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?
KirkMcD is offline  
Closed Thread


Bookmarks

Tags
assign, sockaddrin, struct


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 04:08 PM.