G
grzybek
Hi,
I'm doing network program which
send TCP packet.
I have problem to send such a packet.
I create socket:
s = WSASocket(AF_INET, SOCK_RAW, IPPROTO_RAW , NULL, 0,0);
then:
ret = setsockopt(s, IPPROTO_IP, IP_HDRINCL, (char *)&bOpt, sizeof(bOpt));
I built IP and TCP header : ipHdr and tcpHdr with specific settings.
Next:
memcpy(ptr, &ipHdr, sizeof(ipHdr)); ptr += sizeof(ipHdr);
memcpy(ptr, &tcpHdr, sizeof(tcpHdr)); ptr += sizeof(tcpHdr);
memcpy(ptr, strMessage, strlen(strMessage)); // strMessage="any text"
memset( &remote, 0, sizeof remote );
remote.sin_family = AF_INET;
remote.sin_port = htons(iToPort);
remote.sin_addr.s_addr = inet_addr("10.36.36.55");;
....
ret = connect(s, (struct sockaddr*)&remote, sizeof remote);
....
iTotalSize = sizeof(ipHdr) + sizeof(tcpHdr) + strlen(strMessage);
ret = sendto(s, ptr, iTotalSize, 0, (struct sockaddr*)&remote,sizeof
remote);
( if I made cout << ptr, I can see only first letter of 'strMessage' )
End nothing is sent. ( ret = 58 B )
What is wrong ?
Perhaps anybody has code sending preparing TCP packets.
Regards,
grzybek
I'm doing network program which
send TCP packet.
I have problem to send such a packet.
I create socket:
s = WSASocket(AF_INET, SOCK_RAW, IPPROTO_RAW , NULL, 0,0);
then:
ret = setsockopt(s, IPPROTO_IP, IP_HDRINCL, (char *)&bOpt, sizeof(bOpt));
I built IP and TCP header : ipHdr and tcpHdr with specific settings.
Next:
memcpy(ptr, &ipHdr, sizeof(ipHdr)); ptr += sizeof(ipHdr);
memcpy(ptr, &tcpHdr, sizeof(tcpHdr)); ptr += sizeof(tcpHdr);
memcpy(ptr, strMessage, strlen(strMessage)); // strMessage="any text"
memset( &remote, 0, sizeof remote );
remote.sin_family = AF_INET;
remote.sin_port = htons(iToPort);
remote.sin_addr.s_addr = inet_addr("10.36.36.55");;
....
ret = connect(s, (struct sockaddr*)&remote, sizeof remote);
....
iTotalSize = sizeof(ipHdr) + sizeof(tcpHdr) + strlen(strMessage);
ret = sendto(s, ptr, iTotalSize, 0, (struct sockaddr*)&remote,sizeof
remote);
( if I made cout << ptr, I can see only first letter of 'strMessage' )
End nothing is sent. ( ret = 58 B )
What is wrong ?
Perhaps anybody has code sending preparing TCP packets.
Regards,
grzybek