Question

My C++ application is sending binary data as UDP packets. The sendto() call returns EINVAL (Invalid argument), but I don't see anything wrong with the parameters I'm passing.

I did an strace of the application and here are the revelant system calls:

socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 33
setsockopt(33, SOL_IP, IP_RECVERR, [1], 4) = 0
fcntl(33, F_SETFD, FD_CLOEXEC)          = 0
bind(33, {sa_family=AF_INET, sin_port=htons(1510), sin_addr=inet_addr("127.0.0.1")}, 16) = 0

sendto(33, "\2055\5\0\0\0\1\0\0\0\1\20 \0t\0c\300Ny\274B\10*\206H\206\367\r\2\5\0\200\200\331'\344\272\322\362sD\277\312\300\23\240\224\212\16\20\1\0\0\22", 55, 0, {sa_family=AF_INET, sin_port=htons(1510), sin_addr=inet_addr("219.132.100.190")}, 16) = -1 EINVAL (Invalid argument)

Does anybody see which parameter is invalid?

The application has recently been ported to support IPv6, but I don't know if that has anything to do with it.

Was it helpful?

Solution

You bound your socket to the local address 127.1, but you are sending to a non-localhost address. I need to check, but perhaps the EINVAL means "you can't send 127.1 packets off-host."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top