开发者

socket() function error in C

开发者 https://www.devze.com 2023-01-17 10:29 出处:网络
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)

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 h开发者_如何转开发ave some way out so that above function call results in error. Like stopping some services,etc


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消