문제

I had a program that worked properly with Mac OS 10.6 but inexplicably fails in 10.8. The gist of it is that sendto is now returning -1 and setting errno to EINVAL (22). What's going wrong?

도움이 되었습니까?

해결책

The address I was giving sendto came from the first result of getaddrinfo. Turns out that first result is now an IPV6 result (using sockaddr_in6). sendto on OS 10.8 (at least for now) only seems to work with sockaddr_in address. Make sure to pass a hint to getaddrinfo that says you only want ipv4 addresses, i.e.

struct addrinfo hint;
memset( &hint, 0, sizeof(struct addrinfo));
hint.ai_family = AF_INET;

struct addrinfo* result;
int res = getaddrinfo( friendlyHostname, NULL, &hint, &result );

Read http://linux.die.net/man/3/getaddrinfo for more info.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top