windows-nt/Source/XPSP1/NT/net/snmp/common/dll/string.c
2020-09-26 16:20:57 +08:00

142 lines
2.8 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*++
Copyright (c) 1992-1997 Microsoft Corporation
Module Name:
string.c
Abstract:
Contains string conversion routines.
SnmpUtilIdsToA
SnmpUtilOidToA
Environment:
User Mode - Win32
Revision History:
--*/
///////////////////////////////////////////////////////////////////////////////
// //
// Include files //
// //
///////////////////////////////////////////////////////////////////////////////
#include <snmp.h>
#include <snmputil.h>
#include <stdio.h>
///////////////////////////////////////////////////////////////////////////////
// //
// Private Definitions //
// //
///////////////////////////////////////////////////////////////////////////////
#define MAX_STRING_LEN 512
#define MAX_SUBIDS_LEN 16
///////////////////////////////////////////////////////////////////////////////
// //
// Public Procedures //
// //
///////////////////////////////////////////////////////////////////////////////
LPSTR
SNMP_FUNC_TYPE
SnmpUtilIdsToA(
UINT * pIds,
UINT nIds
)
/*++
Routine Description:
Converts OID subidentifiers into string.
Arguments:
pIds - pointer to subidentifiers.
nIds - number of subidentifiers.
Return Values:
Returns pointer to string representation.
--*/
{
UINT i;
UINT j;
static char szBuf[MAX_STRING_LEN+MAX_SUBIDS_LEN];
static char szId[MAX_SUBIDS_LEN];
if ((pIds != NULL) && (nIds != 0)) {
j = sprintf(szBuf, "%d", pIds[0]);
for (i = 1; (i < nIds) && (j < MAX_STRING_LEN); i++) {
j += sprintf(szId, ".%d", pIds[i]);
if (j >= (MAX_STRING_LEN + MAX_SUBIDS_LEN)-3)
{
strcat(szBuf, "...");
break;
}
else
strcat(szBuf, szId);
}
} else {
sprintf(szBuf, "<null oid>");
}
return szBuf;
}
LPSTR
SNMP_FUNC_TYPE
SnmpUtilOidToA(
AsnObjectIdentifier * pOid
)
/*++
Routine Description:
Converts OID into string.
Arguments:
pOid - pointer to object identifier.
Return Values:
Returns pointer to string representation.
--*/
{
UINT * pIds = NULL;
UINT nIds = 0;
if (pOid != NULL) {
pIds = pOid->ids;
nIds = pOid->idLength;
}
return SnmpUtilIdsToA(pIds, nIds);
}