Note that there are some explanatory texts on larger screens.

plurals
  1. PORaw Socket send TCP SYN-FIN-.. in c++
    primarykey
    data
    text
    <p>My teacher want us to do an exercise on raw socket in c ++ on Windows (for learning tcp communication).</p> <p>I have got a problem with it. I saw a lot of documentation but I don't know how to solve it.</p> <pre><code>int raw() { WSADATA WSAData; SOCKET sock; SOCKADDR_IN sin,din; WSAStartup(MAKEWORD(2, 2), &amp;WSAData); char datagram[MAX_PACKET_SIZE]; struct iphdr *iph = (struct iphdr *)datagram; struct tcphdr *tcph = (struct tcphdr *)((UCHAR *)iph + sizeof(tcphdr)); char new_ip[sizeof "255.255.255.255"]; sock = socket(PF_INET, SOCK_RAW, IPPROTO_TCP); if (sock == INVALID_SOCKET) cout &lt;&lt; "failled init socket" &lt;&lt; endl ; else{ memset(datagram, 0, MAX_PACKET_SIZE); // Clear the data setup_ip_header(iph); setup_tcp_header(tcph); sin.sin_family = AF_INET; sin.sin_port = htons(8888); sin.sin_addr.s_addr = inet_addr("192.168.1.10"); //source ip din.sin_family = AF_INET; din.sin_port = htons(DEST_PORT); din.sin_addr.s_addr = inet_addr(TARGET_SERV_IP); //ip serv to connect tcph-&gt;port_dest = htons(DEST_PORT); iph-&gt;ip_dest = din.sin_addr.s_addr; iph-&gt;ip_source = sin.sin_addr.s_addr; iph-&gt;ip_dest = inet_addr(TARGET_SERV_IP); //ip serv to connect iph-&gt;ip_source = inet_addr("192.168.1.10"); //source ip //iph-&gt;checksum = csum((unsigned short *)datagram, iph-&gt;tot_len &gt;&gt; 1); iph-&gt;checksum = csum((unsigned short *)datagram, sizeof(struct iphdr)); int one = 1; const int *val = &amp;one; if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, (char *)val, sizeof(one)) &lt; 0) printf("failled set socket option IP_HDRINCL"); else{ if (sendto(sock, /* our socket */ datagram, /* the buffer containing headers and data */ ntohs( iph-&gt;tot_len), /* total length of our datagram */ 0, /* routing flags, normally always 0 */ (struct sockaddr *) &amp;sin, /* socket addr, just like in */ sizeof(sin)) &lt; 0) /* a normal send() */ cout &lt;&lt; stderr &lt;&lt; "sendto() error!!!.\n " &lt;&lt; WSAGetLastError() &lt;&lt; endl; else cout &lt;&lt; "packet send\n" &lt;&lt; endl; } closesocket(sock); } } </code></pre> <p>My error occurs at the sendto(). it return 10022 error = WSAEINVAL</p> <p>I saw that can be a new windows protection?</p> <p>Have you any idea to fix my problem or bypass the protection (go deeper, driver, etc)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload