【问题标题】:Segmentation fault ('core' created) RPC - client doesn't execute分段错误(“核心”创建)RPC - 客户端不执行
【发布时间】:2016-02-22 03:49:45
【问题描述】:

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

这是我的 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 中工作,其中结构在“.x”文件中定义,其中只有整数。所以我认为错误与数据类型有关?

非常感谢任何帮助!

提前致谢!!

【问题讨论】:

  • 另外,在编译 ips_client.c 时出现此错误:tmp/cc6nxH9t.o : In function 'ips_programa_1': ips_client.c: (.text+0x83): undefined reference to 'ips_1' collect2: ld returned exit status (1)

标签: client-server rpc


【解决方案1】:

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

对不起!!!呵呵

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2010-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多