Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setsockopt won't compile on VC++ #5

Open
AjayVV opened this issue Jan 21, 2020 · 3 comments
Open

setsockopt won't compile on VC++ #5

AjayVV opened this issue Jan 21, 2020 · 3 comments

Comments

@AjayVV
Copy link

AjayVV commented Jan 21, 2020

The call to setsockopt won't compiler on VC++ compiler since (on Windows headers), setsockopt takes char* and not void*. It is true that MS header/implmenetation is faulty as it doesn't make sense to take char* - but the code won't compile.

int option = 0;
setsockopt(socket_listen, IPPROTO_IPV6, IPV6_V6ONLY,(void*)&option, sizeof(option));
@codeplea
Copy link
Owner

Hi Ajay,

It looks like this code is used in both time_server_dual.c and server_reuse.c.

The error you are describing would only happen if you are compiling the code as C++. Can you try to compile it as C code instead? I've tested it with VS2015 and VS2017, as long as it's compiled as C code, it should work.

I will work on a fix for the example programs to make it compatible with C++. I think this will require a macro so it works on both Windows and Linux.

Thanks for bringing this to my attention.

@AjayVV
Copy link
Author

AjayVV commented Jan 22, 2020

I know that the book is targeted for C programmers, to make the most use of the code samples given. However, in reality, the code would be used in C++ programs, possibly inside some class; hence code should be C++ (and C) complaint. :)

@codeplea
Copy link
Owner

That is very true. I tried very hard to make all of the code C and C++ valid. I just missed this case.

I will try to update the code soon with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants