Can not access data from given OIDs using net-snmp - c++

i implemented the simple net-snmp simple application into my project. when i tried to use the example OID given at the site: .1.3.6.1.2.1.1.1.0 it worked just fine.
now i need to get data from these oids: https://www.sysadmin.md/snmp-most-useful-linux-oids.html. when i tried to implement these oids into my code i got error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV).
the simple application code:
add_mibdir(".");
pdu = snmp_pdu_create(SNMP_MSG_GET);//creating a get pdu
if(read_objid(".1.3.6.1.4.1.2021.11.9", id_oid, &id_len)==1)//specifying the oid we want to receive
cout<<"oid read"<<endl;
else
cout<<"couldnt read oid"<<endl;
snmp_add_null_var(pdu, id_oid, id_len);//making room for the response
status = snmp_synch_response(session_handle, pdu, &response);//getting the response
cout<<"status: "<<status<<endl;
string ReturnBuffer;
cout<<"vars: "<<vars->val.string<<endl;
for(vars = response->variables; vars; vars = vars->next_variable)//printing the values we got back
{
cout<<vars->val.string<<endl;
ReturnBuffer.append(reinterpret_cast<char*>(vars->val.string));
}
ReturnBuffer.append("\0"); //test
return ReturnBuffer;
according to the code the oid itself is read and the status of the response is 0 and yet im not getting any of the data and got the error above, i'd appreciate any help thanks in advance.
language: c++
os: linux(ubuntu)

Related

easywsclient websocket connection issues

I am using https://github.com/dhbaird/easywsclient
The following code wont connect properly, ws comes back as a NULL always and the connection "stucks".
using easywsclient::WebSocket;
ws = WebSocket::from_url("ws://mysite.net:80/app/");
assert(ws);
I tried debuggin it and at easywsclient.cpp (github link above) line 514 (code below) gives really weird values for "status" and this is where it fails it seems. I can't figure out why this is happening, the webapp works fine in my browser
if (sscanf(line, "HTTP/1.1 %d", &status) != 1 || status != 101) { fprintf(stderr, "ERROR: Got bad status connecting to %s: %s and status is %d", url.c_str(), line, status); return NULL; }
This is somewhat new terrority to me so I clearly am not understanding something. Any help is appreciated, thanks!

Error writing to table using IBPP

I have some problem writing to a firebird database using IBPP. I can make queries from tables without problems using the SELECT statement, but whenever I try to write values using IBPP::Set or IBPP::Execute, I get an error.
This is how I connect to my database:
db = IBPP::DatabaseFactory(settings.ServerName, settings.DbName, settings.UserName, settings.Password,
"WIN1252", "PAGE_SIZE 8192 DEFAULT CHARACTER SET WIN1252");
db->Connect();
IBPP::Transaction tr = IBPP::TransactionFactory(db);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
Then I wanted to set a specific value:
st->Execute("UPDATE T_GEOMODELL SET Distance= 42.0 WHERE (OBJEKT_ID = 1756056);");
I also tried
st->Prepare("SELECT * FROM T_GEOMODELL WHERE OBJEKT_ID = 1756056");
st->Set(6, "41");
st->Execute();
Here I get the error that "this->mOutRow" is "nullptr".
With the Firebird ISQL tool however, the same command
UPDATE T_GEOMODELL SET Distance= 42.0 WHERE (OBJEKT_ID = 1756056);
works without problems.
I am using Visual C++ 2015 under x64.
Thanks in advance for any help!
Okay, I found the error - I had to start and commit the transaction using tr->Start(); and tr->Commit();
tr->Start();
st->Execute("UPDATE T_GEOMODELL SET Distance= 42.0 WHERE (OBJEKT_ID = 1756056);");
tr->Commit();

Failed to connect to OpenTok(certificate verified failed)

I created a video chat, used Opentok like this:
in video_session_controller.rb file.
require 'opentok'
def show
#video_session = VideoSession.find_by(id: params[:id])
opentok = OpenTok::OpenTok.new ENV['OPENTOK_API_KEY'], ENV['OPENTOK_SECRET']
session = opentok.create_session :media_mode => :routed
#token = session.generate_token
#video_session.create_opentok_session(session_id: session.session_id, token: #token)
end
It is working on live site, but it is not working on local machine.
In local, it shows following error.
OpenTok::OpenTokError: Failed to connect to OpenTok. Response code:
SSL_connect returned=1 errno=0 state=error: certificate verify failed
How can I fix it?
Thanks.

Receiving data from arduino and HC-05 module using pyserial or pybluez

