简体   繁体   中英

sendto returning EINVAL on Mac OS X 10.8

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, ie

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM