Copy sockaddr_storage to another sockaddr_storage change file

Hey ... As in a recent question (no one was responding to the latest changes), I had a problem assigning a sockaddr structure populated by recvfrom .

As I was informed, I changed my sockaddr to sockaddr_storage and dropped it at the last moment to make sure you have enough space for the address ...

But the problem

 sockaddr_storage s1, s2; /*recv address into s1*/ s2 = s1; 

or memcpy(&s2, &s1, sizeof(sockaddr_storage));

Doesn't work ... does anyone have a solution for copying sockaddr_storage, or at least the address, to keep it in the structure and get the original value later? ...

Thanks.

EDIT: definitions for sockaddr and sockaddr_storage (msdn):

 struct sockaddr { ushort sa_family; char sa_data[14]; }; typedef struct sockaddr_storage { short ss_family; char __ss_pad1[_SS_PAD1SIZE]; __int64 __ss_align; char __ss_pad2[_SS_PAD2SIZE]; } SOCKADDR_STORAGE, *PSOCKADDR_STORAGE; 
+4
source share
1 answer

Your copy seems to be correct ( memcpy , at least). I suspect you are not evaluating the result correctly. You can try using memcmp to verify that the copy was successful.

+1
source

All Articles