getaddrinfo returns always 11001 (host not found) - c++

Although the searched FQDN appears in etc\hosts file.
Any idea?
Thanks a lot!

Since I don't have code, here's a guess:
getaddrinfo("http://www.example.com");
Doesn't work; getaddrinfo takes a hostname not a URL.

Related

SetSslClientCertPfx does not allow change of file location

I am using chilkat active x to access a webservice secured with x509.
SetSslClientCertPfx("pfxfilewithpath","password")
It works fine with the pfx file in the location I used it first.
If I copy it to another path it does not work anymore (error 109) , even after pc reboot or renaming.
Any chance to get this to work ?
Thanks in advance
tom
Using locert.LoadByCommonName("certname") and SetSslClientCert(locert) works but I would prefer to use SetSslClientCertPfx()
Examine the contents of the httpObject.LastErrorText property after calling httpObject.SetSslClientCertPfx (assuming this is for HTTP).

SSL_connect() fails

I'm having some troubles with openssl-1.0.1c in c++, more precisely
SSL_connect() is failing with no reason, and returns -1.
SSL_get_error() returns SSL_SYSCALL_ERROR.
ERR_get_error() returns 0.
WSAGetLastError() returns WSAEINPROGRESS.
I'm stuck in this, and i have ran out of ideas.
Is there anybody who can give me some advice on how to debug this?
Any suggestion is appreciated,
Thanks in advance.
This is what i get on the server side
This is what whireshark shows

Regex.Replace for IP address

I've lifted a piece of code from somewhere on the internet it looks like this
ip = Regex.Replace(ip, #"^(?<Prefix>(\d{1,3}\.){3})\d{1,3}$", "${Prefix}*");
What it does is takes an IP address and replaces the last section with a asterisk. For example 192.168.0.1 would become 192.168.0.*
I'm useless with RegEx, I've tried to understand what the above is actually doing, but not having any success.
What I'm after is 2 more Regex.Replace code so that 192.168.0.1 becomes
192.168.*.*
192.*.*.*
Can anyone help me?
192.168.*.* = ip = Regex.Replace(ip, #"^(?<Prefix>(\d{1,3}\.){2})\d{1,3}\.\d{1,3}$", "${Prefix}*.*");
192.*.*.* = ip = Regex.Replace(ip, #"^(?<Prefix>(\d{1,3}\.))\d{1,3}\.\d{1,3}\.\d{1,3}$", "${Prefix}*.*.*");
Give that a shot, see what happens.

Openssl need to use CA bundle file (Intermediate cert)

I just purchased a SSL certificate from Go Daddy.
Great price, but it seems that it has a draw back.
It seems to need the bundle.crt in order to work correctly on must browser.
I'm not yet really sure what it is, from what I have understand it is an intermediate certificate from Certificate Authority. Correct me if I'm wrong
So in my software I have openssl
SSL_CTX_set_default_passwd_cb(SSL_ctx, pem_passwd_cb);
SSL_CTX_use_PrivateKey_file(SSL_ctx, _private_key, SSL_FILETYPE_PEM);
SSL_CTX_use_certificate_file(SSL_ctx, _certificate, SSL_FILETYPE_PEM);
SSL_CTX_use_certificate_chain_file(SSL_ctx, "./ssl_key/bundle.pem");
SSL_CTX_set_session_cache_mode(SSL_ctx,SSL_SESS_CACHE_SERVER|SSL_SESS_CACHE_NO_INTERNAL);
SSL_CTX_set_quiet_shutdown(SSL_ctx, 1);
The error I get is :
You didn't run init properly or an error occured.
With lasts certs (geotrust) I didn't need the bundle intermediate, I'm really lost here.
Since SSL_CTX_use_certificate_chain_file accepts only PEM files, I have converted the bundle.crt file to PEM using openssl.
Any idea ?
Thanks!
EDIT 1 :
Apparently Intermediate certificate must be on the /etc/ssl/certs folder.
I have putted every intermediate certificate from go-daddy on this folder, and still no luck...
I have removed the line
SSL_CTX_use_certificate_chain_file(SSL_ctx, "./ssl_key/bundle.pem");
Which seems to be no use for me here...
Okay, after testing one million things I finally found out.
I didn't convert the bundle.crt into PEM.
I have pasted the certificate file directly in the bundle.crt (at the beginning of the file)
I have removed this line on my code :
SSL_CTX_use_certificate_file(SSL_ctx, _certificate, SSL_FILETYPE_PEM);
So here's the final code for SSL init :
SSL_CTX_set_default_passwd_cb(SSL_ctx, pem_passwd_cb);
SSL_CTX_use_PrivateKey_file(SSL_ctx, _private_key, SSL_FILETYPE_PEM);
SSL_CTX_use_certificate_chain_file(SSL_ctx, "./ssl_key/bundle.crt");
SSL_CTX_set_session_cache_mode(SSL_ctx,SSL_SESS_CACHE_SERVER|SSL_SESS_CACHE_NO_INTERNAL);
SSL_CTX_set_quiet_shutdown(SSL_ctx, 1);
Hope this helps someone, and save them a lot of time (1 full day for me ;-))

Pinging from a C/C++ program

I want to write a C or C++ program, that given an IP address, Pings it and then performs further action based on whether the Ping was successful or not.
How to do this?
Have a blast at The Ping Page, which has a link to full source on the original Unix ping(8).
EDIT I saw after I posted, you are on Ubuntu. However someone searching this question may still find these links helpful for Windows.
Ping: Raw Sockets Method: http://tangentsoft.net/wskfaq/examples/rawping.html
Implementing Internet Pings Using Icmp.dll: http://support.microsoft.com/default.aspx?scid=kb;en-us;170591
IcmpSendEcho Function: http://msdn.microsoft.com/en-us/library/aa366050%28VS.85%29.aspx
Ping for Windows: http://www.codeproject.com/KB/IP/winping.aspx
This post is old but I think the following link will help future people lookign for a good explanation on how to create a Ping request.
Deconstructing Ping with C and NodeJS
#include <iostream>
using namespace std;
int main() {
int x = system("ping -c1 -s1 8.8.8.8 > /dev/null 2>&1");
if (x==0){
cout<<"success";
}else{
cout<<"failed";
}
replace 8.8.8.8 from your IP Address