Packet sending

This is a discussion on Packet sending within the Networking/Device Communication forums, part of the General Programming Boards category; Hello, I've discovered that using an application called scapy i can send network packets to any address,port, subnet. The thing ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    48

    Packet sending

    Hello, I've discovered that using an application called scapy i can send network packets to any address,port, subnet. The thing that caught my attention was the option to modify the source of the packet in the packet that was sent. I want to do that in c++. So far, all i can do is something like this:
    Code:
     WSAStartup(0x101,&wsadata);
     bsock=socket(AF_INET, SOCK_STREAM, 0);
        
        sinb.sin_family=AF_INET;
        sinb.sin_addr.s_addr=inet_addr(ip);
        sinb.sin_port=htons(port);    
        connect( bsock, (SOCKADDR*) &sinb, sizeof(SOCKADDR_IN) );
    Any help or reference to a proper tutorial will be welcomed. Thanks
    Last edited by like_no_other; 02-19-2009 at 02:24 PM.

  2. #2
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    Well, seeing you called WSAStartup, I am assuming you are on windows.
    http://msdn.microsoft.com/en-us/libr...16(VS.85).aspx
    This has great documentation and examples.

    http://beej.us/guide/bgnet/
    This is also a good reference as well. The examples here are for a unix type environment, but most of it is similar. It also shows some good techniques on how to do some advanced topics.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Source spoofing is usually considered evil. Moreover, it doesn't work unless you are within the core routing network.

    You can set the source IP to something that's not your real IP, but firstly, the socket layer will not allow you to bind to an IP which isn't configured on an interface, and secondly, even if you send a raw packet, your ISP's routers will detect the lie and drop the packet on the floor.

    You might be able to source spoof within a LAN, if the routers are configured stupidly. Anyway, don't do it.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    48
    i've googled a bit and found out that i can send raw packets by registering a new protocol driver to which i later write to through a handle (http://www.codeproject.com/KB/IP/sendrawpacket.aspx). Is it the only way?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 04:25 AM
  2. Problem while constructing IP packet and sending using socket() system call
    By cavestine in forum Networking/Device Communication
    Replies: 10
    Last Post: 10-15-2007, 06:49 AM
  3. unable to recieve UDP packet
    By caroundw5h in forum Networking/Device Communication
    Replies: 15
    Last Post: 09-19-2007, 12:11 PM
  4. Raw Packet (sorry tripple weird Post)
    By Coder87C in forum Networking/Device Communication
    Replies: 6
    Last Post: 03-04-2006, 11:34 AM
  5. packet sending
    By Peaches in forum C Programming
    Replies: 2
    Last Post: 03-08-2002, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21