LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 928|回复: 8

请问bind()子函数应该怎么写?

[复制链接]
发表于 2004-4-11 16:25:53 | 显示全部楼层 |阅读模式
这是错误的提示:


  1. udpserv01.o: In function `main':
  2. udpserv01.o(.text+0x58): undefined reference to `Bind'
  3. *** Error code 1

  4. Stop in /unix/udp_echo_serv.
复制代码


这是Bind()

  1. #include "unp.h"
  2. int    /* [size=4]如果我换成 void函数有错误,不能编译通过 :confused: [/size] */
  3. Bind(int sockfd,const SA *addr,socklen_t addrlen)
  4. {
  5.           if(bind(sockfd,addr,addrlen)<0)  {
  6.                 printf("bind error\n");
  7.                 return(-2);
  8.           }
  9.           return(sockfd);
  10. }
复制代码

这是主函数updserv01.c, 只有一行,Bind()定义在 unp.h

  1. # grep Bind udpserv01.c
  2.         Bind(sockfd, (const SA *)&servaddr, sizeof(servaddr));
复制代码


unp.h

  1. # grep Bind /usr/include/unp.h
  2. void     Bind(int, const SA *, socklen_t);
复制代码



请帮忙~~~~~~:thank :thank
发表于 2004-4-11 20:32:17 | 显示全部楼层
我看书的的bind的原形好像是这样的
#include<sys/types.h>
#include<sys/socket.h>

int bind(int sockFd, const struct sockaddr *sockAddr ,int addrlen);

我是初学,不知道这个对你有没有用处
发表于 2004-4-11 21:21:01 | 显示全部楼层
楼上给的是原形,但是Bind()函数不是原形,是一个包裹函数,
我编写没有用unp,直接就是自己写,用自己的函数代替unp的,
只知道调用,具体还没有研究,就知道怎么多了,不好意思!
发表于 2004-4-11 21:21:59 | 显示全部楼层
int bind(int sockFd, const struct sockaddr *sockAddr ,int addrlen);
看unp.h的定义,怎么把他换成void型的?
发表于 2004-4-12 00:14:31 | 显示全部楼层
你的Bind里面有return(...),当然不能用void了
 楼主| 发表于 2004-4-12 19:51:19 | 显示全部楼层
最初由 libinary 发表
你的Bind里面有return(...),当然不能用void了


thanks !!

now i set return to NULL ,
The compiler has a waning about the return value,
  1. Bind.c: In function `Bind':
  2. Bind.c:7: warning: `return' with a value, in function returning void
复制代码
发表于 2004-4-14 09:43:20 | 显示全部楼层
bind应该是int的
但是Bind是作者自己写的,你注意修改
你也可以把这段写在你的c里做为函数声明的
发表于 2004-4-14 17:04:41 | 显示全部楼层
最初由 dancingpig 发表
bind应该是int的
但是Bind是作者自己写的,你注意修改
你也可以把这段写在你的c里做为函数声明的


这个。。怎么写,我也不懂。。bind()不需要返回也可以的,我们在编程中不需要它的返回值。。:help
发表于 2004-4-14 20:22:41 | 显示全部楼层
既然是void就应该是return,后面不要带返回值
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表