开发者

copying sockaddr_storage to another sockaddr_storage changes address

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_PAD1开发者_运维技巧SIZE];
  __int64 __ss_align;
  char    __ss_pad2[_SS_PAD2SIZE];
} SOCKADDR_STORAGE, *PSOCKADDR_STORAGE;


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