0
votes

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 *'

2
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. - πάντα ῥεῖ
Anton, there are so many things wrong in this code, I'd advise you to look for some BEGINNER tutorials. (Sorry) - Amit
@πάνταῥεῖ 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
@Amit haha sure thing! I know that..and nobody can't point me where are those problems - Anton Yatsushko
@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? - πάντα ῥεῖ

2 Answers

1
votes

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.

0
votes
timeout = send_timeout_seconds * 1000;

setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof timeout);