分段错误('核心'创建)RPC - 客户端无法执行

时间:2016-02-22 03:49:46

标签: client-server rpc

希望你能帮助我。 我一直试图找出我的错误几乎整天都在哪里。这是RPC。客户端必须询问服务器哪个IP属于主机。这就是全部。 服务器工作正常,但是当我尝试执行客户端时,我收到通知,说我遇到了问题"分段错误,('核心')已生成"。

这是我的ips.x文件:

struct envia
{
  char dominio[50];
};

struct retorno
{
  char retips[50];
};

program IPS_PROGRAMA
{
  version VERSION_IPS_PROGRAMA
  {
    struct retorno ips (struct envia) =1;
   } =1;
}=0x20000001;

这里是ips_client.c:

/*
 * This is sample code generated by rpcgen.
 * These are only templates and you can use them
 * as a guideline for developing your own functions.
 */

#include "ips.h"


 void
ips_programa_1(char *host,char *dominio)
{
  CLIENT *clnt;
  struct retorno  *result_1;
  struct envia  ips_1_arg;

#ifndef DEBUG

clnt = clnt_create (host, IPS_PROGRAMA, VERSION_IPS_PROGRAMA, "udp");

if (clnt == NULL) {
    clnt_pcreateerror (host);
    exit (1);
}
#endif  /* DEBUG */

  strcpy(ips_1_arg.dominio,dominio);

  result_1 = ips_1(&ips_1_arg, clnt);

  if (result_1 == (struct retorno *) NULL) {
    clnt_perror (clnt, "call failed");
   }
    printf("recibido del servidor %s \n", result_1->retips);
 #ifndef    DEBUG
  clnt_destroy (clnt);
 #endif  /* DEBUG */
 }


 int
 main (int argc, char *argv[])
{
    char *host;

   if (argc < 2) {
    printf ("usage: %s server_host\n", argv[0]);
    exit (1);
 }
host = argv[1];
ips_programa_1 (host,argv[2]);
exit (0);
}

这是我的ips.server.c:

/*
 * This is sample code generated by rpcgen.
 * These are only templates and you can use them
 * as a guideline for developing your own functions.
 */

#include "ips.h"
#include<netdb.h>  
#include<string.h>
#include<arpa/inet.h>


void funcionip(char * ,char []);

struct retorno *
ips_1_svc(struct envia *argp, struct svc_req *rqstp)
{
  static struct retorno  result;

  memset(result.retips,0,100);
  funcionip(argp->dominio,result.retips);

  return &result;
}

void funcionip(char * dominio, char TodasLasIp[])
{
   struct in_addr **addr_list;
   struct hostent *he = gethostbyname(dominio);

   if (he)
   { 
     int i;
     puts(he->h_name);
     printf("Servidor Dice Nombre del Host : %s\n", he->h_name);
     printf("Servidor Dice Direcciones IP  ");
     addr_list = (struct in_addr **)he->h_addr_list;

     for(i = 0; addr_list[i] != NULL; i++)
       {
         printf("%s \n", inet_ntoa(*addr_list[i]));
         strcat(TodasLasIp,(char*) inet_ntoa(*addr_list[i]));
         strcat(TodasLasIp,"\n");
       }
      printf("\n");
    }
else
  {       
    printf("Servidor dice error gethostbyname\n");
    strcat(TodasLasIp,"error gethostbyname\n");
  }   
}

我曾在其他RPC中工作过,在#34; .x&#34;中定义了struct。文件只是整数。所以我认为错误是关于数据类型的东西?

非常感谢任何帮助!

提前致谢!!

1 个答案:

答案 0 :(得分:0)

我发现了我的愚蠢错误! 执行ips_client时,我需要3个参数: argv [0],argv [1]和argv [2]。 但是,我太傻了,忘了最后一个......¬¬

对不起!!!和合