• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSData. add 6 bytes to NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSData. add 6 bytes to NSData


  • Subject: Re: NSData. add 6 bytes to NSData
  • From: Carlo Gulliani <email@hidden>
  • Date: Sat, 4 Jul 2009 09:23:00 -0700 (PDT)

thanks for your reply, could you show me simple example how to add binary data to existing data and also to add header of 2 bytes

i've been trying to use buffer but i have a troubles with result

my code:

#define PROTO_VERSION_MAJOR     1
#define PROTO_VERSION_MINOR     7
#define PROTO_VERSION ((((u_long)(PROTO_VERSION_MAJOR))<<16)|(u_long)(PROTO_VERSION_MINOR))


#define PROTO_MAJOR(p) (((p)&0xFFFF0000)>>16)
#define PROTO_MINOR(p) ((p)&0x0000FFFF)


typedef struct mrim_packet_header_t
{
    u_long      magic;
    u_long      proto;
    u_long      seq;
    u_long      msg;
    u_long      dlen;
    u_longfrom;
    u_longfromport;
    u_charreserved[16];
}
mrim_packet_header_t;

#define CS_MAGIC    0xDEADBEEF

#define MRIM_CS_HELLO       0x1001

structmrim_packet_header_tpacket;
packet = [self makePacket:MRIM_CS_HELLO length:0];
NSMutableData *data = [NSData dataWithBytes:&packet length:sizeof(packet)];
int c = 4;
char buf[c];
[data getBytes:buf];
int i;
for (i=20; i<[data length]+c; i++)
{
buf[i] = 0;
}
data = [NSData dataWithBytes:buf length:[data length]+c];
}

-(struct mrim_packet_header_t) makePacket:(unsigned long)key length:(unsigned long)len
{
staticunsignedlongseq = 2;
mrim_packet_header_tmrim_head;
//memset(&mrim_head, 0, sizeof (mrim_head));
mrim_head.magic = CS_MAGIC;
mrim_head.proto = PROTO_VERSION;
mrim_head.seq = seq;
mrim_head.msg = key;
mrim_head.dlen = len;
//mrim_head.from = h;
//mrim_head.fromport = 2041;
seq++;
    return mrim_head;
}

so, i found a dump of binary which must to result

0000 efbeadde 13000100 02000000 01100000 00100000 00000000 00000000 00000000 00000020 00000000 00000000 00000000

but i got

efbeadde 07000100 00000000 01100000 00000000 00000000 00000000 00286930 4cc40000 58e4ffbf 36c90091 00000000

my data is different of correct data, why? I use the same variables like there



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSData. add 6 bytes to NSData
      • From: Scott Andrew <email@hidden>
  • Prev by Date: Re: Send files from iphone
  • Next by Date: Re: leaking UIColor objects
  • Previous by thread: Re: NSData. add 6 bytes to NSData
  • Next by thread: Re: NSData. add 6 bytes to NSData
  • Index(es):
    • Date
    • Thread