Listen() to a socket, but which port ?

I’m trying to setup QNX6.2 to act as a server and Listen() for clients that
try and attach. How can I specify which port number I am listening on ?? The
other end (client ) works OK and can connect to a windows server program
with port and IP address. The Windows server program listens, on a specific
port. How can I get QNX to do the same.

Any examples on how to make the accept() non-blocking would be grately
appreciated as well.

Many Thanks

iSocket = socket(AF_INET, SOCK_STREAM, 0); // Open a a socket

listen( iSocket, backlog); //Mark willingness to accept incoming connection
requests

iAddressLen = sizeof(iAddress);

accept( iSocket, (struct sockaddr *)&iAddress, &iAddressLen ) ; //Blocks
waiting on a client

— cut —

#define MY_PORT_NUMBER 2002

int sock, length;
struct sockaddr_in server;

sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
perror(“opening stream socket”);
exit(1);
}

/* Name socket: ip address(any), tcp port */

server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(MY_PORT_NUMBER);

/* Bind to specified port */

if (bind(sock, (struct sockaddr *)&server,sizeof(server)))
{
perror(" binding stream socket");
exit(1);
}

/* Start accepting connections */

listen(sock, 1);

— cut —