views:

39

answers:

1

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

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;
+1  A: 

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

Hasturkun