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.
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.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; }
why that?
thanks
ps. i have the port openend i want to connect to.



LinkBack URL
About LinkBacks


