当前位置:  技术问答>linux和unix

真心求教!!UNIX域编程中bind() 和listen()函数出错!!

    来源: 互联网  发布时间:2017-04-10

    本文导语:  刚接触UNIX域编程 运行时 bind() 和listen()一直报错代码如下: #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  int main() {   struct sockaddr_un address;   int sock=0, conn;   int ...

刚接触UNIX域编程
运行时 bind() 和listen()一直报错代码如下:
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 


int main()
{
  struct sockaddr_un address;
  int sock=0, conn;
  int addrLength;
  char buf[1024] = {0};
  char *msg = "I has recived";
  if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) = 0)
  {
    printf("int while!n");
    recv(conn, buf, sizeof(buf), 0);
    printf("%s/n", buf);
    send(conn, msg, strlen(msg), 0);
  }
  return 0;
}

运行时一直报告以下两个错误:
bind: Operation not permitted
listen: Invalid argument

请了解的人帮忙解决!!!

|
addrLength = sizeof(address.sun_family)+strlen(address.sun_path);
似乎应该是:
addrLength = sizeof(struct sockaddr_un);

另外看一下/mnt/hgfs/share/unix/foo.sock的权限问题。

|
确定/mnt/hgfs/share/unix/foo.sock文件已经不存在,确定/mnt/hgfs/share/unix目录你有写权限。

    
 
 
 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐
  • 在linux下面怎么安程序啊?我刚裝了一个 linux,下了一个迅雷安装程序,可是不知道怎么安装啊?真心请教。
  • 真心需要各位前辈指点,谢谢 有关LINUX USB驱动程序编写的一个问题
  • 真心请教Linux kernel进入Suspend问题
  • 真心求助:各位大哥能帖一个 socket 程序的例子吗?(要是多线程序的),分少了开帖再加!谢谢!


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,