delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/01/20/20:21:37

From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: libsocket over the net...
Date: Sun, 21 Jan 2001 00:09:39 +0000
Organization: Customer of Energis Squared
Lines: 60
Message-ID: <3A6A28C3.502361A2@phekda.freeserve.co.uk>
References: <3A69FEFF DOT 7020104 AT operamail DOT com>
NNTP-Posting-Host: modem-21.uranium.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: newsg2.svr.pol.co.uk 980039787 29326 62.136.65.149 (21 Jan 2001 01:16:27 GMT)
NNTP-Posting-Date: 21 Jan 2001 01:16:27 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.17 i586)
X-Accept-Language: de,fr
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello.

Sahab Yazdani wrote:
> i am attempting to test my application (which uses libsocket) for over
> the net usage.  It doesn't work.  It accepts the connection from the
> client, but then whatever packets I send get garbled up

How are they garbled? Are the data in the wrong order? Do you get any of
the sent data when you do recv()?

> (do I have to make everything in packet structures network edian??)

Only if you want to send data between machines with different endianness,
i.e. if you want your program to be portable. If you only want to use
Intel PCs, then you don't have to worry about this.

[snip]
> I have included the source code for the actual transmission and receive
> of packets with this message in the hope that somebody on this newsgroup
> might be able to help me out...

I have some comments below:

[snip]
>         strcpy(retType.header, "MASS.NET\0" );

You don't need to use a nul character to terminate a string in "".
"MASS.NET" is a nul-terminated string. 'MASS.NET' is not nul-terminated
(notice the single quotes).

[snip]
>         if ( send( sock, (void *) &header, sizeof( MassacreHeader ), 0 )!=sizeof( MassacreHeader ) )

I recommend that you always store the send() return code. It makes
debugging and recovery from error easier. E.g.:

    ...
    ret = send(...);
    if (ret < 0)
      perror("uh-oh");
    ...

[snip]
>                             lsck_perror("ERROR");

lsck_perror() is obsolete now - libsocket comes with a modified versions
of perror() and strerror() that handle socket error codes.

I cannot see anything obviously wrong with your program. You have packed
the data structures for transmission, which is a wise idea. I realise this
post is not much help, but if you could describe how the data is garbled,
I may be able to help better.

Bye,

-- 
Richard Dawe <richdawe AT bigfoot DOT com> http://www.bigfoot.com/~richdawe/ 

"The soul is the mirror of an indestructible universe."
--- Gottfried W. Leibniz

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019