I have a socket() function call in my code.(using C language): socket(AF_INET, SOCK_STREAM, 0)) I want that it should result in error.(INVALID_SOCKET) Do we have some way out so that above function call results in error. Like stopping some services,etc
A:
You could create as many sockets as possible i.e. until it fails, then call your code. Or use #define to set the values of AF_INET and/or SOCK_STREAM to invalid values.
ammoQ
2010-09-23 06:14:28
Thank ammoQ.Actually I cannot change my code(for #define)
Pradeep
2010-09-23 06:18:24
Do we any limit for socket creation ?
Pradeep
2010-09-23 06:18:44
AFAIK there is a limit on how many sockets you can open.
ammoQ
2010-09-23 07:12:49
+2
A:
Since you say this is in your code, you could define your own implementation of socket
that always returns INVALID_SOCKET:
int socket(int domain, int type, int protocol)
{
return INVALID_SOCKET;
}
If you link with the object file that defines your version of socket before linking with the real version, the linker will send all calls to socket
to your implementation.
R Samuel Klatchko
2010-09-23 06:42:38