views:

134

answers:

4

Could not find a direct answer to this anywhere. Can someone shed some lights. Thanks.

+1  A: 
#include <sys/types.h>
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
Delan Azabani
+4  A: 

There's no such command built into the language. Sockets need to be used but they are platform dependent.

Darin Dimitrov
I was thinking something like that also. I guess the answer from Delan is for Linux.
Gunner
Yes, on Windows it's `winsock.h`.
Darin Dimitrov
+1  A: 

On Winsock, that would be connect(), but socket needs to be created first.

alxx
+3  A: 

There's no single C "command" (rather, function) to "open" a connection to a remote host.

First, you need a socket, this is provided by the socket() function (see your documentation for relevant header files). Then, you need to call connect() to establish the connection. However, that requires that all host names have been resolved, so you may have had to call gethostbyname() or similar, to turn a hostname into an IP address.

Since you said this was a job interview question, would it be possible to tell us what line of business the company is in and what position was interviewed for?

Vatine