LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   #define Question (https://www.linuxquestions.org/questions/programming-9/define-question-782410/)

SeymourButts 01-15-2010 10:19 AM

#define Question
 
I am not familar with the pipes with the values. What value does OBJECT_ID_tag have in this context?

Code:

/* -- Tag class encoding -- */
#define UNIVERSAL        0x00
#define APPLICATION      0x40
#define CONTEXTSPECIFIC  0x80
#define PRIVATE          0xC0

/* -- Tag primitive/contructed form -- */
#define PRIMITIVE        0x00
#define CONSTRUCT        0x20

/* -- SNMP Tags -- */
#define INTEGER_tag          ( UNIVERSAL  | PRIMITIVE | 0x02 )
#define OCTET_STRING_tag    ( UNIVERSAL  | PRIMITIVE | 0x04 )
#define NULL_tag            ( UNIVERSAL  | PRIMITIVE | 0x05 )
#define OBJECT_ID_tag        ( UNIVERSAL  | PRIMITIVE | 0x06 )
#define SEQUENCE_tag        ( UNIVERSAL  | CONSTRUCT | 0x10 )
#define SET_OF_tag          ( UNIVERSAL  | CONSTRUCT | 0x11 )


Sergei Steshenko 01-15-2010 10:23 AM

Quote:

Originally Posted by SeymourButts (Post 3827639)
I am not familar with the pipes with the values. What value does OBJECT_ID_tag have in this context?

Code:

/* -- Tag class encoding -- */
#define UNIVERSAL        0x00
#define APPLICATION      0x40
#define CONTEXTSPECIFIC  0x80
#define PRIVATE          0xC0

/* -- Tag primitive/contructed form -- */
#define PRIMITIVE        0x00
#define CONSTRUCT        0x20

/* -- SNMP Tags -- */
#define INTEGER_tag          ( UNIVERSAL  | PRIMITIVE | 0x02 )
#define OCTET_STRING_tag    ( UNIVERSAL  | PRIMITIVE | 0x04 )
#define NULL_tag            ( UNIVERSAL  | PRIMITIVE | 0x05 )
#define OBJECT_ID_tag        ( UNIVERSAL  | PRIMITIVE | 0x06 )
#define SEQUENCE_tag        ( UNIVERSAL  | CONSTRUCT | 0x10 )
#define SET_OF_tag          ( UNIVERSAL  | CONSTRUCT | 0x11 )


Your question is very strange from a number of points of view:
  1. OBJECT_ID_tag conceptually is no different from, say INTEGER_tag, so why are you asking specifically about OBJECT_ID_tag ?
  2. what do pipes have to do with the above ?
.

At all, have you ever heard of bitwise operations in "C" and other languages and/or about bitfields and operations on/over/with them ?

SeymourButts 01-15-2010 10:43 AM

I have a C program that builds and sends snmp traps. Been trying to port this program from Solaris to Linux. I ran the program using valgrind and it says there is a Memory Fault on the bolded build_tag() function below when the OBJECT_ID_tag is the first parm.

I have no idea why so I am trying diagnose what's going on.


/* valgrind error message*/
==1072== Invalid write of size 1
==1072== at 0x410A8C: build_tag (ber.c:160)


Code:

unsigned char *ucPollerId = 215;
...
unsigned long OIDpollerid [] = { 1, 3, 6, 1, 4, 1,74,2,7308,1, 19};
unsigned long OIDpollerid_length = 11;
...
ucPacket = build_oct (ucPollerId, strlen (ucPollerId),  ucPacket);
ucPacket = build_tag (OCTET_STRING_tag, ucPacket);
ber_oid = OIDpollerid + 1;
*ber_oid = OIDpollerid [0] * 40 + OIDpollerid [1];
ucPacket = ucbuild_oid (ber_oid, OIDpollerid_length - 1, ucPacket);
...
ucPacket = build_tag (OBJECT_ID_tag, ucPacket);
...


Sergei Steshenko 01-15-2010 10:55 AM

Quote:

Originally Posted by SeymourButts (Post 3827668)
I have a C program that builds and sends snmp traps. Been trying to port this program from Solaris to Linux. I ran the program using valgrind and it says there is a Memory Fault on the bolded build_tag() function below when the OBJECT_ID_tag is the first parm.

I have no idea why so I am trying diagnose what's going on.


/* valgrind error message*/
==1072== Invalid write of size 1
==1072== at 0x410A8C: build_tag (ber.c:160)


Code:

unsigned char *ucPollerId = 215;
...
ucPacket = build_oct (ucPollerId, strlen (ucPollerId),  ucPacket);
ucPacket = build_tag (OCTET_STRING_tag, ucPacket);
ber_oid = OIDpollerid + 1;
*ber_oid = OIDpollerid [0] * 40 + OIDpollerid [1];
ucPacket = ucbuild_oid (ber_oid, OIDpollerid_length - 1, ucPacket);
...
ucPacket = build_tag (OBJECT_ID_tag, ucPacket);
...


You haven't answered my questions which makes my suspicions even stronger. The suspicions are that you lack very basic knowledge in "C"/programming in general.

Please answer my questions first.

If I'm not clear, the very first sentence of yours:

Quote:

I am not familar with the pipes with the values
makes me very suspicious - the question indicates you simply do not know what '|' character means, and this knowledge belongs to the category of very basic knowledge of "C".

Or, to put it bluntly, the quoted very first sentence of yours invalidates the whole question or, in other words, makes it senseless/pointless.

SeymourButts 01-15-2010 11:16 AM

Wow, that's quite an attitude your packing there.

The "|" I referenced represents a Bitwise OR operation. My extreme apologies for calling it a pipe. What was I thinking.

Since I am not an expert, unlike yourself, I tend to ask questions in the spritit of LinuxQuestions dot org.

johnsfine 01-15-2010 11:43 AM

Quote:

Originally Posted by SeymourButts (Post 3827703)
Wow, that's quite an attitude your packing there.

The "|" I referenced represents a Bitwise OR operation. My extreme apologies for calling it a pipe. What was I thinking.

We can't read your mind. Calling the bitwise OR operator a "pipe" was enough to completely obscure the nature of your question (given that you also provided so little basic info about your question).

I couldn't have done a better job than Sergei at trying to guess what you meant and/or explain why you needed to ask the question in a way we can understand. There really was nothing wrong with Sergei's "attitude".

Back on topic:

I'm not sure I trust valgrind in this situation, but assuming we trust it, or just because you gave no other hint of what we need to look at:

We would need to see the declaration of ucPacket and the definition of build_tag in order to get some idea about the problem that you want us to help you with.

Sergei Steshenko 01-15-2010 11:46 AM

Quote:

Originally Posted by SeymourButts (Post 3827703)
Wow, that's quite an attitude your packing there.

The "|" I referenced represents a Bitwise OR operation. My extreme apologies for calling it a pipe. What was I thinking.

Since I am not an expert, unlike yourself, I tend to ask questions in the spritit of LinuxQuestions dot org.

So, then the next part of your question remains:

Quote:

I am not familar with the pipes with the values
.

I.e., taking into account your clarification and substituting 'pipes' with "Bitwise OR operation", your question/statement is legitimately transformed into:

I am not familiar with "Bitwise OR operation" with numbers.

And I have already addressed this in my reply - you need to learn about bitfields and operations over/on/with them.

Your (transformed) question still doesn't make sense to me - because it may imply that you do know about bitwise operations, but just do not know about bitwise operations in case one of the operands is a number.

I suggest to enter

C bitwise bitfield bitmask

into your favorite WEB search engine - the above search items are common knowledge. You might also spell the search query this way:

C bitwise bit field mask
.

From your post regarding SNMP it looks like you are dealing with SW working pretty closely to/with HW. In such a case knowledge of bitwise operations and bit fields/masks is an absolute must.

Conceptually your question is very similar to a request to explain how, say, multiplication works in terms of additions, or how addition is performed in a radix system and how/what for carry in/out is used - again, it's a common basic knowledge.

SeymourButts 01-15-2010 12:01 PM

Quote:

Originally Posted by johnsfine (Post 3827735)
Back on topic:

I'm not sure I trust valgrind in this situation, but assuming we trust it, or just because you gave no other hint of what we need to look at:

We would need to see the declaration of ucPacket and the definition of build_tag in order to get some idea about the problem that you want us to help you with.


/* On Linux */
printf ("Pointer Before Start of Encoding : %p\n", ucPacket);

0x7feffcb20

/* On Solaris */
printf ("Pointer Before Start of Encoding : %p\n", ucPacket);

ffbebffc


Code:

unsigned char buffer [4096];
unsigned char *p,*q;
/* Set pointer to end of buffer space for subsequent BER encoding in reverse */
memset (buffer, 0, sizeof (buffer));
q = &buffer [sizeof (buffer)];  /* Pointing to next byte beyond end of buffer */
p = q;

/* Build a BER encoded SNMP v2 Trap packet */

p = ucBuildSNMPv2Trap (p);
               
/* Returns pointer to first encoded byte */


unsigned char* ucBuildSNMPv2Trap (unsigned char *ucPacket)


ucPacket = build_tag (OBJECT_ID_tag, ucPacket);


/* -- REQUIRES: tag number < 31 -- */
uchar* build_tag( register uchar x, register uchar* p ){
  *--p = x;
  return p;
}


Sergei Steshenko 01-15-2010 12:26 PM

Quote:

Originally Posted by SeymourButts (Post 3827749)
/* On Linux */
printf ("Pointer Before Start of Encoding : %p\n", ucPacket);

0x7feffcb20

/* On Solaris */
printf ("Pointer Before Start of Encoding : %p\n", ucPacket);

ffbebffc


Code:

unsigned char buffer [4096];
unsigned char *p,*q;
/* Set pointer to end of buffer space for subsequent BER encoding in reverse */
memset (buffer, 0, sizeof (buffer));
q = &buffer [sizeof (buffer)];  /* Pointing to next byte beyond end of buffer */
p = q;

/* Build a BER encoded SNMP v2 Trap packet */

p = ucBuildSNMPv2Trap (p);
               
/* Returns pointer to first encoded byte */


unsigned char* ucBuildSNMPv2Trap (unsigned char *ucPacket)


ucPacket = build_tag (OBJECT_ID_tag, ucPacket);


/* -- REQUIRES: tag number < 31 -- */
uchar* build_tag( register uchar x, register uchar* p ){
  *--p = x;
  return p;
}


What sense do

Code:

printf ("Pointer Before Start of Encoding : %p\n", ucPacket);

0x7feffcb20

/* On Solaris */
printf ("Pointer Before Start of Encoding : %p\n", ucPacket);

ffbebffc

have ? I.e. what sense does a hexadecimal pointer value make to an outside observer if only one pointer value is displayed ? Had it been zero, it would have been an indication of something, but since it's a non-zero pointer, what conclusions can be made ?

My point is that pointer values make sense relative to each other (no, I don't mean Linux relative to Solaris) taking into account object sizes.

So, in more general terms, why/what for just a pointer value and nothing else is printed ? I.e. what kind of debugging methodology is it supposed to reflect ?

SeymourButts 01-15-2010 12:33 PM

I am just trying to find the differences between Solaris and Linux and having the extra "0x7" in there on the Linux env seemed noteworthy. I guess it's not.

Sergei Steshenko 01-15-2010 12:38 PM

Quote:

Originally Posted by SeymourButts (Post 3827781)
I am just trying to find the differences between Solaris and Linux and having the extra "0x7" in there on the Linux env seemed noteworthy. I guess it's not.

Look, I'm serious - (re)learn "C". Your questions and your approaches make no sense to me whatsoever.

SeymourButts 01-15-2010 12:45 PM

Quote:

Originally Posted by Sergei Steshenko (Post 3827785)
Look, I'm serious - (re)learn "C". Your questions and your approaches make no sense to me whatsoever.

Your attitude makes no sense to me. Look, I'm serious learn some "Manners".

carbonfiber 01-15-2010 12:47 PM

-- OFFTOPIC --

Sergei Steshenko: A personal request, if I may. Could you please not start your posts with a "Quote" of the whole post you are replying to, espcially when you are replying to the last post in a thread? It is fairly disturbing when reading the thread top to bottom (and not only).

If I also may, you said: "Your questions and your approaches make no sense to me whatsoever.". Why do you not give up on the thread, then? Your posts would seem to indicate that SeymourButts has been irrefutably denied help in this matter. This is not for you to decide. The thread's reply count keeps getting incremented, and potential helpers might lose interest, thinking the OP has been given an answer, etc.

johnsfine 01-15-2010 01:30 PM

Quote:

Originally Posted by SeymourButts (Post 3827749)
/* On Linux */
printf ("Pointer Before Start of Encoding : %p\n", ucPacket);

0x7feffcb20

/* On Solaris */
printf ("Pointer Before Start of Encoding : %p\n", ucPacket);

ffbebffc

That was not what I asked for. I wanted the declaration. You gave me the value.

It was however, unexpectedly useful information.

A common cause of porting issues similar to those you experienced is that the original programmer made inappropriate assumptions about the relative sizes of objects such as void* and int.

I thought about asking about those, but it seemed both a long shot and a hard question. Solaris has void* either 4 bytes or 8 bytes, but 8 is more common. Linux has void* also either 4 bytes or 8 bytes, with 4 more common. Suspecting a change in sizeof(void*) as a significant component of the bug is only likely if it changed from 4 to 8, which is unusual when changing from Solaris to Linux.

But in fact, by showing me the values, you did show me the sizes and sizeof(void*) was 4 in your Solaris system and 8 in your Linux system.

Code:

unsigned char buffer [4096];
I also asked for the definition of build_tag. Since you left off the top of that function definition, I don't know what it is, but I don't think it is the definition of build_tag.

My just guessing that the change in size of void* is an important factor in the bug, is not enough. We need to find the code that contains the inappropriate assumptions about the size of void*

Quote:

Originally Posted by Sergei Steshenko (Post 3827774)
what sense does a hexadecimal pointer value make to an outside observer if only one pointer value is displayed ? Had it been zero, it would have been an indication of something, but since it's a non-zero pointer, what conclusions can be made ?

You can conclude that %p displays a 64bit address in that Linux system, so you can conclude the code was compiled as x86_64, not x86.
You can be moderately confident that %p displays a 32bit address in that Solaris system (a 64 bit address with the high 32 bits zero is possible but on Solaris in this context, unlikely).

I also find it frustrating that the OP is neither using nor apparently understanding basic C programming terminology. That make discussing the real problem difficult. I would have complained about that myself if you hadn't already complained about it more than enough.

But at this point I'm joining the viewpoint that you're complaining about the flaws in the OP's posts too much and you're apparently not trying to help.

jf.argentino 01-15-2010 01:38 PM

Quote:

Your attitude makes no sense to me. Look, I'm serious learn some "Manners".
Sorry but, it's not a rude attitude to tell you to (re)learn some C basics, it looks like you've a not too easy job to do, but you are not good enough with some C programming basic concepts. You'll gain plenty of time to follow Sergei's advice.
There's no shame to have to learn something, so you don't have to take it as an attack!
Seeing how you're responding doesn't give me the like to help you, and maybe I'm not the only one!
To end, Sergei was thanked 56 times... So his posts make sense for some people around there...


All times are GMT -5. The time now is 10:11 AM.