Index: agent/mibgroup/agentx/protocol.c
===================================================================
--- agent/mibgroup/agentx/protocol.c	(Revision 19663)
+++ agent/mibgroup/agentx/protocol.c	(Arbeitskopie)
@@ -677,8 +677,19 @@
     session->s_snmp_errno = 0;
     session->s_errno = 0;
 
+	/* We've received a PDU that has specified a context.  NetSNMP however, uses
+	 * the pdu->community field to specify context when using the AgentX
+	 * protocol.  Therefore we need to copy the context name and length into the
+	 * pdu->community and pdu->community_len fields, respectively. */
+	if (pdu->contextName != NULL && pdu->community == NULL)
+	{	
+		pdu->community     = (u_char *) strdup(pdu->contextName);
+		pdu->community_len = pdu->contextNameLen;
+		pdu->flags |= AGENTX_MSG_FLAG_NON_DEFAULT_CONTEXT;  // may be wrong, se below!
+	}
+
     /*
-     * Various PDU types don't include context information (RFC 2741, p. 20). 
+     * Various PDU types don't include context information (RFC 2741, p. 20)! 
      */
     switch (pdu->command) {
     case AGENTX_MSG_OPEN:
@@ -687,20 +698,9 @@
     case AGENTX_MSG_COMMITSET:
     case AGENTX_MSG_UNDOSET:
     case AGENTX_MSG_CLEANUPSET:
-        pdu->flags &= ~(AGENTX_MSG_FLAG_NON_DEFAULT_CONTEXT);
+        pdu->flags &= ~(AGENTX_MSG_FLAG_NON_DEFAULT_CONTEXT);   // now fix the flag
     }
 
-	/* We've received a PDU that has specified a context.  NetSNMP however, uses
-	 * the pdu->community field to specify context when using the AgentX
-	 * protocol.  Therefore we need to copy the context name and length into the
-	 * pdu->community and pdu->community_len fields, respectively. */
-	if (pdu->contextName != NULL && pdu->community == NULL)
-	{	
-		pdu->community     = (u_char *) strdup(pdu->contextName);
-		pdu->community_len = pdu->contextNameLen;
-		pdu->flags |= AGENTX_MSG_FLAG_NON_DEFAULT_CONTEXT;
-	}
-
     /*
      * Build the header (and context if appropriate).  
      */
@@ -1006,7 +1006,7 @@
 
     agentx_build_int((*buf + 16), (*out_len - ilen) - 20, network_order);
 
-    DEBUGMSGTL(("agentx_build", "packet built okay\n"));
+    DEBUGMSGTL(("agentx_build", "packet build okay\n"));
     return 1;
 }
 
