Could not find a direct answer to this anywhere. Can someone shed some lights. Thanks.
views:
134answers:
4
+1
A:
#include <sys/types.h>
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
Delan Azabani
2010-09-19 09:22:06
+4
A:
There's no such command built into the language. Sockets need to be used but they are platform dependent.
Darin Dimitrov
2010-09-19 09:22:53
I was thinking something like that also. I guess the answer from Delan is for Linux.
Gunner
2010-09-19 09:24:11
Yes, on Windows it's `winsock.h`.
Darin Dimitrov
2010-09-19 09:25:56
+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
2010-09-19 09:50:14