| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Fri Aug 13, 2010 12:37 pm Post subject: setsockopt errors ?! |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Aug 13, 2010 12:59 pm Post subject: |
|
|
Change optval to char and cast with (char*)&optval.
_________________
- Retired. |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Fri Aug 13, 2010 2:09 pm Post subject: |
|
|
| 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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Aug 13, 2010 2:55 pm Post subject: |
|
|
IP_HDRINCL option is meant to be DWORD, sorry about that.
Try changing optval to DWORD instead.
_________________
- Retired. |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 893
|
Posted: Sun Aug 22, 2010 10:01 am Post subject: |
|
|
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 |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Aug 26, 2010 9:13 am Post subject: |
|
|
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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Thu Aug 26, 2010 10:36 am Post subject: |
|
|
What's your code look like now?
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Aug 26, 2010 10:40 am Post subject: |
|
|
| 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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Thu Aug 26, 2010 11:32 am Post subject: |
|
|
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 |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Aug 26, 2010 11:42 am Post subject: |
|
|
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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
|
| Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 893
|
Posted: Thu Aug 26, 2010 3:36 pm Post subject: |
|
|
| In the code that you posted, you're still passing optval instead of the address of optval. That generates error 10014.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Fri Aug 27, 2010 1:40 am Post subject: |
|
|
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 |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Fri Aug 27, 2010 12:51 pm Post subject: |
|
|
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 |
|
 |
|