0

Still, having troubles with my code.

if (argc > 0) {
int route (argc);//[argc+1]
((char*) route)[0] = 1;
((char*) route)[1] = 2;//131
((char*) route)[2] = 3 + argc * 4;
((char*) route)[3] = 4;
for (int i = 0; i < argc; i++) {
    route = inet_addr(argv[i]);
}

if (setsockopt(_socket.native_handle(), IPPROTO_IP, IP_OPTIONS, route, (argc + 1) * 4) < 0) {
    perror("can't set socket option");
}
}

here's a part of it, keep getting this error C2664: cannot convert parameter 4 from 'int' to 'const char *'

  • Did you mean to refer to `argv` rather than `argc` there? `argc` actually is an integer value that is used to specify the number of presen string arguments for the `main()` function. – πάντα ῥεῖ Jun 02 '15 at 19:24
  • 1
    Anton, there are so many things wrong in this code, I'd advise you to look for some *BEGINNER* tutorials. (Sorry) – Amit Jun 02 '15 at 19:25
  • @πάνταῥεῖ well, I'm an amateor at this, so I'm a bit confused. if I'm refering to argv there (argv+1) - it's giving me another error, that I should refer ro arithmetic type and bla bla bla – Anton Yatsushko Jun 02 '15 at 19:30
  • @Amit haha sure thing! I know that..and nobody can't point me where are those problems – Anton Yatsushko Jun 02 '15 at 19:32
  • @AntonYatsushko _"and nobody can't point me where are those problems"_ Well, your code is far from doing anything meaningful, e.g. `int route (argc)`. As mentioned `argc` is the number of arguments passed to `main()` usually, unless you're using that symbol name in a completely different manner here. So what should we answer? – πάντα ῥεῖ Jun 02 '15 at 19:36
  • @πάνταῥεῖ as I were saying before at another post, I found this program in the internet and trying to actually make it work.The main goal of that program is increasing bandwidth of connections with user-defined route of simultaneous use of several channels of data, I dothe best I can, and of course thanks for help guys!! – Anton Yatsushko Jun 02 '15 at 19:43
  • @AntonYatsushko Post more context then please, to make it more meaningful. All of that doesn't makes sense for me as it looks and stands. – πάντα ῥεῖ Jun 02 '15 at 19:45
  • @πάνταῥεῖ sure, here is a link to my privious post concerning this program and explaining things [link]http://stackoverflow.com/questions/30599576/dynamic-loose-source-routing-in-ip-networks – Anton Yatsushko Jun 02 '15 at 19:51
  • @AntonYatsushko Post stand alone questions. Do not refer to links to _explain more_. – πάντα ῥεῖ Jun 02 '15 at 19:53
  • @πάνταῥεῖ Well, I got my main code there, if you could just look at it.. – Anton Yatsushko Jun 02 '15 at 19:58
  • @AntonYatsushko Nope. I don't follow such explanatory links in general. I justify questions by their actual content. Did you ever read this [article from the help center](http://stackoverflow.com/help/mcve)? – πάντα ῥεῖ Jun 02 '15 at 20:07
  • @πάνταῥεῖ still I don't understand why you can't look at it..but anyways, thank you for your help. appreciate it – Anton Yatsushko Jun 02 '15 at 20:12
  • @AntonYatsushko I'm not referring to your programming problem primarily (which it looks now is solved with the accepted answer), but I'm trying to teach you how to improve your questions on SO. – πάντα ῥεῖ Jun 02 '15 at 20:15

2 Answers2

1

Microsoft's implementation of setsockopt() has a const char* for the fourth option. POSIX usually has a const void*. It has to be pointing to a buffer that contains values. The last argument is the size in bytes of the buffer.

So something like this:

setsockopt(
    _socket.native_handle(), IPPROTO_IP, IP_OPTIONS,
    reinterpret_cast<char*>(&route), sizeof(int));

I don't know enough about sockets to tell you whether what you're passing actually makes sense. Here's the documentation on MSDN for IP_OPTIONS.

isanae
  • 3,253
  • 1
  • 22
  • 47
0
timeout = send_timeout_seconds * 1000;

setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof timeout);
  • 3
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Adrian Mole Feb 19 '21 at 13:30