|
[code:1]
//--------------------------------------------------------------
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/un.h>
static char filename[] = {"/home/mryx/testsock/data"};
int main(int argc, char *argv[])
{
int sock;
struct sockaddr_un name;
size_t size;
sock = socket(PF_UNIX, SOCK_DGRAM, 0);
if(sock < 0){
printf("\tExit , errno = %d\n", errno);
exit(-1);
}
name.sun_family = AF_FILE;
strcpy(name.sun_path, filename);
size = (offsetof(struct sockaddr_un, sun_path) + strlen(name.sun_path)+1);
if(bind(sock, (struct sockaddr*)&name, size) < 0){
printf("\tExit, errno = %d\n", errno);
shutdown(sock, 0);
exit(-1);
}
shutdown(sock, 0);
return 0;
}
//---------------------------------------------------------
[/code:1]
运行之后,
Exit, errno = 98
这个程序几乎就是libc文档的原样阿。。。怎么通不过阿。。。 [/code] |
|