免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1120 | 回复: 4
打印 上一主题 下一主题

linux debug 求助 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-03-23 13:14 |只看该作者 |倒序浏览
[gaozh@PDC ~]$ ./client
----co re da--------
-------- gethostname--------
Segmentation fault (core dumped)
什么错误,怎么改正呢?谢谢!!

论坛徽章:
0
2 [报告]
发表于 2005-03-23 13:29 |只看该作者

linux debug 求助

你自己写的程序么?可以用
  1. gdb client
复制代码

来调试

论坛徽章:
0
3 [报告]
发表于 2005-03-23 14:16 |只看该作者

linux debug 求助

if(connect(sockfd, (struct sockaddr*)&their_addr, sizeof(their_addr)) != 0)
就这过不去.

论坛徽章:
0
4 [报告]
发表于 2005-03-23 14:40 |只看该作者

linux debug 求助

#include <string.h>;
#include <netdb.h>;
#include <sys/types.h>;
#include <netinet/in.h>;
#include <sys/socket.h>;
#include <stdio.h>;

int main(int argc, char* argv[])
  {
    int sockfd, numbytes;
    struct sockaddr_in their_addr; /* connector's address information */

  if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    {
        printf("socket failed\n";
        exit(1);
    }
    bzero(&their_addr, sizeof(their_addr));   /* zero the rest of the struct */
    their_addr.sin_family = AF_INET;   /* host byte order */
    their_addr.sin_port = htons(7000);  /* short, network byte order */

printf("----0003--------\n";
   // their_addr.sin_addr.s_addr = inet_addr("192.168.181.8";
   inet_pton(PF_INET, "192.168.181.8", &their_addr.sin_addr);
printf("-------hhhh-----%d\n", sockfd);
    if(connect(sockfd, (struct sockaddr*)&their_addr, sizeof(their_addr)) == -1)
{
        printf("----disconnect----\n";
        printf("----1111---\n";
        exit(1);
     }
{
printf("<>; - 1\n";
}
printf("----2222-----\n";
    if (send(sockfd, "hello", 6, 0) <= 0)
    {
        printf("----send----\n";
        exit(1);
    }
    close(sockfd);
    return 0;
}
编译信息
[gaozh@PDC ~]$ make
gcc   client.c -o client
[gaozh@PDC ~]$ ./client
----0003--------
-------hhhh-----3
----disconnect----
----1111---

论坛徽章:
0
5 [报告]
发表于 2005-03-23 14:49 |只看该作者

linux debug 求助

什么意思?
你后来的这个程序不是能执行么?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP