在SOLARIS上,RPC调用“ svc_fd_create”失败,并出现“文件编号错误”错误

时间:2018-08-07 10:13:28

标签: network-programming solaris rpc

我需要在基本代码中替换一些过时的RPC调用。我必须将“ svcfd_create()”替换为“ svc_fd_create()”。更改在Linux上已成功运行,但是在SOLARIS上却失败。

我创建了以下示例程序来检查场景,“ svcfd_create()”运行正常,但是“ svc_fd_create()”失败,并显示错误“套接字:错误的文件号”。

Platfrom:

bash-3.2#uname -a SunOS XXXXXXX 5.10 Generic_Virtual sun4v sparc sun4v

用于编译的命令:

/ usr / bin / CC -R / usr / ucblib -L ​​/ usr / ucblib -L ​​/ usr / lib -lsocket -lrpcsoc -lnsl Server.c

#include <stdio.h>
#include <stdlib.h>
#include <rpc/rpc.h>
#include <rpc/svc_soc.h>
#include <errno.h>
#include <string.h>
#include <memory.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>

main()
{
        register SVCXPRT *transp;
        struct sockaddr_in serv_addr;
        memset(&serv_addr,0,sizeof(serv_addr));
        int sock;
        int pid;

        sock  = socket(AF_INET, SOCK_STREAM, 0);
        if (sock < 0) printf("ERROR opening socket");

        serv_addr.sin_family = AF_INET;
        serv_addr.sin_addr.s_addr = INADDR_ANY;
        serv_addr.sin_port = htons(2363);

        if (bind(sock, (struct sockaddr *) &serv_addr,
                 sizeof(serv_addr)) < 0)
                 printf("ERROR on binding \n");
        listen(sock,5);

        perror("socket");

        printf("Socket created : %d \n", sock);
        printf("before svc_fd_create \n");
        // Uncomment the line with "svcfd_create" and comment the line with "svc_fd_create" to run success scenario
        //transp = svcfd_create(sock, 0, 0);  // RPC CALL WORKING
        transp = svc_fd_create(sock, 0, 0);    // RPC CALL NOT WORKING
        printf("after svc_fd_create \n");
        perror("socket");
        if (transp == NULL) {
            printf ("cannot create tcp service.\n");
            fprintf(stderr, "socket() failed: %s\n", strerror(errno));
            exit(1);
        }
        else
        {
            printf ("transp->xp_fd: %d \n", transp->xp_fd);
        }
}

使用“ svcfd_create”,结果如下:

bash-3.2# ./a.out
socket: Error 0
Socket created : 3
before svc_fd_create
after svc_fd_create
socket: Error 0
transp->xp_fd: 3

使用“ svc_fd_create”,结果如下:

bash-3.2# ./a.out
socket: Error 0
Socket created : 3
before svc_fd_create
after svc_fd_create
socket: Bad file number
cannot create tcp service.
socket() failed: Bad file number

要使“ svc_fd_create()”成功工作,这里缺少什么。我在这里茫然。

0 个答案:

没有答案