binary file sent from windows -> linux help needed
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: binary file sent from windows -> linux help needed

  1. #1
    Join Date
    Mar 2009
    Posts
    166

    binary file sent from windows -> linux help needed

    Hello,

    I am sending an encrypted binary file over tcp/ip form windows to linux. When I get into linux and try to run mcrypt to decrypt the file I get "wrong key" error. I am wondering somehow if the file is being corrupted because of the different platforms? Here are some facts I do know:

    1. This works with the exact same code windows->windows
    2. My file where I write the binary form the tcp/ip stream looks like this:

    void StringToFile(string msg, string file)
    {
    ofstream ofs(file.c_str(), ofstream::binary);
    ofs.clear();
    ofs.write(msg.data(), message.size());
    ofs.close();
    }

    Can anyone help?

    Regards,
    Ellay K.

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,569

    Re: binary file sent from windows -> linux help needed

    Is that actual code or did you just type it in ? The reason I am asking:

    Code:
    ofs.write(msg.data(), message.size());

  3. #3
    Join Date
    Mar 2009
    Posts
    166

    Re: binary file sent from windows -> linux help needed

    I just typed it in.. that is a typo.. the actual code is:

    ofs.write(msg.data(), msg.size());

    Thanks..; any idea what might be going wrong?

    Regards,
    Ellay K.

  4. #4
    Join Date
    Mar 2009
    Posts
    166

    Re: binary file sent from windows -> linux help needed

    One additional piece of information.. this is how I write files to strings:

    Code:
    string WriteFileToString(string filename)
    {
    	ifstream infile(filename.c_str(), ifstream::binary);
    	infile.seekg(0,ios::end);
    	size_t length = infile.tellg();
    	infile.seekg(0, ios::beg);
    	string message(length, 0);
    	copy(istreambuf_iterator<char>(infile), istreambuf_iterator<char>(), message.begin());
    	return message;
    }
    I am wondering if the line return difference between unix and windows is my problem? I dont know how to fix that.

    Regards,
    Ellay K.

  5. #5
    Join Date
    Mar 2009
    Posts
    166

    Re: binary file sent from windows -> linux help needed

    Another interesting piece of information. If I write the message in the code like this:

    Code:
    string msg="<?xml version=\"1.0\" encoding=\"UTF-8\"?> <Status> <Time>1246650079</Time> <Msg_ID>73</Msg_ID> <Name>Testing </Name>";
    it works both windows->windows and windows->linux

    however if I write it like this:

    Code:
    string msg="<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
    					      <Status> \
    						   <Time>1246650079</Time> \
    						      <Msg_ID>73</Msg_ID> \
    						       <Name>Testing </Name>";
    It only works windows->windows and not windows to linux.

  6. #6
    Join Date
    Mar 2009
    Posts
    166

    Re: binary file sent from windows -> linux help needed

    It also seems to work with linux with less than 170 characters.. more than 170 characters it crashes.. can anyone help me?

    Regards,
    Ellay K.

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: binary file sent from windows -> linux help needed

    The most common reason why using multiple lines would cause a problem is differing newline conventions between the platforms. However, if you're opening all your files (for reading and writing) in binary mode, that shouldn't be a problem.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center