This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Socket connect() returns ENXIO

I created two sockets to do a simple loopback test, however I received an ENXIO error when I tried to connect the socket. Any suggestion what I missed?

SOCKET soctx, socrx;

struct sockaddr_in serv_addr;

fdOpenSession(TaskSelf();

soctx = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

if(soctx == INVALID_SOCKET) { goto exit }

socrx = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

// prepare address

bzero(&serv_addr, sizeof(struct sockaddr_in));

serv_addr.sin_family = AF_INET;

serv_addr.sin_addr.s_addr = inet_addr("192.168.0.107);

serv_addr.sin_port = htons(1234);

if (bind(socrx, (PSA)&serv_addr, sizeof(serv_addr)) < 0) {goto exit}

if (listen(socrx, 1) < 0 {goto exit}

if (connect(soctx, (PSA)&serv_addr, sizeof(serv_addr)) < 0) {goto exit} <--connect() returns ENXIO

...

Thanks

  • For that error see page 91 of the following doc.

    http://www.ti.com/lit/ug/spru524i/spru524i.pdf

    This is what it says:

    ENXIO No egress interface specified for this socket to send out data. Use
    SO_IFDEVICE socket option and specify an interface before retrying to
    send out data using this socket.

    Judah

  • I tried that before, and it didn't work.

    Also, according to the user guide, SO_IFDEVICE option is only for raw type and DGRAM socket.

    I am using SOCK_STREAM.

  • 2 minor things: 

    1. You're missing a quote for the IP address string.

    serv_addr.sin_addr.s_addr = inet_addr("192.168.0.107);

    2. You should check that the rx socket was created successfully.  You are doing this for the tx socket, but not the rx one.  It could have failed to allocate.


    You failure could be related to the following:

    1. The typical order of API calls for a TCP server is:
      1. socket()
      2. bind()
      3. listen()
      4. accept()

    You have a, b and c, but I don’t see d.  You should try adding accept code before trying to connect the tx socket to the rx socket.

    Judah

  • Part of my problem was that I didn't  have an IP set. When I didn't have an IP set, the code jumped to sock.c line 645 and NDK_connect() returns ENXIO error.

    I had to add the following to my .cfg file:

    var Ip = xdc.useModule('ti.ndk.config.Ip');

    Ip.address = "192.168.0.11";

    Ip.mask = "255.255.255.0";

    Ip.ifIdx = 1;