tags:

views:

45

answers:

2

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
Thank ammoQ.Actually I cannot change my code(for #define)
Pradeep
Do we any limit for socket creation ?
Pradeep
AFAIK there is a limit on how many sockets you can open.
ammoQ
+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