Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


setsockopt errors ?!

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Aug 13, 2010 12:37 pm    Post subject: setsockopt errors ?! Reply with quote

I'v been messing with sockets lately and wanted to control the packet's header
so i found out that i should use setsockopt for that
but i always get error 10014 ( means that it's a bad address - http://msdn.microsoft.com/en-us/library/ms740668%28v=VS.85%29.aspx )
that's my code
Code:

   WSADATA   wsaData;
   int      optval = 1;

   if( WSAStartup( MAKEWORD( 2, 2 ), &wsaData ) ) {
      printf("[-]WSAStartup failed - Error: %d\n", WSAGetLastError());
      return -1;
   }
   if( ( sockraw = WSASocketA( AF_INET, SOCK_RAW, IPPROTO_RAW, NULL, NULL, NULL ) ) == INVALID_SOCKET ) {
      printf("[-]WSASocket failed - Error: %d\n", WSAGetLastError());
      return -1;
   }
   if( setsockopt( sockraw, IPPROTO_IP, IP_HDRINCL, (char*)optval, sizeof optval ) == SOCKET_ERROR ) {
      printf("[-]setsockopt failed - Error: %d\n", WSAGetLastError());
      return -1;
   }

any ideas?

_________________
Stylo
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Aug 13, 2010 12:59 pm    Post subject: Reply with quote

Change optval to char and cast with (char*)&optval.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Aug 13, 2010 2:09 pm    Post subject: Reply with quote

Wiccaan wrote:
Change optval to char and cast with (char*)&optval.

If i do that i get an invalid argument error ( 10022 ).

_________________
Stylo
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Aug 13, 2010 2:55 pm    Post subject: Reply with quote

IP_HDRINCL option is meant to be DWORD, sorry about that.

Try changing optval to DWORD instead.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Aug 13, 2010 4:12 pm    Post subject: Reply with quote

Wiccaan wrote:
IP_HDRINCL option is meant to be DWORD, sorry about that.

Try changing optval to DWORD instead.

Actually now i get error 10004 which means A blocking operation was interrupted by a call to WSACancelBlockingCall.
X_X
Perhaps it's because i'm using winsock2 instead of the older version?
It's driving me crazy Mad
if any1 have any clue about messing around with the packet's headers it'd be great

_________________
Stylo
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Sun Aug 22, 2010 10:01 am    Post subject: Reply with quote

Are you sure that you're getting error 10004 instead of 10014? 10014 would make sense, since you're passing reinterpret_cast<const char *>(optval) instead of &optval.

Cheers,
adude
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Aug 26, 2010 9:13 am    Post subject: Reply with quote

i've tested few options in that optval parameter and it wasn't helping
now i'm getting error 10004.
my other question is there another way to control the packet's header in windows > C++ or C

_________________
Stylo
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu Aug 26, 2010 10:36 am    Post subject: Reply with quote

What's your code look like now?
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Aug 26, 2010 10:40 am    Post subject: Reply with quote

Code:

   WSADATA   wsaData;
   int      optval = 1;

   if( WSAStartup( MAKEWORD( 2, 2 ), &wsaData ) ) {
      printf("[-]WSAStartup failed - Error: %d\n", WSAGetLastError());
      return -1;
   }
   if( ( sockraw = WSASocketA( AF_INET, SOCK_RAW, IPPROTO_RAW, NULL, NULL, NULL ) ) == INVALID_SOCKET ) {
      printf("[-]WSASocket failed - Error: %d\n", WSAGetLastError());
      return -1;
   }
   if( setsockopt( sockraw, IPPROTO_IP, IP_HDRINCL, (char*)optval, sizeof optval ) == SOCKET_ERROR ) {
      printf("[-]setsockopt failed - Error: %d\n", WSAGetLastError());
      return -1;
   }

_________________
Stylo
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu Aug 26, 2010 11:32 am    Post subject: Reply with quote

I saw that bit posted earlier, what is the context it is used in.

Are you looking up by domain name? Which if your DNS is doing reverse lookups, if the host you are trying to reach is configured improperly it will fail due to no reverse lookup. Or are you looking by IP.

Have a look at this, it might help to shed some light on what exactly you are trying to do.

_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>


Last edited by AhMunRa on Thu Aug 26, 2010 11:45 am; edited 1 time in total
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Aug 26, 2010 11:42 am    Post subject: Reply with quote

I'm not even trying to reach any host
i'm at the level where i create the socket and i want the socket will have the option of editing the packet's header

_________________
Stylo
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu Aug 26, 2010 11:46 am    Post subject: Reply with quote

In recent versions of Windows Microsoft has taken away alot of the ability for you to modify packets for security reasons.

http://tangentsoft.net/wskfaq/advanced.html#rawsocket

You will also be limited to what you can modify in a packets header, unless you are building the whole packet yourself.

Some suggested reading.

RFC-791 Internet Protocol
RFC-793 Transmission Control Protocol
Raw IP FAQ

This is unrelated in what you are trying to do, but what you would learn from this would greatly help you understand sockets and packets.

http://www.faqs.org/docs/Linux-mini/Divert-Sockets-mini-HOWTO.html
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Thu Aug 26, 2010 3:36 pm    Post subject: Reply with quote

In the code that you posted, you're still passing optval instead of the address of optval. That generates error 10014.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Aug 27, 2010 1:40 am    Post subject: Reply with quote

AhMunRa wrote:
In recent versions of Windows Microsoft has taken away alot of the ability for you to modify packets for security reasons.

http://tangentsoft.net/wskfaq/advanced.html#rawsocket

You will also be limited to what you can modify in a packets header, unless you are building the whole packet yourself.

Some suggested reading.

RFC-791 Internet Protocol
RFC-793 Transmission Control Protocol
Raw IP FAQ

This is unrelated in what you are trying to do, but what you would learn from this would greatly help you understand sockets and packets.

http://www.faqs.org/docs/Linux-mini/Divert-Sockets-mini-HOWTO.html

Great articles i'll take a look at it later on
@justa_dude
when i pass the address of optval i still get an errors
but this time error 10004

_________________
Stylo
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Fri Aug 27, 2010 12:51 pm    Post subject: Reply with quote

I think it would help if we could see the code in it's entirety, a snippet is not enough in this case.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites