|
@@ -9,6 +9,7 @@
|
|
|
|
|
|
|
|
#include "config.h"
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
+#include <assert.h>
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
@@ -186,13 +187,15 @@ void display(char *buf)
|
|
|
|
|
|
|
|
int callapi(char *command, char *host, short int port)
|
|
int callapi(char *command, char *host, short int port)
|
|
|
{
|
|
{
|
|
|
- char buf[RECVSIZE+1];
|
|
|
|
|
|
|
+ size_t bufsz = RECVSIZE;
|
|
|
|
|
+ char *buf = malloc(bufsz+1);
|
|
|
struct hostent *ip;
|
|
struct hostent *ip;
|
|
|
struct sockaddr_in serv;
|
|
struct sockaddr_in serv;
|
|
|
SOCKETTYPE sock;
|
|
SOCKETTYPE sock;
|
|
|
int ret = 0;
|
|
int ret = 0;
|
|
|
int n, p;
|
|
int n, p;
|
|
|
|
|
|
|
|
|
|
+ assert(buf);
|
|
|
SOCKETINIT;
|
|
SOCKETINIT;
|
|
|
|
|
|
|
|
ip = gethostbyname(host);
|
|
ip = gethostbyname(host);
|
|
@@ -221,8 +224,16 @@ int callapi(char *command, char *host, short int port)
|
|
|
else {
|
|
else {
|
|
|
p = 0;
|
|
p = 0;
|
|
|
buf[0] = '\0';
|
|
buf[0] = '\0';
|
|
|
- while (p < RECVSIZE) {
|
|
|
|
|
- n = recv(sock, &buf[p], RECVSIZE - p , 0);
|
|
|
|
|
|
|
+ while (true)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (bufsz < RECVSIZE + p)
|
|
|
|
|
+ {
|
|
|
|
|
+ bufsz *= 2;
|
|
|
|
|
+ buf = realloc(buf, bufsz);
|
|
|
|
|
+ assert(buf);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ n = recv(sock, &buf[p], RECVSIZE, 0);
|
|
|
|
|
|
|
|
if (SOCKETFAIL(n)) {
|
|
if (SOCKETFAIL(n)) {
|
|
|
printf("Recv failed: %s\n", SOCKERRMSG);
|
|
printf("Recv failed: %s\n", SOCKERRMSG);
|