copying sockaddr_storage to another sockaddr_storage changes address

Question:

Hey... As in a recent question (nobody did react on the last changes) I have a problem with assigning a sockaddr structure filled byrecvfrom.

As I have been advised , I did change my sockaddr to sockaddr_storage and casted it in the last moment to be sure of having enough space for the address...

But the problem of

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

or

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

Do not work... anyone has a solution to copy a sockaddr_storage or at least the address to hold it in a structure and get the original value later on?...

Thank You.

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;

Answer:

our copying appears to be correct (the memcpy, at least). I suspect you are misparsing the result. You can try usingmemcmp to verify that the copy was successful.

你可能感兴趣的:(copying sockaddr_storage to another sockaddr_storage changes address)