mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-02-03 23:35:04 +01:00
Merge pull request #4387 from SparkiDev/popen_host
Get host name: add code to use popen and the command 'host'
This commit is contained in:
25
src/ssl.c
25
src/ssl.c
@@ -34388,8 +34388,8 @@ int wolfSSL_CMAC_Init(WOLFSSL_CMAC_CTX* ctx, const void *key, size_t keyLen,
|
||||
}
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ret = wc_InitCmac((Cmac*)ctx->internal, (const byte*)key, (word32)keyLen,
|
||||
WC_CMAC_AES, NULL);
|
||||
ret = wc_InitCmac((Cmac*)ctx->internal, (const byte*)key,
|
||||
(word32)keyLen, WC_CMAC_AES, NULL);
|
||||
if (ret != 0) {
|
||||
ret = WOLFSSL_FAILURE;
|
||||
}
|
||||
@@ -34419,7 +34419,8 @@ int wolfSSL_CMAC_Update(WOLFSSL_CMAC_CTX* ctx, const void* data, size_t len)
|
||||
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
if (data) {
|
||||
ret = wc_CmacUpdate((Cmac*)ctx->internal, (const byte*)data, (word32)len);
|
||||
ret = wc_CmacUpdate((Cmac*)ctx->internal, (const byte*)data,
|
||||
(word32)len);
|
||||
if (ret != 0){
|
||||
ret = WOLFSSL_FAILURE;
|
||||
}
|
||||
@@ -34442,7 +34443,8 @@ int wolfSSL_CMAC_Final(WOLFSSL_CMAC_CTX* ctx, unsigned char* out,
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_CMAC_Final");
|
||||
|
||||
if (ctx == NULL || ctx->cctx == NULL || ctx->internal == NULL || len == NULL) {
|
||||
if (ctx == NULL || ctx->cctx == NULL || ctx->internal == NULL ||
|
||||
len == NULL) {
|
||||
ret = WOLFSSL_FAILURE;
|
||||
}
|
||||
|
||||
@@ -34456,7 +34458,10 @@ int wolfSSL_CMAC_Final(WOLFSSL_CMAC_CTX* ctx, unsigned char* out,
|
||||
}
|
||||
}
|
||||
if (ret == WOLFSSL_SUCCESS) {
|
||||
ret = wc_CmacFinal((Cmac*)ctx->internal, out, (word32*)len);
|
||||
word32 len32 = (word32)*len;
|
||||
|
||||
ret = wc_CmacFinal((Cmac*)ctx->internal, out, &len32);
|
||||
*len = (size_t)len32;
|
||||
if (ret != 0) {
|
||||
ret = WOLFSSL_FAILURE;
|
||||
}
|
||||
@@ -34489,7 +34494,8 @@ void *wolfSSL_OPENSSL_malloc(size_t a)
|
||||
|
||||
int wolfSSL_OPENSSL_hexchar2int(unsigned char c)
|
||||
{
|
||||
return (int)HexCharToByte((char)c);
|
||||
/* 'char' is unsigned on some platforms. */
|
||||
return (int)(signed char)HexCharToByte((char)c);
|
||||
}
|
||||
|
||||
unsigned char *wolfSSL_OPENSSL_hexstr2buf(const char *str, long *len)
|
||||
@@ -57076,7 +57082,7 @@ void *wolfSSL_BIO_get_ex_data(WOLFSSL_BIO *bio, int idx)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(NO_FILESYSTEM) && defined (OPENSSL_EXTRA)
|
||||
#ifdef OPENSSL_EXTRA
|
||||
/* returns amount printed on success, negative in fail case */
|
||||
int wolfSSL_BIO_vprintf(WOLFSSL_BIO* bio, const char* format, va_list args)
|
||||
{
|
||||
@@ -57086,6 +57092,7 @@ int wolfSSL_BIO_vprintf(WOLFSSL_BIO* bio, const char* format, va_list args)
|
||||
return WOLFSSL_FATAL_ERROR;
|
||||
|
||||
switch (bio->type) {
|
||||
#if !defined(NO_FILESYSTEM)
|
||||
case WOLFSSL_BIO_FILE:
|
||||
if (bio->ptr == NULL) {
|
||||
va_end(args);
|
||||
@@ -57093,6 +57100,7 @@ int wolfSSL_BIO_vprintf(WOLFSSL_BIO* bio, const char* format, va_list args)
|
||||
}
|
||||
ret = XVFPRINTF((XFILE)bio->ptr, format, args);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case WOLFSSL_BIO_MEMORY:
|
||||
/* In Visual Studio versions prior to Visual Studio 2013, the va_* symbols
|
||||
@@ -57152,8 +57160,7 @@ int wolfSSL_BIO_printf(WOLFSSL_BIO* bio, const char* format, ...)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !NO_FILESYSTEM && OPENSSL_EXTRA */
|
||||
#endif /* OPENSSL_EXTRA */
|
||||
|
||||
#if !defined(NO_FILESYSTEM) && defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
64
src/wolfio.c
64
src/wolfio.c
@@ -765,7 +765,9 @@ int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, word16 port, int to_sec)
|
||||
ADDRINFO* answer = NULL;
|
||||
char strPort[6];
|
||||
#else
|
||||
#if !defined(WOLFSSL_USE_POPEN_HOST)
|
||||
HOSTENT* entry;
|
||||
#endif
|
||||
SOCKADDR_IN *sin;
|
||||
#endif
|
||||
|
||||
@@ -799,6 +801,68 @@ int wolfIO_TcpConnect(SOCKET_T* sockfd, const char* ip, word16 port, int to_sec)
|
||||
sockaddr_len = answer->ai_addrlen;
|
||||
XMEMCPY(&addr, answer->ai_addr, sockaddr_len);
|
||||
freeaddrinfo(answer);
|
||||
#elif defined(WOLFSSL_USE_POPEN_HOST)
|
||||
{
|
||||
char host_ipaddr[4] = { 127, 0, 0, 1 };
|
||||
int found = 1;
|
||||
|
||||
if ((XSTRNCMP(ip, "localhost", 10) != 0) &&
|
||||
(XSTRNCMP(ip, "127.0.0.1", 10) != 0)) {
|
||||
FILE* fp;
|
||||
char host_out[100];
|
||||
char cmd[100];
|
||||
|
||||
XSTRNCPY(cmd, "host ", 6);
|
||||
XSTRNCAT(cmd, ip, 99 - XSTRLEN(cmd));
|
||||
found = 0;
|
||||
fp = popen(cmd, "r");
|
||||
if (fp != NULL) {
|
||||
while (fgets(host_out, sizeof(host_out), fp) != NULL) {
|
||||
int i;
|
||||
int j = 0;
|
||||
for (j = 0; host_out[j] != '\0'; j++) {
|
||||
if ((host_out[j] >= '0') && (host_out[j] <= '9')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
found = (host_out[j] >= '0') && (host_out[j] <= '9');
|
||||
if (!found) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
host_ipaddr[i] = atoi(host_out + j);
|
||||
while ((host_out[j] >= '0') && (host_out[j] <= '9')) {
|
||||
j++;
|
||||
}
|
||||
if (host_out[j] == '.') {
|
||||
j++;
|
||||
found &= (i != 3);
|
||||
}
|
||||
else {
|
||||
found &= (i == 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
pclose(fp);
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
sin = (SOCKADDR_IN *)&addr;
|
||||
|
||||
sin->sin_family = AF_INET;
|
||||
sin->sin_port = XHTONS(port);
|
||||
XMEMCPY(&sin->sin_addr.s_addr, host_ipaddr, sizeof(host_ipaddr));
|
||||
}
|
||||
else {
|
||||
WOLFSSL_MSG("no addr info for responder");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
entry = gethostbyname(ip);
|
||||
sin = (SOCKADDR_IN *)&addr;
|
||||
|
||||
Reference in New Issue
Block a user