一:socketpair的使用:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<errno.h>
#include<string.h>
#include<sys/types.h>
#include<sys/socket.h>
int main(){
int z;
int s[2];
z=socketpair(AF_LOCAL,SOCK_STREAM,0,s);
if(z==-1){
perror("create");
exit(1);
}
printf("s[0]=%d\n",s[0]);
printf("s[1]=%d\n",s[1]);
system("netstat --unix -p");
return 0;
}
运行结果:
s[0]=3
s[1]=4
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 11 [ ] DGRAM 6197 1717/syslogd /dev/log
unix 2 [ ] DGRAM 4876 1147/udevd @udevd
unix 3 [ ] STREAM CONNECTED 13873 2672/a.out
unix 3 [ ] STREAM CONNECTED 13872 2672/a.out
unix 2 [ ] DGRAM 8637 1929/nmbd
unix 2 [ ] DGRAM 6757 1925/smbd
unix 2 [ ] DGRAM 6585 1938/anacron
unix 2 [ ] DGRAM 6546 1916/xfs
unix 2 [ ] DGRAM 6503 1896/crond
unix 2 [ ] DGRAM 6487 1887/xinetd
unix 2 [ ] DGRAM 6360 1147/udevd
unix 2 [ ] DGRAM 6257 1758/rpc.statd
unix 2 [ ] DGRAM 6205 1721/klogd
可以看出已经创建成功了本地套接口。