INtime SDK Help
Migrating older network applications
INtime SDK v7 > About INtime > Networking and I/O > TCP/IP Networking > Migrating older network applications

Applications written in versions of INtime prior to 4.0 will need to be converted to use the new network stack (also known as "Network7"). The API has been changed slightly to bring it into line with modern BSD standards and you need to link your application with new libraries.

Converting your project

Some project settings need to change to recompile your application to use the new stack. They are as follows:

  1. Add __INTIME__ and __C99__ to your preprocessor defines
  2. Remove ciff3m8.lib and netiff3m.lib from your linker settings, replace them with netlib.lib and clib.lib

Changes to source code

The following are major changes in the implementation of the network software, and are designed to pull the stack closer to a standard implementation.

  1. socktout() is no longer supported. Use fcntl(s,F_SETFL,O_NONBLOCK) or poll() /select() instead.
  2. select() now takes a struct timeval for the last parameter, rather than the nonstandard short word 10ms tick value
  3. Older INtime networking did not support non-blocking connect().

The following code demonstrates how to use fcntl() to achieve this:

Title Text
Copy Code
int connect_with_timeout(char *peer, in_port_t port, long conn_to)
{
    int rval;
    struct sockaddr_in addr;
    int flags;
    fd_set wfds;
    struct timeval tv;
    int s;

    s = socket(AF_INET, SOCK_STREAM, 0);
    if (s == -1)
    {
        fprintf(stderr, "socket() Error e=%d%s \n", errno, strerror(errno));
        return -1;
    }

    // Set non-blocking
    flags = fcntl(s, F_GETFL);
    flags |= O_NONBLOCK;
    fcntl(s, F_SETFL, flags);

    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = inet_addr(peer);

    rval = connect(s, (struct sockaddr *)&addr, sizeof(addr));
    if (rval < 0)
    {
        // connect() retuns EINPROGRESS when non-blocking
        if (errno == EINPROGRESS)
        {
            tv.tv_sec = conn_to;
            tv.tv_usec = 0;
            FD_ZERO(&wfds);
            FD_SET(s, &wfds);
            if ((rval = select(s+1, NULL, &wfds, NULL, &tv)) > 0)
            {
               return s;
            }
            else
            if (rval == 0)
            {
                fprintf(stderr, "Timeout! \n");
                shutdown(s,SHUT_RDWR);
                errno = ETIMEDOUT;
                return -1;
            }
            else
            {
                fprintf(stderr, "select() Error e=%d%s \n", errno, strerror(errno));
                shutdown(s,SHUT_RDWR);
                return -1;
            }
        }
        else
        {
            fprintf(stderr, "connect() Error e=%d%s \n", errno, strerror(errno));
            shutdown(s,SHUT_RDWR);
            return -1;
        }
    }
    else
    {
        fprintf(stderr, "Error connecting %d%s\n", errno, strerror(errno));
        shutdown(s,SHUT_RDWR);
        return -1;
    }

  // Set to blocking mode again...
  flags = fcntl(s, F_GETFL);
  flags &= (~O_NONBLOCK);
  fcntl(s, F_SETFL, flags);
  return s;
}

New features

The following are features new to INtime networking.

IPv6

BPF

libpcap

SCTP

IPFW

See Also