Thread: packets dropped by kernel?

  1. #1
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214

    packets dropped by kernel?

    hi.
    i was into raw sockets the last time so i wrote a simple
    program that would create a single packet and send it
    to the destination.
    Code:
    #include <netinet/in.h>
    #include <sys/socket.h>
    #include <netinet/ip.h>
    #include <netinet/tcp.h>
    
    int main ()
    {
        int tcp_socket;
        
        struct sockaddr_in peer;
        
        struct send_tcp
        {
    	struct iphdr ip;
    	struct tcphdr tcp;
        } packet;
        
        packet.ip.version = 4;
        packet.ip.ihl = 5;
        packet.ip.tos = 0;
        packet.ip.tot_len = htons(40);
        packet.ip.id = 1;
        packet.ip.frag_off = 0;
        packet.ip.ttl = 255;
        packet.ip.protocol = IPPROTO_TCP;
        packet.ip.check = 14536;
        packet.ip.saddr = inet_addr("192.168.0.10");
        packet.ip.daddr = inet_addr("192.168.0.1");
        
        
        packet.tcp.source = htons(8000);
        packet.tcp.dest = htons(23);
        packet.tcp.seq = 1;
        packet.tcp.ack_seq = 2;
        packet.tcp.doff = 5;
        packet.tcp.res1 = 0;
        packet.tcp.fin = 0;
        packet.tcp.syn = 1;
        packet.tcp.rst = 0;
        packet.tcp.psh = 0;
        packet.tcp.ack = 0;
        packet.tcp.urg = 0;
        packet.tcp.res2 = 0;
        packet.tcp.window = htons(512);
        packet.tcp.check = 8889;
        packet.tcp.urg_ptr = 0;
        
        peer.sin_family = AF_INET;
        peer.sin_port = htons(25);
        peer.sin_addr.s_addr = inet_addr("192.168.0.1");
    
    	tcp_socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
        
            sendto(tcp_socket, &packet, sizeof(packet), 0, (struct sockaddr *)&peer, sizeof(peer));
    
    
    	close(tcp_socket);
    
        return 0;
    }
    with that code i want to establish a connection to my gateway on port 23. so i switched on tcpdump on the gateway and sent the packet. the was successfully sent but the gateway wasnt replying to that syn packet.
    why that?

    thanks

    ps. i have the port openend i want to connect to.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    You should really use libnet for this sort of thing. Also, read up on TCP/IP. It is alittle bit more complex than I think you believe.

  3. #3
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    well i will get some more informations about this topic.
    can anyone of you provide an example?
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Kernel bug? (attn matsp)
    By brewbuck in forum Linux Programming
    Replies: 7
    Last Post: 04-13-2009, 10:31 AM
  2. SOS - Can a monolithic kernel be used in a micro-kernel style OS?
    By sean in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 11-20-2008, 09:30 AM
  3. Accessing and editing packets of other applications
    By Inder in forum Linux Programming
    Replies: 1
    Last Post: 09-01-2006, 12:00 PM
  4. Programming RIP2 with kernel routes table
    By jpablo in forum Linux Programming
    Replies: 1
    Last Post: 04-22-2006, 11:26 AM
  5. CreateThread ?!
    By Devil Panther in forum Windows Programming
    Replies: 13
    Last Post: 11-15-2005, 10:55 AM