win10 winsock sendto error

恒晓 徐 1 Reputation point
2021-03-07T10:23:15.81+00:00

i want to send 44 bytes of data , and i use sendto , and return 44 , but The data was not actually sent . i donot konw why ?

WSAStartup(MAKEWORD(2, 2), &wsaData); 
sockRaw = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); 
DWORD bOpt = TRUE; 
setsockopt(sockRaw, IPPROTO_IP, IP_HDRINCL, (const char*)&bOpt, sizeof(bOpt)); 
// ... struct sockaddr_in dest;
memset(&dest, 0, sizeof(dest)); 
dest.sin_family = AF_INET; 
dest.sin_port = htons(dest_port); // 先起始端口把。 
// 设置目标地址。
if ((dest.sin_addr.s_addr = inet_addr(dest_host)) == INADDR_NONE) 
{ 
     if ((hp = gethostbyname(dest_host)) != NULL)  
    {
        memcpy(&(dest.sin_addr), hp->h_addr_list[1], hp->h_length); 
        dest.sin_family = hp->h_addrtype; 
        printf("dest.sin_addr = %s \n", inet_ntoa(dest.sin_addr)); 
    }
    else
    {}
}  
char nmap_syn[] = { 0x45, 0x00, 0x00, 0x2c, 0x8a, 0x0e, 0x00, 0x00, 0x29, 0x06, 0x00, 0x00, 0xc0, 0xa8, 0x00, 0x6a, 0xc0, 0xa8, 0x00, 0x46, 0x89, 0x08, 0x00, 0x50, 0x48, 0x95, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4 }; 
sendto(sockRaw, nmap_syn, sizeof(nmap_syn), 0, (struct sockaddr*)&dest, sizeof(dest)); 
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,429 questions
{count} votes