Variable and pointer

J

Julia

I am a n00b to c, so have pitty on me if I ask dumb questions :).
I have a function (testframe() ) that has needs a pointer to a 6 byte MAC
address as input. The input is an unsigned 8 bit char pointer.
This pointer should then point to the 6 byte MAC address stored somewhere.
How do I actually write this in code? An integer is only 32 bit, so how do I
have something holding the MAC Address and more again, how do I create a
pointer pointing to this "something".

Julia
 
D

Dan Pop

In said:
I am a n00b to c, so have pitty on me if I ask dumb questions :).
I have a function (testframe() ) that has needs a pointer to a 6 byte MAC
address as input. The input is an unsigned 8 bit char pointer.
This pointer should then point to the 6 byte MAC address stored somewhere.
How do I actually write this in code? An integer is only 32 bit, so how do I
have something holding the MAC Address and more again, how do I create a
pointer pointing to this "something".

unsigned char macaddr[6], *p = macaddr;

Dan
 
K

Kevin Easton

Julia said:
I am a n00b to c, so have pitty on me if I ask dumb questions :).
I have a function (testframe() ) that has needs a pointer to a 6 byte MAC
address as input. The input is an unsigned 8 bit char pointer.
This pointer should then point to the 6 byte MAC address stored somewhere.
How do I actually write this in code? An integer is only 32 bit, so how do I
have something holding the MAC Address and more again, how do I create a
pointer pointing to this "something".

unsigned char mac[6] = { 0x00, 0xC0, 0x4F, 0xDD, 0xB8, 0x73 };

then just pass "mac". An array (like "mac") is evaluated as a pointer
to its first subobject unless it is the operand of unary-& or sizeof, so
you don't need to do anything special to create the pointer.

- Kevin.
 
T

Thomas Matthews

Julia said:
I am a n00b to c, so have pitty on me if I ask dumb questions :).
I have a function (testframe() ) that has needs a pointer to a 6 byte MAC
address as input. The input is an unsigned 8 bit char pointer.
This pointer should then point to the 6 byte MAC address stored somewhere.
How do I actually write this in code? An integer is only 32 bit, so how do I
have something holding the MAC Address and more again, how do I create a
pointer pointing to this "something".

Julia

Most applications treat MAC addresses as a collection of
octects (bytes). Just access it via pointer to unsigned
char. If the processor wants to promote the 8-bit u.c.
to a 32-bit unsigned integer, let it. Some processors
actually fetch the 8 bits into a 32-bit register.

If you need more help, please post a code fragment
demonstrating what you are doing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top