I'm having trouble receiving data from arduino and the bluetooth module HC-05. I tried to receive data with PySerial and Pybluez, but none have worked for me. I appreciate if someone could review what I'm doing wrong.
I found this in StackOverflow, but it did not work.
Bluetooth communication between Arduino and PyBluez
This is my arduino code:
#include <SoftwareSerial.h>
#define RxD 10
#define TxD 11
SoftwareSerial BTSerial(RxD, TxD);
void setup()
{
BTSerial.flush();
delay(500);
BTSerial.begin(9600);
BTSerial.println("The controller has successfuly connected to the PC");
Serial.begin(9600);
delay(100);
}
void loop()
{
BTSerial.write("{Dato1: 545}");
}
This's how I tested it with pyserial:
import serial
device_handler = serial.Serial('COM6', 9600, timeout=1)
count = 0
while (count < 5):
print device_handler.readline()
count += 1
device_handler.close()
And this's how I tried with pybluez, as explained in this link:
https://people.csail.mit.edu/albert/bluez-intro/x232.html
import bluetooth
import sys
bd_addr = "20:15:03:19:27:02"
port = 1
sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((bd_addr, port))
print 'Connected'
sock.settimeout(1.0)
count = 0;
while (count < 10):
data = sock.recv(12)
print 'received: %s'%data
count += 1
sock.close()
None of the two forms worked for me. Pyserial doesn't throw an error and performs the five readings. Apparently it is getting nothing. On the other hand, pybluez throws this exception:
IOError: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Thaks for your help and sorry for my English so bad.
In you PyBluez code you have this line of code
sock.settimeout(1.0)
This is the line that is causing your error because the Arduino is not responding to your Bluetooth connection within that 1 (second?) time period. To fix this either remove that line of code or math the timeout longer.

APNS issue with django

I'm using the following project for enabling APNS in my project:
https://github.com/stephenmuss/django-ios-notifications
I'm able to send and receive push notifications on my production app fine, but the sandbox apns is having strange issues which i'm not able to solve. It's constantly not connecting to the push service. When I do manually the _connect() on the APNService or FeedbackService classes, I get the following error:
File "/Users/MyUser/git/prod/django/ios_notifications/models.py", line 56, in _connect
self.connection.do_handshake()
Error: [('SSL routines', 'SSL3_READ_BYTES', 'sslv3 alert handshake failure')]
I tried recreating the APN certificate a number of times and constantly get the same error. Is there anything else i'm missing?
I'm using the endpoints gateway.push.apple.com and gateway.sandbox.push.apple.com for connecting to the service. Is there anything else I should look into for this? I have read the following:
Apns php error "Failed to connect to APNS: 110 Connection timed out."
Converting PKCS#12 certificate into PEM using OpenSSL
Error Using PHP for iPhone APNS
Turns out Apple changed ssl context from SSL3 to TLSv1 in development. They will do this in Production eventually (not sure when). The following link shows my pull request which was accepted into the above project:
https://github.com/stephenmuss/django-ios-notifications/commit/879d589c032b935ab2921b099fd3286440bc174e
Basically, use OpenSSL.SSL.TLSv1_METHOD if you're using python or something similar in other languages.
Although OpenSSL.SSL.SSLv3_METHOD works in production, it may not work in the near future. OpenSSL.SSL.TLSv1_METHOD works in production and development.
UPDATE
Apple will remove SSL 3.0 support in production on October 29th, 2014 due to the poodle flaw.
https://developer.apple.com/news/?id=10222014a
I have worked on APN using python-django, for this you need three things URL, PORT and Certificate provided by Apple for authentication.
views.py
import socket, ssl, json, struct
theCertfile = '/tmp/abc.cert' ## absolute path where certificate file is placed.
ios_url = 'gateway.push.apple.com'
ios_port = 2195
deviceToken = '3234t54tgwg34g' ## ios device token to which you want to send notification
def ios_push(msg, theCertfile, ios_url, ios_port, deviceToken):
thePayLoad = {
'aps': {
'alert':msg,
'sound':'default',
'badge':0,
},
}
theHost = ( ios_url, ios_port )
data = json.dumps( thePayLoad )
deviceToken = deviceToken.replace(' ','')
byteToken = deviceToken.decode('hex') # Python 2
theFormat = '!BH32sH%ds' % len(data)
theNotification = struct.pack( theFormat, 0, 32, byteToken, len(data), data )
# Create our connection using the certfile saved locally
ssl_sock = ssl.wrap_socket( socket.socket( socket.AF_INET, socket.SOCK_STREAM ), certfile = theCertfile )
ssl_sock.connect( theHost )
# Write out our data
ssl_sock.write( theNotification )
# Close the connection -- apple would prefer that we keep
# a connection open and push data as needed.
ssl_sock.close()
Hopefully this would work for you.