Sending UDP Raw socket
Posted on
16th Feb 2014 07:03 pm by
admin
I truly need help on this. I am trying to write a test program that simulate a network environment that have 5 clients and 1 server. To do so, I need to be able to edit IP header to change it's source address and various other values in the header. To change it, I need to use socket raw and IP_HRINCL socket option.
However, it doesn't work during the send with error 10049, "Address not available" from WSAGetLastError(). I am wondering how would I do so, and can I please look at a simple example on how to change your IP header and send it. By the way, I am using winsock with VC++, and my os is XP. I know there are some issues regarding XP's compatibility with Raw socket. In addition, if winsock is not a viable option, is there anyway for me to write in lower socket?
Did you know?Explore Trending and Topic pages for more stories like this.
Here's my code
Code:
#include
#include
#include
using namespace std;
int initialize();
void main()
{
initialize();
SOCKET sock = socket(AF_INET,SOCK_RAW,IPPROTO_IP);
int error;
char on = 1;
setsockopt(sock,IPPROTO_IP,IP_HDRINCL,&on,sizeof(on));
if(sock == INVALID_SOCKET)
cout << "Crap raw socket " << endl;
/* Header data */
unsigned char header[32] = {0x45,0x00,0x00,0x20,0x01,0xf1,0x00,0x00,0x05,0x11,0x9c,0x0a,0x05,0x3a,0x38,0x02,0xe0,
0x02,0xfa,0x93};
memset(header+20,0,12);
SOCKADDR_IN sock_add;
sock_add.sin_family = AF_INET;
sock_add.sin_port = htons(1542);
sock_add.sin_addr.s_addr = inet_addr("192.168.1.1");
error = sendto(sock,(char*)header,32,0,(LPSOCKADDR)&sock_add,sizeof(SOCKADDR_IN));
}
int initialize()
{
int t;
/* Before any Winsock function to work, we need to call to wsock.dll to initialize those
functions */
WSADATA wsa_data;
t = WSAStartup(MAKEWORD(1,1), &wsa_data);
if(t != 0)
return -1;
else
return 0;
}
Your Answer:
Login to answer
118
39
Other forums
Output Full URL of Current Page
Let's say I am currently viewing a dynamic page:
http://www.mydomain.com/directory/index.php
Multidimensional array problems in $_POST
I'm having trouble with a three-dimensional $_POST array. It starts as a two-dimensional array on th
opening a window with after form submission
I know this this forum has nothing to do with JS, but i'm trying to use it with my php script.
<
fire away
i launched about 4 months ago as a lagit co. i have 2 paying clients, 1probono, 1 side progect, and
Pop-up Banner
Hello Friends,I need to use banner in our client site.Example: www.example.com if i enter this site
ASP.NET 2.0 - Enter Key - Default Submit Button
Hi,One of the most annoying things in developing web pages is handling the "Enter key" for form subm
Error In Syntax
I got this error:
Code: Parse error: syntax error, unexpected '>' in /home/bucket/publ
Getting PHP to ammended the selected in option field
Hey Guys
thanks for everyones help so far. This site and its users are oozing awesomness.
Check before inserting in DB ???
This is my code
---------------
if ( $_POST ['Submit'])
{{
$username = $_POST ['usernm
type check while uploading
Hi Everyone,
How can I check the exact type of a file while uploading on my site?
Here