Skip to content
Advertisement

select() fails when adding m32 flag to Makefile

i have the following code, which simply creates udp socket to listen to a multicast group.

I’m compiling it using gcc, with -c -g flags, on x64 machine. When adding -m32 flag to linking & compiling phases in Makefile, select() call is failing with Invalid Argument.

After debugging a little bit with and without the flag, i found out that using the flag i get all the same values for all variables, except:

readfds: 0x80.. (repeats 31 times) – WITH -m32 flag

readfds: 0x80.. (repeats 15 times) – without the flag

sock.sin_zero: 0x5c, 0xD5, 0xff, and some other weird values WITH -m32 flag

sock.sin_zero: 0x0,0x0,0x20,0x0,0x0 – without the flag

All variables reading is done inside the file loop, right after FD_SET

I don’t really understand why does it changes at whole (as 32 bit program suppose to run just fine on 64 bit machines) , or why does select() returns Invalid Argument in that case.

could someone please help?

JavaScript

Advertisement

Answer

You’re not setting the tv_usec field of the timeout argument, so it will contain some garbage (whatever happened to be on the stack where timeout_value was allocated). If that random garbage happens to be a negative number, you’ll get the EINVAL invalid argument error. If it happens to be ok, you won’t. Minor changes to things (like using -m32 or not) will tend to change this.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement