user1884325
user1884325

Reputation: 2550

TFTP Client (based on ENET) won't connect to remote TFTP server

I'm trying to implement a TFTP client in C (Windows, Visual Studio 2005).

The TFTP client is supposed to connect to a remote TFTP server address on port 69.

The TFTP client is using the ENET API for the networking stuff, but I can't get it to work.

The TFTP client never switches to the 'CONNECTED' state and is stuck in 'CONNECTING' state.

When I run the native Windows TFTP client on Windows 7 (cmd, windows console), it has no problem connecting to the TFTP server and I can retrieve a remote file without any problems.

So I must be doing something wrong in the code below and I'm hoping that somebody out there can tell me what I'm doing wrong:

#include "enet.h"
#include <stdlib.h>
#include <stdio.h>

#pragma comment(lib, "Winmm.lib")
#pragma comment(lib, "Ws2_32.lib")

void main(void)
{
    ENetAddress address;
    ENetEvent thisEvent;
    ENetPeer *peer;
    ENetHost* client;
    int rc;

    memset(&thisEvent,0,sizeof(ENetEvent));

    rc = enet_initialize ();

    /* Create a TFTP client */
    client = enet_host_create(NULL, 1,1,0,0);

    /* Address and port of remote TFTP server */
    rc = enet_address_set_host (& address, "192.168.30.50");
    address.port = 69;

    /* Connect client to server */
    peer = enet_host_connect (client, & address, 1, 0);    

    while (1)
    {
        printf("State = %d | Event Type = %d\n", peer->state, thisEvent.type);
        enet_host_service (client, &thisEvent, 1000);
    }
}

Upvotes: 0

Views: 463

Answers (1)

nobody
nobody

Reputation: 20173

From the documentation it doesn't look like this "ENet" library is for plain UDP communications. Rather, it implements a "single, uniform protocol layered over UDP". This is not the TFTP protocol, so your client is not compatible with a standard TFTP server.

Use plain sockets instead.

Upvotes: 1

Related Questions