A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » need help in unix c programming

#1 2010-04-08 12:40 AM


Re: need help in unix c programming

struct Employee_Details
{       char [20]
        long int 
        char [20]

#2 2010-04-08 12:59 PM

From: Boston, MA
Registered: 2002-06-12
Posts: 3,839

Re: need help in unix c programming

What sort of garbage?  Are you sure the garbage is coming from the file, and not
just a problem with sending it over the network?  Ie: have you added debugging code
to the sending side to log exactly what it read from the file, to compare against what
you receive over the network?

Because, if that code is really as you show it with no checking of return values or
handling of short reads/writes, then that could definitely be your problem, assuming
your using a TCP socket...  TCP is a stream protocol, so every send()/write() you do
does NOT necessarily correlate into a single corresponding recv()/read() on the
other end...  It's entirely possible for both sending and receiving to return short
counts, in which case you need to loop to send/receive the rest...  Plus, of course,
you should be checking for errors and EOF, not only on the socket I/O but also the
file I/O...  (Right now, it looks to me like your search loop will inifinitely loop if it fails
to find the target record in the file...)

Also, are the sender and receiver of this data both on identical systems?  Because,
if not, you really shouldn't be sending structs of that nature across the network as-is...
Things such as integer endianness and float representation can vary between
platforms, and structure alignment/padding can vary even among compilers, let
alone platforms...  And, sizeof(time_t) and sizeof(long) also varies between 32-bit
and 64-bit systems...


  • Index
  • » C
  • » need help in unix c programming

Board footer

Powered by FluxBB