如何解决Asterisk

时间:2015-05-12 14:16:07

标签: c asterisk

我为星号编写了一个模块,需要与服务请求信息进行通信并返回它,但由于某种原因,我的套接字根本没有连接。当我telnet到服务它工作正常,但我无法弄清楚为什么它在模块中返回-1

这是我模块中的代码

int SocketQuery(char buffer[BUFFSIZE],char *qrystr){
            int sock;
            struct sockaddr_in eserver;
            int sockres = 0;
            unsigned char receiving = 1;

            memset(sendbuff,0,sizeof(sendbuff));
            /* Create the TCP socket */
            if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
              ast_log(LOG_ERROR,"Failed to create socket for LCRROUTER");
              return -1;
            }
            /* Construct the server sockaddr_in structure */
            memset(&eserver, 0, sizeof(eserver));       /* Clear struct */
            eserver.sin_family = AF_INET;                  /* Internet/IP */
            eserver.sin_addr.s_addr = inet_addr(IP);  /* IP address */
            eserver.sin_port = htons(port);       /* server port */
            /* Establish connection */
            ast_log(LOG_NOTICE,"LCRROUTER - Connection to %s on port %s\n", IP, port);
            sockres = connect(sock,
                        (struct sockaddr *) &eserver,
                        sizeof(eserver));
            if (sockres < 0) {
              ast_log(LOG_ERROR,"LCRROUTER - Failed to connect with server on %s:%s. Error Code %d", IP,port,sockres);
              return -1;
            }

sockres返回-1。我想念一下吗?

1 个答案:

答案 0 :(得分:1)

您可以使用

 tcpdump port YOUR_PORT_HERE -v -s0

在该表单中,它将显示通过套接字发送的所有数据包。