2

can any one tell me why the following code always return 0 . the socket descriptor value is 3. i am using the open suse TFTP server . which is listening on port 69 in Local host.

connect() function return success ..

   connection_timer.tv_sec = 2; // s
    connection_timer.tv_usec = 0; 

 FD_ZERO(&fd_reader);
    // laukiam, kol bus ka nuskaityti
    FD_SET(socket_descriptor, &fd_reader);

    int select_ready = select(socket_descriptor + 1, &fd_reader, NULL, NULL, &connection_timer); 

When i use TCPdump to check the packet it send the first packet then the connection is closed in somewhere before receive Ack received..

Puppy
  • 144,682
  • 38
  • 256
  • 465
Balamurugan
  • 2,259
  • 8
  • 33
  • 48

3 Answers3

2

You will get a return code of 0 from select it the timer (connection_timer in your example) expires before any descriptor has become interesting.

So it's not an error. It seems most likely you didn't initialize connection_timer properly.

cnicutar
  • 178,505
  • 25
  • 365
  • 392
1

WSAStartup functions needs to be called. I do have the same problem and that got resolved after calling this startup function.

Dishum
  • 11
  • 1
1

I suspect that you are not receiving the response because you used connect() on a UDP socket, which made it so that you only accept datagrams from the connected destination.

Since the TFTP reply does not come from port 69, but rather from an ephemeral port, the acknowledgement is never received.

Solution: Don't connect() your UDP socket until after you finish the initial connection.

Hasturkun
  • 35,395
  • 6
  • 71
  • 104