468,785 Members | 1,675 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,785 developers. It's quick & easy.

Network programming


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







Jul 19 '05 #1
2 2296
"grzybek" <gr*****@freebsd.gze.pl> wrote in message
news:bm**********@news2.ipartners.pl...

Hi,
I'm doing network program which
send TCP packet.
I have problem to send such a packet.

[...]

Unfortunately (or fortunately), the C++ standard doesn't address such topics
as sockets. Please take these types of questions to a newsgroup pertaining
to your target platform.
Jul 19 '05 #2
Hi,

More than you ever want to know about socket's programming:

http://www.developerweb.net/sock-faq/flatfaq.php

Regards, Ron AF Greve.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by John Walton | last post: by
2 posts views Thread by Jesse Engle | last post: by
4 posts views Thread by Wayne M J | last post: by
5 posts views Thread by Terry | last post: by
6 posts views Thread by Eric | last post: by
9 posts views Thread by Mex | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.