hyunsang park
hyunsang park

Reputation: 11

why sockaddr_in and sockaddr each is imcompatible?

I try to memcpy ipv4 address in *ai(struct addrinfo)

struct addrinfo *ai;
char *p = (char *)(void *)(ai->ai_addr);

memcpy(p + afd->a_off, "d83adcca", (size_t)afd->a_addrlen); // "d83adcca ipv4 address is hex data - not correct.."

So, i need verify that i have been correctly assigned. I use this code :

struct sockaddr_in ipv4 = (struct sockaddr_in *)ai->ai_addr;
inet_ntop(AF_INET, &(ipv4->sin_addr), ipAddress, INET_ADDRSTRLEN);

BUT, ipAddress and ai->ai_addr is not matched!! If you know how to assigned these struct, Please help me. Thanks.

Upvotes: 0

Views: 80

Answers (0)

Related Questions