i have an agent thanks to netsnmp library , its working fine for the Getrequest , I use MibIreasonning to do my test of get and set however I have a big problem for the set , when I do the snmp set i got no Response and the value dosent change , with command line i use :
snmpset -v2c -cprivate 127.0.0.1:10181 1.3.6.1.4.1.4045.61005681.20.2.3.0.0 i 1
and i got : Timeout: No Response from 127.0.0.1:10181
and If i do snmpset in public I got : Error in packet , Reason noAccess
Here is my code if you can please help me :
//-------------------------------------------------------------------------------------------------
// ValueOID
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <iostream>
#include <string>
int handle_AgentSNMP15 (
netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
int value=0 ;
switch (reqinfo->mode) {
case MODE_GET:
std::cout<<"GETSNMP15"<<std::endl;
std::cout<<"get value "<<*(requests->requestvb->val.integer)<<std::endl;
snmp_set_var_typed_value(
requests->requestvb,
ASN_INTEGER,
(u_char*)&value,
sizeof(value));
break;
case MODE_SET_RESERVE1:
std::cout<<*(requests->requestvb->val.integer)<<std::endl;
case MODE_SET_RESERVE2:
value = *(requests->requestvb->val.integer);
std::cout<<"RESERVE2"<<std::endl;
break;
case MODE_SET_FREE:
break;
case MODE_SET_ACTION:
std::cout<<"SETACTION"<<std::endl;
value = *(requests->requestvb->val.integer);
break;
case MODE_SET_COMMIT:
std::cout<<"SETCOMMIT"<<std::endl;
value = *(requests->requestvb->val.integer);
break;
case MODE_SET_UNDO:
break;
default:
{
snmp_log(
LOG_ERR,
"Unknown mode (%d) in handle_dot1dBaseType\n",
reqinfo->mode);
std::cout<<"ERROR OTHER THAN GET";
return SNMP_ERR_GENERR;
}
}
return SNMP_ERR_NOERROR;
}
void init_Value() {
static oid AgentSNMP15[]={1,3,6,1,4,1,4045,61005681,20,2,3,0};
netsnmp_register_scalar(netsnmp_create_handler_registration(
"agentSNMP15",
handle_AgentSNMP15,
AgentSNMP15,
OID_LENGTH(AgentSNMP15),
HANDLER_CAN_RWRITE));
}
Thanks for your help
Related
I am a very new coder, and I'm trying to code a program that when SW1 is pressed on the Tivaware launch board, it lights the red LED and when I press both SW1 and SW2 the Blue LED is on. when I run the code shown below only the Red LED is on and there is no response from the board.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
bool sw1_not_pressed,sw2_not_pressed,sw1_pressed,sw2_pressed;
int main(void){
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN);
while(1)
{
sw1_not_pressed = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4 );
sw2_not_pressed = GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0 );
sw1_pressed = !sw1_not_pressed;
sw2_pressed = !sw2_not_pressed;
if(sw1_pressed)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
}
else
{
if(sw2_pressed && sw1_pressed)
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2,0x00 );
}
}
}
}
I am very grateful for any help given and thank you for responding to my question.
I'm working on lib which uses a lot of file system functions.
What I want is that my function returns various of error codes (not just -1 as error) depending on errno in case file system function fails.
Although I could use errno values directly but I want to create some abstraction layer between my functions error codes and system errno (e.g. my error values begins on -1000 and are negative whereas errno values are positive).
My question what is the best way to implement it.
For now I see two possible solution:
use an enum with error codes and switch case function to translate, e.g.:
typedef enum {
MY_ERROR_EPERM = -1104, /* Operation not permitted */
MY_ERROR_ENOENT = -1105, /* No such file or directory */
// ...
} MyReturnCodes_t;
int ErrnoToErrCode(unsigned int sysErrno) {
int error = ENOSYS;
switch(sysErrno) {
case EPERM: error = MY_ERROR_EPERM; break;
case ENOENT: error = MY_ERROR_ENOENT; break;
// ...
}
return error;
}
use translation directly in enum:
#define ERR_OFFSET -1000
typedef enum {
MY_ERROR_EPERM = ERR_OFFSET - EPERM, /* Operation not permitted */
MY_ERROR_ENOENT = ERR_OFFSET - ENOENT, /* No such file or directory */
MY_ERROR_ESRCH = ERR_OFFSET - ESRCH, /* No such process */
// ...
} MyReturnCodes_t;
Which way is more constant?
One more point: This library should be used both on QNX and Linux OS, what is the proper way to align errno codes (which different in some cases)?
I´d go for a std::map in a dedicated function. You don't have to care about gaps or anything as long as you use the provided error macros:
#include <iostream>
#include <errno.h>
#include <map>
namespace MyError
{
enum MyReturnCode: int
{
MY_INVALID_VAL = 0 , /* Invalid Mapping */
MY_ERROR_EPERM = -1104, /* Operation not permitted */
MY_ERROR_ENOENT = -1105, /* No such file or directory */
};
MyReturnCode fromErrno(int e)
{
static const std::map<int, MyReturnCode> mapping {
{ EPERM, MY_ERROR_EPERM},
{ ENOENT, MY_ERROR_ENOENT}
};
if(mapping.count(e))
return mapping.at(e);
else
return MY_INVALID_VAL;
}
}
int main()
{
std::cout << MyError::fromErrno(ENOENT) << std::endl;
std::cout << MyError::fromErrno(42) << std::endl;
return 0;
}
http://coliru.stacked-crooked.com/a/1da9fd44d88fb097
OS : win10 64 bits
compiler : vc2017 64bits
vlc version : 3.0.9.2 from here
Source codes
#include <vlc/vlc.h>
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
void libvlc_callback(libvlc_event_t const *event, void*)
{
switch (event->type) {
case libvlc_MediaMetaChanged:
std::cout<<__func__<<": libvlc_MediaMetaChanged = "<<event->u.media_meta_changed.meta_type<<std::endl;
break;
case libvlc_MediaSubItemAdded:
std::cout<<__func__<<": libvlc_MediaSubItemAdded = "<<event->u.media_subitem_added.new_child<<std::endl;
break;
case libvlc_MediaDurationChanged:
std::cout<<__func__<<": libvlc_MediaDurationChanged = "
<<event->u.media_duration_changed.new_duration<<std::endl;
break;
case libvlc_MediaParsedChanged:
std::cout<<__func__<<": libvlc_MediaParsedChanged = "<<event->u.media_parsed_changed.new_status<<std::endl;
break;
case libvlc_MediaFreed:
std::cout<<__func__<<": libvlc_MediaFreed = "<<event->u.media_freed.md<<std::endl;
break;
case libvlc_MediaStateChanged:
std::cout<<__func__<<":libvlc_MediaStateChanged = "<<event->u.media_state_changed.new_state<<std::endl;
break;
default:
break;
}
}
std::vector<libvlc_event_e> create_events()
{
return {libvlc_MediaMetaChanged,
libvlc_MediaSubItemAdded,
libvlc_MediaDurationChanged,
libvlc_MediaParsedChanged,
libvlc_MediaFreed,
libvlc_MediaStateChanged};
}
int main()
{
libvlc_instance_t *inst = libvlc_new(0, nullptr);
char const *location = "C:/Users/ssss/audio/audio.mp3";
libvlc_media_t *vlc_media = libvlc_media_new_location(inst, location);
libvlc_event_manager_t *vlc_events = libvlc_media_event_manager(vlc_media);
for(libvlc_event_e const &event : create_events()){
libvlc_event_attach(vlc_events, event, libvlc_callback, nullptr);
}
libvlc_media_add_option(vlc_media, "--sout='#transcode{acodec=s16l, ab=16, channels=1, samplerate=16000}:"
"std{access=file, mux=wav, "
"dst=\"audio.wav\"}'");
std::this_thread::sleep_for(std::chrono::seconds(10));
libvlc_media_release(vlc_media);
libvlc_release(inst);
}
The output I got are
main libvlc debug: VLC media player - 3.0.9.2 Vetinari
main libvlc debug: Copyright © 1996-2020 the VideoLAN team
main libvlc debug: revision 3.0.9.2-0-gd4c1aefe4d
main libvlc debug: configured with ../extras/package/win32/../../../configure '--enable-update-check' '--enable-lua' '--enable-faad' '--enable-flac' '--enable-theora' '--enable-avcodec' '--enable-merge-ffmpeg' '--enable-dca' '--enable-mpc' '--enable-libass' '--enable-schroedinger' '--enable-realrtsp' '--enable-live555' '--enable-dvdread' '--enable-shout' '--enable-goom' '--enable-caca' '--enable-qt' '--enable-skins2' '--enable-sse' '--enable-mmx' '--enable-libcddb' '--enable-zvbi' '--disable-telx' '--enable-nls' '--host=x86_64-w64-mingw32' '--with-breakpad=https://win.crashes.videolan.org' 'host_alias=x86_64-w64-mingw32' 'PKG_CONFIG_LIBDIR=/home/jenkins/workspace/vlc-release/windows/vlc-release-win32-x64/contrib/x86_64-w64-mingw32/lib/pkgconfig'
main libvlc debug: using multimedia timers as clock source
main libvlc debug: min period: 1 ms, max period: 1000000 ms
main libvlc debug: searching plug-in modules
main libvlc debug: loading plugins cache file C:\vlc-3.0.9.2-win64\plugins\plugins.dat
main libvlc warning: cannot read C:\vlc\vlc-3.0.9.2-win64\plugins\plugins.dat: No such file or directory
main libvlc debug: recursively browsing `C:\vlc\vlc-3.0.9.2-win64\plugins'
main libvlc debug: plug-ins loaded: 494 modules
main logger debug: looking for logger module matching "any": 2 candidates
main logger debug: using logger module "console"
main libvlc debug: translation test: code is "C"
main keystore debug: looking for keystore module matching "memory": 3 candidates
main keystore debug: using keystore module "memory"
main libvlc debug: CPU has capabilities MMX MMXEXT SSE SSE2 SSE3 SSSE3 SSE4.1 SSE4.2 FPU
libvlc_callback: libvlc_MediaFreed = 000001DBD602CC50
main libvlc debug: exiting
main libvlc debug: no exit handler
main libvlc debug: removing all interfaces
main keystore debug: removing module "memory"
I cannot see any audio.wav generated in the folder, which step I missed or done it wrong? Thanks
Edit: pass parameters into libvlc_new
const char * const vlc_args[] = {
"--sout",
"#transcode{acodec=s16l,channels=2,samplerate=44100}:std{access=file,mux=wav,dst=\"C:/my_path/clip_0002.wav\"}",
"C:/my_path/audio.wav"};
libvlc_instance_t *inst = libvlc_new(3, vlc_args);
std::this_thread::sleep_for(std::chrono::seconds(60));
libvlc_release(inst);
It give me output message
main libvlc debug: exiting
main libvlc debug: no exit handler
main libvlc debug: removing all interfaces
main keystore debug: removing module "memory"
Don't know why the output file 'audio.wav' never generated in the folder
Found a solution, you need to play the media and open the file correctly, for simplicity I use "libvlc_media_new_path" in this example, if you are using "libvlc_media_new_location", remember to append "file:///" before the location and change to native separator.
#include "core/vlc_error.hpp"
#include <vlc/vlc.h>
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#include <QString>
void libvlc_callback(libvlc_event_t const *event, void*)
{
switch (event->type) {
case libvlc_MediaMetaChanged:
std::cout<<__func__<<": libvlc_MediaMetaChanged = "<<event->u.media_meta_changed.meta_type<<std::endl;
break;
case libvlc_MediaSubItemAdded:
std::cout<<__func__<<": libvlc_MediaSubItemAdded = "<<event->u.media_subitem_added.new_child<<std::endl;
break;
case libvlc_MediaDurationChanged:
std::cout<<__func__<<": libvlc_MediaDurationChanged = "
<<event->u.media_duration_changed.new_duration<<std::endl;
break;
case libvlc_MediaParsedChanged:
std::cout<<__func__<<": libvlc_MediaParsedChanged = "<<event->u.media_parsed_changed.new_status<<std::endl;
break;
case libvlc_MediaFreed:
std::cout<<__func__<<": libvlc_MediaFreed = "<<event->u.media_freed.md<<std::endl;
break;
case libvlc_MediaStateChanged:
std::cout<<__func__<<":libvlc_MediaStateChanged = "<<event->u.media_state_changed.new_state<<std::endl;
break;
default:
break;
}
}
std::vector<libvlc_event_e> create_events()
{
return {libvlc_MediaMetaChanged,
libvlc_MediaSubItemAdded,
libvlc_MediaDurationChanged,
libvlc_MediaParsedChanged,
libvlc_MediaListEndReached,
libvlc_MediaFreed,
libvlc_MediaStateChanged};
}
int main()
{
libvlc_instance_t *inst = libvlc_new(0, nullptr);
char const *location = "clip_0002.wav";
libvlc_media_t *vlc_media = libvlc_media_new_path(inst, location);
libvlc_event_manager_t *vlc_events = libvlc_media_event_manager(vlc_media);
for(libvlc_event_e const &event : create_events()){
libvlc_event_attach(vlc_events, event, libvlc_callback, nullptr);
}
QString const cmd("transcode{acodec=s16l, ab=16, channels=1, samplerate=16000}:"
"std{access=file, mux=wav, "
"dst='audio.wav'}");
QString config = ":sout=#duplicate{dst=display,dst=\"%1\"}";
config = config.arg(cmd);
std::cout<<"-------------------------"<<std::endl;
std::cout<<config.toStdString()<<std::endl;
libvlc_media_add_option(vlc_media, ":sout-all");
qt_vlc::vlc_error::show_err_msg();
libvlc_media_add_option(vlc_media, config.toUtf8().data());
qt_vlc::vlc_error::show_err_msg();
libvlc_media_player_t *vlc_player = libvlc_media_player_new_from_media(vlc_media);
libvlc_audio_set_mute(vlc_player, true);
libvlc_media_player_play(vlc_player);
while(1){
qt_vlc::vlc_error::show_err_msg();
if(libvlc_media_get_state(vlc_media) == libvlc_Ended){
break;
}
std::cout<<"media state = "<<libvlc_media_get_state(vlc_media)<<std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
libvlc_media_player_release(vlc_player);
libvlc_media_release(vlc_media);
libvlc_release(inst);
}
You can convert video to audio by this solution too, problem is it will show the video when converting, finding a way to hide the video.
I am trying to build a fast DNS resolver in c++ with static libraries (work everywhere). So far so good my version uses gethostbyname and on some servers it doesn't work i get A non-recoverable name server error occurred (NO_RECOVERY). Also when compiling we are getting this warning :
Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
#include <stdio.h>
#include <cstring>
// for dom
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
char* host = "google.com";
int debugLevel = 5;
char* ip_of_domain;
struct hostent *he;
he = gethostbyname(host);
if (he == NULL)
{
switch(h_errno)
{
case HOST_NOT_FOUND:
if(debugLevel >= 3) puts("The host was not found.");
break;
case NO_ADDRESS:
if(debugLevel >= 3) puts("The name is valid but it has no address.");
break;
case NO_RECOVERY:
if(debugLevel >= 3) puts("A non-recoverable name server error occurred.");
break;
case TRY_AGAIN:
if(debugLevel >= 3) puts("The name server is temporarily unavailable.");
break;
}
}
else
{
ip_of_domain = strdup(inet_ntoa(*((struct in_addr *) he->h_addr_list[0])));
}
if(debugLevel >= 4) printf("IP=%s\n",ip_of_domain);
}
The program has to be compatible every where, 32 and 64 bits.
Any solution?
Thanks.
Use c-ares library, here: https://c-ares.haxx.se/. This is a true OS-independent resolver.
I am currently coding in Visual Studio 2010, using C++ and the Irrlicht game engine. I have tried asking this question on their forum, however I haven't had any response.
I am using the tutorials on the Irrlicht website:
http://irrlicht.sourceforge.net/docu/example002.html
The error I am getting is: "unresolved external symbol _imp_createDevice referenced in function _main"
I have added linked the Irrlicht library and include files already, but I am still getting this error.
// Tutorial2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <irrlicht.h>
#include <iostream>
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) OpenGL 1.5\n (b) Direct3D 9.0c\n (c) Direct3D 8.1\n"\
" (d) Burning's Software Renderer\n (e) Software Renderer\n"\
" (f) NullDevice\n (otherKey) exit\n\n");
char i;
std::cin >> i;
switch(i)
{
case 'a':driverType = video::EDT_OPENGL; break;
case 'b':driverType = video::EDT_DIRECT3D9; break;
case 'c':driverType = video::EDT_DIRECT3D8; break;
case 'd':driverType = video::EDT_BURNINGSVIDEO; break;
case 'e':driverType = video::EDT_SOFTWARE; break;
case 'f':driverType = video::EDT_NULL; break;
default: return 1;
}
// create device and exit if creation failed
IrrlichtDevice *device =
createDevice(driverType, core::dimension2d<u32>(640, 480));
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
device->getFileSystem()->addFileArchive("../../media/map-20kdm2.pk3");
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0;
if (mesh)
node = smgr->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
// node = smgr->addmeshSceneNode(mesh->getMesh(0));
if (node)
node->setPosition(core::vector3df(-1300,-144,-1249));
smgr->addCameraSceneNodeFPS();
device->getCursorControl()->setVisible(false);
int lastFPS = -1;
while(device->run())
{
if(device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255, 200, 200, 200));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Quake 3 Map example[";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
else
device->yield();
}
device->drop();
return 0;
}
I've managed to build the sample, no problem.
The only way to get your error is to mix the 32 and 64bit lib files.
Rename the 64bit library Irrlicht_x64.lib and try building again.