Gnutella Forums  

Go Back   Gnutella Forums > Gnutella News and Gnutelliums Forums > General Gnutella Development Discussion
Register FAQ The Twelve Commandments Members List Calendar Arcade Find the Best VPN Today's Posts

General Gnutella Development Discussion For general discussion about Gnutella development.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old April 24th, 2002
Disciple
 
Join Date: April 3rd, 2002
Posts: 10
Cerebro is flying high
Question Header struct

I make this struct:
char ID[16];
char payloadID;
char TTL;
char Hops;
int payloadlen;

But sizeof(mystruct) = 24 ¿? It seems to be 23 bytes long. It MUST to be 23 bytes long.

Help me, please.
Reply With Quote
  #2 (permalink)  
Old April 24th, 2002
Gnutella Veteran
 
Join Date: March 24th, 2002
Location: Virginia
Posts: 101
tshdos is flying high
Default

sizeof() returns the total storage bytes of the struct including padded bytes for alignment. It is returning 24 because of a
byte that was added for alignment.

The format of your structure looks fine except payloadID, TTL, Hops, and payloadlen should probably be unsigned.

Last edited by tshdos; April 24th, 2002 at 05:21 PM.
Reply With Quote
  #3 (permalink)  
Old April 25th, 2002
Disciple
 
Join Date: April 3rd, 2002
Posts: 10
Cerebro is flying high
Default

Thanks for answer.
I have to copy it to a string to send header. I must copy 24 or 23 bytes? (because protocol says must to be 23 bytes). How can I copy?
Reply With Quote
  #4 (permalink)  
Old April 25th, 2002
Gnutella Veteran
 
Join Date: March 24th, 2002
Location: Virginia
Posts: 101
tshdos is flying high
Default

You shouldn't have to copy it to a string in order to send it, just pass a pointer to the struct. Only copy/send 23 bytes either way you do it. If you really need to copy it to a string just use memcpy.
Reply With Quote
  #5 (permalink)  
Old April 25th, 2002
Disciple
 
Join Date: April 3rd, 2002
Posts: 10
Cerebro is flying high
Default

Yes, I copy it with memcpy, but I must specify the size. And, if sizeof says 24bytes, I should copy 24bytes, however I need 23 bytes. Thats my problem.
You say I must send a pointer to struct, mmm, if I send a pointer to data on my computer to another PC, I think it will not work.

Thanks for answer.
Reply With Quote
  #6 (permalink)  
Old April 25th, 2002
Gnutella Veteran
 
Join Date: March 24th, 2002
Location: Virginia
Posts: 101
tshdos is flying high
Default

Quote:
Yes, I copy it with memcpy, but I must specify the size. And, if sizeof says 24bytes, I should copy 24bytes, however I need 23 bytes.
memcpy( string, &struct, 23 )

Quote:
You say I must send a pointer to struct, mmm, if I send a pointer to data on my computer to another PC, I think it will not work.
Obviously that would not work. I am saying to pass a pointer to the struct to your send function.

i.e.:
bytes = send( sock, (char*)&struct, 23, 0 )
Reply With Quote
  #7 (permalink)  
Old April 25th, 2002
Disciple
 
Join Date: April 3rd, 2002
Posts: 10
Cerebro is flying high
Thumbs up

Thanks a lot. I will use it.
Reply With Quote
  #8 (permalink)  
Old April 30th, 2002
Disciple
 
Join Date: April 3rd, 2002
Posts: 10
Cerebro is flying high
Default

Failed. I was searching information about this. I found something. A struct can have a diferent size than its elements. it´s happens because there is a byte used to struct.
Then I can´t use this solution. I need to copy element by element.
If someone has some code to do this, please, tell me. I´m working on that.
Reply With Quote
  #9 (permalink)  
Old April 30th, 2002
Unregistered
Guest
 
Posts: n/a
Default

create a small char buffer, memcpy into it and send the buffer. Monitor your serial port and watch to see if the bytes are correct.
Look at other client source code and see how they did it and quit re-inventing the wheel. Even better, use another clients source code and build on top of that so we can get more features instead of more base code that we don't need.
Reply With Quote
  #10 (permalink)  
Old April 30th, 2002
Disciple
 
Join Date: April 3rd, 2002
Posts: 10
Cerebro is flying high
Default

Yes, I read that about wheels before. Bu I need to do that. I try to see another client, but its easiest reinvent the wheel than understand some codes.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Zip Header Geoff114 General Mac Support 1 November 30th, 2005 09:18 AM
zip header Unregistered Download/Upload Problems 2 June 25th, 2002 08:22 AM
Creating header struct Unregistered General Gnutella Development Discussion 3 April 4th, 2002 09:50 AM
help! zip header?? Unregistered Mac OSX 3 March 28th, 2002 07:10 PM
zip header Unregistered Mac OSX 2 March 18th, 2002 06:53 PM


All times are GMT -7. The time now is 01:44 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 ©2011, Crawlability, Inc.

Copyright © 2020 Gnutella Forums.
All Rights Reserved.