socketpair的使用

一: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     

可以看出已经创建成功了本地套接口。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值