471,120 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,120 software developers and data experts.

Network programming

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

I create socket:
ret = setsockopt(s, IPPROTO_IP, IP_HDRINCL, (char *)&bOpt, sizeof(bOpt));

I built IP and TCP header : ipHdr and tcpHdr with specific settings.

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("");;

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

( 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.


Jul 19 '05 #1
2 2361
"grzybek" <gr*****@freebsd.gze.pl> wrote in message

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

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


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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.