Q:

send_to: An invalid argument was supplied

I'm trying to send a Raw TCP packet on the network, using the boost::asio library. My program works well on Mac OS X 10.8, but when I run the program under Windows 7 I get an exception (in console): Error: send_to: An invallid argument was supplied. The code to open the socket and the send_to() method is:
try {
    socket_.open();
    socket_.send_to(request_buffer.data(), ep);
} catch (std::exception& e) {
    std::cerr << "Error: " << e.what() << std::endl;
}

For defining the endpoint:
    ip::address_v4::bytes_type b = {{XXX, XXX, XXX, XXX}};
ip::raw::endpoint ep(boost::asio::ip::address_v4(b), (portnumber);

How can I solve the exception, so that the program can run under Windows? In the output window from Visual Studio 2010 the exception is:
First-chance exception at 0x000007fefcce9e5d (KernelBase.dll) in (programname).exe: Microsoft C++ exception: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> > at memory location 0x0,...

A:

It seems that RAW TCP sockets are blocked in Windows 7 (http://msdn.microsoft.com/nl-nl/library/windows/desktop/ms740548(v=vs.85).aspx). Using this link (http://www.savarese.com/software/rocksaw/#Q4) the story has been confirmed and in order to write TCP packets via a raw socket on Windows: you have to open the socket with either IPPROTO_IP or IPPROTO_RAW. Then you have to set the IP_HDRINCL socket option and populate both the IP and TCP headers of each packet. What this means in terms of RockSaw is that on Windows you have to use RawSocket.getProtocolByName("ip") and setIPHeaderInclude(true). 
Therefore with Boost::Asio it seems inpossible to send a packet with a own IP-header and a custom TCP packet (see the github of Kevin Conley, named above in a comment)

