IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Console flux de sortie


Sujet :

C++

  1. #41
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    J'ai essayé ton code mais j'ai une erreur :

    [C++ Erreur] Unit1.cpp(41): E2285 Impossible de trouver une correspondance pour 'string::basic_string(unsigned char *,unsigned int)'

  2. #42
    Membre très actif

    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2011
    Messages
    685
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2011
    Messages : 685
    Par défaut
    Citation Envoyé par minnesota Voir le message
    J'avais lu en diagonal cette après midi, vite fait, j'ai refait une lecture en diagonal dans l'autre sens, c'est pas mieux

    Je te propose ça, comme ça, vite fait dans le genre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    if (errorStatus==SNMP_ERRORSTATUS_NOERROR){
      AsnAny* any= &snmpVarList.list->value;
      if (any->asnType==ASN_OCTETSTRING)
        cout<< string(any->asnValue.string.stream, any->asnValue.string.length).c_str()<< endl;
    }
    stream est un pointeur sur BYTE qui est une union qui peut valoir ASN_OCTETSTRING, je ne penses pas que ta lecture "à la va vite" soit pertinente.

  3. #43
    Membre Expert
    Inscrit en
    Avril 2010
    Messages
    1 495
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1 495
    Par défaut
    Citation Envoyé par atum25 Voir le message
    J'ai essayé ton code mais j'ai une erreur :

    [C++ Erreur] Unit1.cpp(41): E2285 Impossible de trouver une correspondance pour 'string::basic_string(unsigned char *,unsigned int)'
    essaye en faisant un cast :
    static_cast ou reinterpret_cast

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    cout<< string(static_cast<unsigned char*>(any->asnValue.string.stream), any->asnValue.string.length).c_str()<< endl;
    Vu l'heure, j'ai pas plus relu.

  4. #44
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    essaye en faisant un cast :
    static_cast ou reinterpret_cast


    cout<< string(static_cast<unsigned char*>(any->asnValue.string.stream), any->asnValue.string.length).c_str()<< endl;
    Toujours la meme erreur ...'string::basic_string(unsigned char *,unsigned int)'

  5. #45
    Membre très actif

    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2011
    Messages
    685
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2011
    Messages : 685
    Par défaut
    Citation Envoyé par atum25 Voir le message
    Toujours la meme erreur ...'string::basic_string(unsigned char *,unsigned int)'
    Voici les différents constructeur de string (autrement dit de basic_string<char>) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    string ( );
    string ( const string& str );
    string ( const string& str, size_t pos, size_t n = npos );
    string ( const char * s, size_t n );//celui qui peut marcher avec la solution de Minnesota
    string ( const char * s );
    string ( size_t n, char c );
    template<class InputIterator> string (InputIterator begin, InputIterator end);
    donc normalement, avec ceci :

    cout<< string(static_cast<char*>(any->asnValue.string.stream), any->asnValue.string.length).c_str()<< endl;

    ça devrait marcher.

  6. #46
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    cout<< string(static_cast<char*>(any->asnValue.string.stream), any->asnValue.string.length).c_str()<< endl;
    Cannot cas from 'unsigned char*' to 'char *'

    Je comprend vraiment pas comment fair :S

  7. #47
    Membre très actif

    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2011
    Messages
    685
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2011
    Messages : 685
    Par défaut
    Citation Envoyé par atum25 Voir le message
    Cannot cas from 'unsigned char*' to 'char *'

    Je comprend vraiment pas comment fair :S
    reinterpret_cast à la place de static_cast (unsigned char et char sont considérés comme des types sans relation/sans rapport)

  8. #48
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    reinterpret_cast à la place de static_cast (unsigned char et char sont considérés comme des types sans relation)
    Oui je viens d'essayer, sa compile bien, mais lors de l'execution, il ne ce passe rien

  9. #49
    Membre Expert
    Inscrit en
    Avril 2010
    Messages
    1 495
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1 495
    Par défaut
    J'ai vient d'installé le service snmp sur mon PC pour voir de plus près le problème que tu rencontres, j'ai fait cette ébauche et émis une requête sur lui même, ben avec ce que je t'es indiqué précédemment ça fonctionne : Assure-toi juste que ton oid correspond à une chaine.

    Après, bien sur, il faut tout virer aux profits de quelque chose de plus propre à base de ostringstream...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    #include <windows.h>
    #include <Snmp.h>     //+ lib Snmpapi
    #include <Mgmtapi.h> // + lib mgmtapi
     
    #include <iostream>
    #include <string>
    #include <vector>
     
    #include <cstdio>
     
    using namespace std;
     
    #define TRACE printf
     
    /***********************************************************************
    *      SnmpUtilPrintAsnAny     (SNMPAPI.@) -
    *      http://source.winehq.org/source/dlls/snmpapi/main.c
    */
    VOID WINAPI SnmpUtilPrintAsnAny2(AsnAny *any)
    {
        unsigned int i;
     
        TRACE("(%p)\n", any);
     
        switch (any->asnType)
       {
        case ASN_NULL:       TRACE("Null value\n"); return;
        case ASN_INTEGER32:  TRACE("Integer32 %d\n", any->asnValue.number); return;
        case ASN_UNSIGNED32: TRACE("Unsigned32 %u\n", any->asnValue.unsigned32); return;
        case ASN_COUNTER32:  TRACE("Counter32 %u\n", any->asnValue.counter); return;
        case ASN_GAUGE32:    TRACE("Gauge32 %u\n", any->asnValue.gauge); return;
        case ASN_TIMETICKS:  TRACE("Timeticks %u\n", any->asnValue.ticks); return;
        case ASN_COUNTER64:
        {
            TRACE("Counter64 %x%08x\n", (DWORD)(any->asnValue.counter64.QuadPart>>32),(DWORD)any->asnValue.counter64.QuadPart);
            return;
        }
        case ASN_OCTETSTRING:
        {
            TRACE("String ");
            for (i = 0; i < any->asnValue.string.length; i++)
                TRACE("%c", any->asnValue.string.stream[i]);
            TRACE("\n");
            return;
        }
        case ASN_IPADDRESS:
        {
            TRACE("IpAddress ");
            if (any->asnValue.string.length < 4)
            {
                TRACE("Invalid\n");
                return;
            }
            for (i = 0; i < 4; i++)
            {
                TRACE("%u", any->asnValue.string.stream[i]);
                if (i < 3) TRACE(".");
            }
            TRACE("\n");
            return;
        }
        case ASN_BITS:
        {
            TRACE("Bits ");
            for (i = 0; i < any->asnValue.string.length; i++)
            {
                TRACE("0x%02x", any->asnValue.string.stream[i]);
                if (i < any->asnValue.object.idLength - 1) TRACE(" ");
            }
            TRACE("\n");
            return;
        }
        case ASN_OPAQUE:
        {
            TRACE("Opaque ");
            for (i = 0; i < any->asnValue.string.length; i++)
            {
                TRACE("0x%02x", any->asnValue.string.stream[i]);
                if (i < any->asnValue.object.idLength - 1) TRACE(" ");
            }
            TRACE("\n");
            return;
        }
        case ASN_OBJECTIDENTIFIER:
        {
            TRACE("ObjectID ");
            for (i = 0; i < any->asnValue.object.idLength; i++)
            {
                TRACE("%u", any->asnValue.object.ids[i]);
                if (i < any->asnValue.object.idLength - 1) TRACE(".");
            }
            TRACE("\n");
            return;
        }
        default:
        {
            TRACE("Invalid type %d\n", any->asnType);
            return;
        }
        }
    }
     
     
    int main(int argc, char* argv[]){
     
      vector<string> SNMPErrorInfoInCodes;
      SNMPErrorInfoInCodes.push_back("0 SNMP_ERRORSTATUS_NOERROR:\nThe agent reports that no errors occurred during transmission");
      SNMPErrorInfoInCodes.push_back("1 SNMP_ERRORSTATUS_TOOBIG:\nThe agent could not place the results of the requested SNMP operation in a single SNMP message.");
      SNMPErrorInfoInCodes.push_back("2 SNMP_ERRORSTATUS_NOSUCHNAME:\nThe requested SNMP operation identified an unknown variable.");
      SNMPErrorInfoInCodes.push_back("3 SNMP_ERRORSTATUS_BADVALUE:\nThe requested SNMP operation tried to change a variable but it specified either a syntax or value error.");
      SNMPErrorInfoInCodes.push_back("");
      SNMPErrorInfoInCodes.push_back("");
      SNMPErrorInfoInCodes.push_back("");
      SNMPErrorInfoInCodes.push_back("");
      SNMPErrorInfoInCodes.push_back("");
      SNMPErrorInfoInCodes.push_back("");
     
      SnmpVarBindList snmpVarList;
      AsnInteger errorStatus,errorIndex;
      LPSNMP_MGR_SESSION session;
     
      //Initialisation snmpVarList
      snmpVarList.list = NULL;
      snmpVarList.len = 1;
     
      cout<< "realloc"<< endl;
     
      snmpVarList.list = (SnmpVarBind*) \
        realloc(snmpVarList.list, sizeof(SnmpVarBind) * snmpVarList.len);
     
      cout<< "SnmpMgrOpen"<< endl;
      session = SnmpMgrOpen("127.0.0.1","public",1000,3);
     
      if (!session){
        cout<< "no_session"<< endl;
        return 1;
      }
     
      cout<< "session_ok"<< endl;
     
      //.1.3.6.1.2.1.1.1.0 for system description
      //.1.3.6.1.2.1.1.4.0 for system contact
      //.1.3.6.1.2.1.1.5.0 for system name
      SnmpMgrStrToOid(".1.3.6.1.2.1.1.5.0",
        &snmpVarList.list->name);
     
      cout<< "SnmpMgrStrToOid_ok"<< endl;
     
      //Envoi de la requete
      if (!SnmpMgrRequest(session,SNMP_PDU_GET, &snmpVarList, &errorStatus, &errorIndex)){
        cout<< "SnmpMgrRequest function fails"<< endl;
        SnmpMgrClose(session);
        return 1;}
     
      cout<< "errorStatus: "<< SNMPErrorInfoInCodes[errorStatus]<< endl;
      cout<< endl;
      cout<< "by SnmpUtilPrintAsnAny: "<< endl;
      SnmpUtilPrintAsnAny(&snmpVarList.list->value);
      cout<< endl;
     
      cout<< "by string_constructor only if any->asnType==ASN_OCTETSTRING: "<< endl;
      AsnAny* any= &snmpVarList.list->value;
        if (any->asnType==ASN_OCTETSTRING)
          cout<< "String "<< string(reinterpret_cast<char*>(any->asnValue.string.stream),
                        any->asnValue.string.length).c_str()
            << endl;
      cout<< endl;
      cout<< "by SnmpUtilPrintAsnAny2: "<< endl;
      SnmpUtilPrintAsnAny2(&snmpVarList.list->value);
      cout<< endl;
     
      /*
      if (errorStatus==SNMP_ERRORSTATUS_NOERROR){
        cout<< "no error occurred during transmission"<< endl;
        SnmpUtilPrintAsnAny(&snmpVarList.list->value);
      }
      //*/
     
      cout<< "SnmpMgrClose"<< endl;
      SnmpMgrClose(session);
     
      return 0;
    }

  10. #50
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    Salut tout le monde

    Merci pour ton essai minnesota, lorceque j'éssai ton code cher moi sur mon switch,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
        if (any->asnType==ASN_OCTETSTRING)
          cout<< "String "<< string(reinterpret_cast<char*>(any->asnValue.string.stream),
                        any->asnValue.string.length).c_str()
            << endl;
    Cette parti la du code fais planter le programme =s, et lorceque je le met en commentaire, la fonction SnmpUtilPrintAsnAny affiche bien la chaine, mais la fonction SnmpUtilPrintAsnAny2 n'affiche pas la chaine, je te joint une copie d'ecran de ma console.
    Images attachées Images attachées  

  11. #51
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    J'éssai avec un entier qui represente le numéro de port, avec la fonction SnmpUtilPrintAsnAny de la bibligotheque j'affiche bien "interger32 34" alors qu'avec la fonction SnmpUtilPrintAsnAny2 de minnesota j'affiche "interger32 0". j'ai vraiment besoin de garder ce numéro de port en mémoire

  12. #52
    Membre Expert
    Inscrit en
    Avril 2010
    Messages
    1 495
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1 495
    Par défaut
    Essaye d'appeler SnmpUtilPrintAsnAny en dernier, il n'est pas impossible qu'il y ait eu une réinitialisation suite à son appel. Essaye aussi de faire le test depuis un autre PC à base de Windows XP par exemple. Comme il ne m'est pas possible de reproduire ton problème, je ne vois pas comment t'aider.

    Essaie ceci et montre le résultat, sait-on jamais :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    #include <windows.h>
    #include <Snmp.h>     //+ lib Snmpapi
    #include <Mgmtapi.h> // + lib mgmtapi
     
    #include <iostream>
    #include <string>
    #include <vector>
     
    #include <cstdio>
     
    using namespace std;
     
    #define TRACE printf
     
    /***********************************************************************
    *      SnmpUtilPrintAsnAny     (SNMPAPI.@) -
    *      http://source.winehq.org/source/dlls/snmpapi/main.c
    */
    VOID WINAPI SnmpUtilPrintAsnAny2(AsnAny *any)
    {
        unsigned int i;
     
        TRACE("(%p)\n", any);
     
        switch (any->asnType)
       {
        case ASN_NULL:       TRACE("Null value\n"); return;
        case ASN_INTEGER32:  TRACE("Integer32 %d\n", any->asnValue.number); return;
        case ASN_UNSIGNED32: TRACE("Unsigned32 %u\n", any->asnValue.unsigned32); return;
        case ASN_COUNTER32:  TRACE("Counter32 %u\n", any->asnValue.counter); return;
        case ASN_GAUGE32:    TRACE("Gauge32 %u\n", any->asnValue.gauge); return;
        case ASN_TIMETICKS:  TRACE("Timeticks %u\n", any->asnValue.ticks); return;
        case ASN_COUNTER64:
        {
            TRACE("Counter64 %x%08x\n", (DWORD)(any->asnValue.counter64.QuadPart>>32),(DWORD)any->asnValue.counter64.QuadPart);
            return;
        }
        case ASN_OCTETSTRING:
        {
            TRACE("String ");
            for (i = 0; i < any->asnValue.string.length; i++)
                TRACE("%c", any->asnValue.string.stream[i]);
            TRACE("\n");
            return;
        }
        case ASN_IPADDRESS:
        {
            TRACE("IpAddress ");
            if (any->asnValue.string.length < 4)
            {
                TRACE("Invalid\n");
                return;
            }
            for (i = 0; i < 4; i++)
            {
                TRACE("%u", any->asnValue.string.stream[i]);
                if (i < 3) TRACE(".");
            }
            TRACE("\n");
            return;
        }
        case ASN_BITS:
        {
            TRACE("Bits ");
            for (i = 0; i < any->asnValue.string.length; i++)
            {
                TRACE("0x%02x", any->asnValue.string.stream[i]);
                if (i < any->asnValue.object.idLength - 1) TRACE(" ");
            }
            TRACE("\n");
            return;
        }
        case ASN_OPAQUE:
        {
            TRACE("Opaque ");
            for (i = 0; i < any->asnValue.string.length; i++)
            {
                TRACE("0x%02x", any->asnValue.string.stream[i]);
                if (i < any->asnValue.object.idLength - 1) TRACE(" ");
            }
            TRACE("\n");
            return;
        }
        case ASN_OBJECTIDENTIFIER:
        {
            TRACE("ObjectID ");
            for (i = 0; i < any->asnValue.object.idLength; i++)
            {
                TRACE("%u", any->asnValue.object.ids[i]);
                if (i < any->asnValue.object.idLength - 1) TRACE(".");
            }
            TRACE("\n");
            return;
        }
        default:
        {
            TRACE("Invalid type %d\n", any->asnType);
            return;
        }
        }
    }
     
     
    int main(int argc, char* argv[]){
     
      vector<string> SNMPErrorInfoInCodes;
      //J'avais commencé avec un vector, mais un map est plus indiqué...
      SNMPErrorInfoInCodes.push_back("\
        0 SNMP_ERRORSTATUS_NOERROR:\n\
        The agent reports that no errors occurred during transmission");
      SNMPErrorInfoInCodes.push_back("\
        1 SNMP_ERRORSTATUS_TOOBIG:\n\
        The agent could not place the results of the requested SNMP operation in a \
        single SNMP message.");
      SNMPErrorInfoInCodes.push_back("\
        2 SNMP_ERRORSTATUS_NOSUCHNAME:\n\
        The requested SNMP operation identified an unknown variable.");
      SNMPErrorInfoInCodes.push_back("\
        3 SNMP_ERRORSTATUS_BADVALUE:\n\
        The requested SNMP operation tried to change a variable but it specified \
        either a syntax or value error.");
      SNMPErrorInfoInCodes.push_back("\
        4 SNMP_ERRORSTATUS_READONLY:\n\
        The requested operation tried to change a variable that was not allowed to \
        change according to the community profile of the variable.");
      SNMPErrorInfoInCodes.push_back("\
        5 SNMP_ERRORSTATUS_GENERR:\n\
        An error other than one of those listed here occurred during the requested \
        operation.");
      SNMPErrorInfoInCodes.push_back("\
        UNKNOWNERROR\n");
      SNMPErrorInfoInCodes.push_back("\
        SNMP_MGMTAPI_TIMEOUT:\n\
        The request timed-out.");
      SNMPErrorInfoInCodes.push_back("\
        SNMP_MGMTAPI_SELECT_FDERRORS:\n\
        Unexpected error file descriptors indicated by the Windows Sockets select \
        function.");
     
      SnmpVarBindList snmpVarList;
      AsnInteger errorStatus,errorIndex;
      LPSNMP_MGR_SESSION session;
     
      //Initialisation snmpVarList
      snmpVarList.list= 0;
      snmpVarList.len= 1;
     
      cout<< "realloc"<< endl;
      snmpVarList.list= (SnmpVarBind*) \
        realloc(snmpVarList.list, sizeof(SnmpVarBind) * snmpVarList.len);
     
      int timeOutInmilliseconds= 3000;
      int numberOfRetries= 2;
     
      cout<< "SnmpMgrOpen"<< endl;
      session = SnmpMgrOpen(
                  "127.0.0.1", "public",
                  timeOutInmilliseconds, numberOfRetries
                  );
     
      if (!session){
        cout<< "no_session"<< endl;
        return 1;
      }
     
      cout<< "session_ok"<< endl;
     
      //.1.3.6.1.2.1.1.1.0 for system description
      //.1.3.6.1.2.1.1.4.0 for system contact
      //.1.3.6.1.2.1.1.5.0 for system name
      SnmpMgrStrToOid(".1.3.6.1.2.1.1.5.0",
        &snmpVarList.list->name);
     
      cout<< "SnmpMgrStrToOid_ok"<< endl;
     
      //Envoi de la requete
      if (!SnmpMgrRequest(session,SNMP_PDU_GET, &snmpVarList, &errorStatus, &errorIndex)){
        cout<< "SnmpMgrRequest function fails"<< endl;
        cout<<"errorStatus: "<< errorStatus<< " - errorIndex: "<<errorIndex<< endl;
        switch(::GetLastError()){
          case SNMP_MGMTAPI_TIMEOUT:
            cout<< SNMPErrorInfoInCodes[7]<< endl;
            break;
          case SNMP_MGMTAPI_SELECT_FDERRORS:
            cout<< SNMPErrorInfoInCodes[8]<< endl;
            break;
          default:
            cout<< SNMPErrorInfoInCodes[6]<< endl;
        }
        SnmpMgrClose(session);
        return 1;}
     
      cout<< "errorStatus: \n"<< SNMPErrorInfoInCodes[errorStatus]<< endl;
      cout<< endl;
     
      AsnAny* any= &snmpVarList.list->value;
     
      cout<< endl;
      cout<< "by string_constructor only if any->asnType==ASN_OCTETSTRING: "<< endl;
        if (any->asnType==ASN_OCTETSTRING)
          cout<< "String "
              << string(reinterpret_cast<char*>(any->asnValue.string.stream),
                        any->asnValue.string.length).c_str()
              << endl;
     
      cout<< endl;
      cout<< "balayage (unicode?) only if any->asnType==ASN_OCTETSTRING: "<< endl;
      if (any->asnType==ASN_OCTETSTRING){
       cout<< "String ("<< any->asnValue.string.length<< ") "<< flush;
       for (int i= 0; i < 30; i++)
         cout<< any->asnValue.string.stream[i]<< flush;
      cout<< endl;
      }
     
      cout<< endl;
      cout<< "by SnmpUtilPrintAsnAny2: "<< endl;
      SnmpUtilPrintAsnAny2(&snmpVarList.list->value);
     
      cout<< endl;
      cout<< "by SnmpUtilPrintAsnAny: "<< endl;
      SnmpUtilPrintAsnAny(&snmpVarList.list->value);
     
      cout<< endl;
      cout<< "SnmpMgrClose"<< endl;
      SnmpMgrClose(session);
     
      return 0;
    }

  13. #53
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    Salut,

    Je viens d'essayer ton morceau de code malheureusement, cela ne fonction pas.
    Lorceque je l'execute, tout va bien, aucun code d'erreur mais lorceque j'arive sur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     if (any->asnType==ASN_OCTETSTRING)
          cout<< "String "
              << string(reinterpret_cast<char*>(any->asnValue.string.stream),
                        any->asnValue.string.length).c_str()
              << endl;
    Le programme s'arrete.

    Pareil pour le test suivant, et pour SnmpUtilPrintAnsAny2.
    Si je met tout en commentaire, ma chaine s'affiche bien avec SnmpUtilPrintAsnAny.

    Je ne peux pas trop essayer sur un windows Xp, je vais essayer tt de suite ...
    Voila si tu a une autre idée.Merci

  14. #54
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    le probleme vien du faite que tout est a 0, je joint une copi d'ecran ou j'ai arreter le programme juste avant d'appeler SnmpUtilPrintAsnAny2 et ou j'inspect ma variable tout est a 0
    Images attachées Images attachées  

  15. #55
    Membre Expert
    Inscrit en
    Avril 2010
    Messages
    1 495
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1 495
    Par défaut
    C'est bizarre comme problème, mais comme je ne peux pas le reproduire, je ne vois pas trop. Tu peux éventuellement tester un utilitaire comme snmputil, sinon je peux aussi te filer la version compilée du programme pour tester histoire d'être sûr que c'est pas ton edi-rad qui est en cause...

  16. #56
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    Ouai c'est vraiment bizzar. Je veux bien ta version compiler que j'essai sur mon environnement

  17. #57
    Membre Expert
    Inscrit en
    Avril 2010
    Messages
    1 495
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1 495
    Par défaut
    Y'a trois utilitaires différents, dont la version compilée.
    Fichiers attachés Fichiers attachés

  18. #58
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    Dans le snmp_info, quand tu lance le getinfo.cmd, c'est avec le programme en c++ que tu m'a envoyer?? parceque cela marche très bien cher moi

  19. #59
    Membre Expert
    Inscrit en
    Avril 2010
    Messages
    1 495
    Détails du profil
    Informations forums :
    Inscription : Avril 2010
    Messages : 1 495
    Par défaut
    Oui, avec snmp_info.exe

  20. #60
    Membre confirmé
    Homme Profil pro
    Developpeur
    Inscrit en
    Mars 2012
    Messages
    146
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Developpeur
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2012
    Messages : 146
    Par défaut
    Tu peux m'envoyé le code source complet de ce programme stp, parceque cela marche

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Traiter les flux de sortie
    Par soulhouf dans le forum Linux
    Réponses: 9
    Dernier message: 20/04/2006, 18h48
  2. [Java 1.5] Process : afficher le flux de sortie
    Par Zapan dans le forum API standards et tierces
    Réponses: 2
    Dernier message: 11/01/2006, 11h34
  3. [MySQL] Flux de sortie : ob_start + header
    Par ToxiZz dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 14/12/2005, 00h56
  4. Awk - changer le flux de sortie
    Par Longrais dans le forum Linux
    Réponses: 1
    Dernier message: 16/08/2005, 18h11
  5. [Console] Tampon de sortie et endl
    Par Évariste Galois dans le forum C++
    Réponses: 18
    Dernier message: 09/07/2005, 18h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo