diff --git a/include/freerdp/errorcodes.h b/include/freerdp/errorcodes.h new file mode 100644 index 000000000..d330858fc --- /dev/null +++ b/include/freerdp/errorcodes.h @@ -0,0 +1,39 @@ +/* + * File: errorcodes.h + * Author: Arvid + * + * Created on April 13, 2012, 9:09 AM + */ + +#ifndef ERRORCODES_H +#define ERRORCODES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* This static variable holds an error code if the return value from connect is false. +* This variable is always set to 0 in the beginning of the connect sequence. +* The returned code can be used to inform the user of the detailed connect error. +* The value can hold one of the defined error codes below OR an error according to errno +*/ +extern int connectErrorCode ; +#define ERRORSTART 10000 +#define PREECONNECTERROR ERRORSTART + 1 +#define UNDEFINEDCONNECTERROR ERRORSTART + 2 +#define POSTCONNECTERROR ERRORSTART + 3 +#define DNSERROR ERRORSTART + 4 /* general DNS ERROR */ +#define DNSNAMENOTFOUND ERRORSTART + 5 /* EAI_NONAME */ +#define CONNECTERROR ERRORSTART + 6 /* a connect error if errno is not define during tcp connect */ +#define MCSCONNECTINITIALERROR ERRORSTART + 7 +#define TLSCONNECTERROR ERRORSTART + 8 +#define AUTHENTICATIONERROR ERRORSTART + 9 + + +#ifdef __cplusplus +} +#endif + +#endif /* ERRORCODES_H */ + diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index e00e1bd15..e6830855a 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -39,6 +39,7 @@ typedef struct rdp_freerdp_peer freerdp_peer; #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/libfreerdp-core/connection.c b/libfreerdp-core/connection.c index 98ab48e08..1daeb0508 100644 --- a/libfreerdp-core/connection.c +++ b/libfreerdp-core/connection.c @@ -107,6 +107,9 @@ boolean rdp_client_connect(rdpRdp* rdp) if (mcs_send_connect_initial(rdp->mcs) != true) { + if(!connectErrorCode){ + connectErrorCode = MCSCONNECTINITIALERROR; + } printf("Error: unable to send MCS Connect Initial\n"); return false; } diff --git a/libfreerdp-core/freerdp.c b/libfreerdp-core/freerdp.c index e5364d7a2..e059492d8 100644 --- a/libfreerdp-core/freerdp.c +++ b/libfreerdp-core/freerdp.c @@ -28,6 +28,8 @@ #include #include +/* connectErrorCode is 'extern' in errorcodes.h. See comment there.*/ + /** Creates a new connection based on the settings found in the "instance" parameter * It will use the callbacks registered on the structure to process the pre/post connect operations * that the caller requires. @@ -43,6 +45,8 @@ boolean freerdp_connect(freerdp* instance) { rdpRdp* rdp; boolean status = false; + /* We always set the return code to 0 before we start the connect sequence*/ + connectErrorCode = 0 ; rdp = instance->context->rdp; @@ -52,6 +56,9 @@ boolean freerdp_connect(freerdp* instance) if (status != true) { + if(!connectErrorCode){ + connectErrorCode = PREECONNECTERROR; + } printf("freerdp_pre_connect failed\n"); return false; } @@ -74,6 +81,9 @@ boolean freerdp_connect(freerdp* instance) if (status != true) { printf("freerdp_post_connect failed\n"); + if(!connectErrorCode){ + connectErrorCode = POSTCONNECTERROR; + } return false; } @@ -109,7 +119,9 @@ boolean freerdp_connect(freerdp* instance) return true; } } - + if(!connectErrorCode){ + connectErrorCode = UNDEFINEDCONNECTERROR; + } return status; } diff --git a/libfreerdp-core/transport.c b/libfreerdp-core/transport.c index 46c21652d..dbc3fcbd1 100644 --- a/libfreerdp-core/transport.c +++ b/libfreerdp-core/transport.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -88,6 +89,9 @@ boolean transport_connect_tls(rdpTransport* transport) transport->tls->sockfd = transport->tcp->sockfd; if (tls_connect(transport->tls) != true) { + if(!connectErrorCode){ + connectErrorCode = TLSCONNECTERROR; + } tls_free(transport->tls); transport->tls = NULL; return false; @@ -108,6 +112,9 @@ boolean transport_connect_nla(rdpTransport* transport) transport->tls->sockfd = transport->tcp->sockfd; if (tls_connect(transport->tls) != true) { + if(!connectErrorCode){ + connectErrorCode = TLSCONNECTERROR; + } tls_free(transport->tls); transport->tls = NULL; return false; @@ -126,6 +133,9 @@ boolean transport_connect_nla(rdpTransport* transport) if (credssp_authenticate(transport->credssp) < 0) { + if(!connectErrorCode){ + connectErrorCode = AUTHENTICATIONERROR; + } printf("Authentication failure, check credentials.\n" "If credentials are valid, the NTLMSSP implementation may be to blame.\n"); diff --git a/libfreerdp-utils/tcp.c b/libfreerdp-utils/tcp.c index 81ece04d7..b986788ab 100644 --- a/libfreerdp-utils/tcp.c +++ b/libfreerdp-utils/tcp.c @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -55,6 +56,9 @@ #endif +/* connectErrorCode is 'extern' in errorcodes.h. See comment there.*/ +int connectErrorCode ; + int freerdp_tcp_connect(const char* hostname, int port) { int status; @@ -73,6 +77,14 @@ int freerdp_tcp_connect(const char* hostname, int port) if (status != 0) { + if(status==EAI_NONAME){ + if(!connectErrorCode){ + connectErrorCode = DNSNAMENOTFOUND; + } + } + if(!connectErrorCode){ + connectErrorCode = DNSERROR; + } printf("tcp_connect: getaddrinfo (%s)\n", gai_strerror(status)); return -1; } @@ -90,7 +102,14 @@ int freerdp_tcp_connect(const char* hostname, int port) printf("connected to %s:%s\n", hostname, servname); break; } - + if(!connectErrorCode){ + int tmperror = errno ; + if(tmperror!=0){ + connectErrorCode = tmperror ; + }else{ + connectErrorCode = CONNECTERROR; + } + } close(sockfd); sockfd = -1; }