*
* Example of socketpair(2) function:
*/
#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 argc,char **argv) {
int z; /* Status return code */
int s[2]; /* Pair of sockets */
/*
* Create a pair of local sockets:
*/
z = socketpair(AF_LOCAL,SOCK_STREAM,0,s);
if ( z == -1 ) {
fprintf(stderr, "%s: socketpair(AF_LOCAL, SOCK_STREAM, 0)\n",
strerror(errno));
return 1; /* Failed */
}
/*
* Report the socket file descriptors returned:
*/
printf("s[0] = %d;\n",s[0]);
printf("s[1] = %d;\n",s[1]);
system("netstat --unix -p");
return 0;
}
/***************************************************************
* OUTPUT
*********
[sgupta@rhel55x86 socketpair]$ ./socketpair
s[0] = 3;
s[1] = 4;
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ] DGRAM 1247 - @/org/kernel/udev/udevd
unix 2 [ ] DGRAM 4882 - @/org/freedesktop/hal/udev_event
unix 18 [ ] DGRAM 4350 - /dev/log
unix 3 [ ] STREAM CONNECTED 151338 8060/socketpair
unix 3 [ ] STREAM CONNECTED 151337 8060/socketpair
unix 3 [ ] STREAM CONNECTED 151096 -
unix 3 [ ] STREAM CONNECTED 151095 -
unix 2 [ ] DGRAM 151091 -
unix 3 [ ] STREAM CONNECTED 7696 - @/tmp/fam-root-
unix 3 [ ] STREAM CONNECTED 7695 -
unix 3 [ ] STREAM CONNECTED 7686 - /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 7685 -
unix 3 [ ] STREAM CONNECTED 7677 - /tmp/.X11-unix/X0
unix 3 [ ] STREAM CONNECTED 7676 -
unix 3 [ ] STREAM CONNECTED 7673 - /tmp/.X11-unix/X0
unix 3 [ ] STREAM CONNECTED 7672 -
unix 3 [ ] STREAM CONNECTED 7668 - /var/run/pcscd.comm
unix 3 [ ] STREAM CONNECTED 7667 -
unix 3 [ ] STREAM CONNECTED 7648 - /tmp/.font-unix/fs7100
unix 3 [ ] STREAM CONNECTED 7647 -
unix 2 [ ] DGRAM 7641 -
unix 3 [ ] STREAM CONNECTED 7651 - /tmp/.X11-unix/X0
unix 3 [ ] STREAM CONNECTED 7625 -
unix 2 [ ] DGRAM 5599 -
unix 3 [ ] STREAM CONNECTED 5571 - /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 5570 -
unix 3 [ ] STREAM CONNECTED 5548 - @/var/run/hald/dbus-VD8jlHSvyw
unix 3 [ ] STREAM CONNECTED 5545 -
unix 3 [ ] STREAM CONNECTED 5408 - @/var/run/hald/dbus-VD8jlHSvyw
unix 3 [ ] STREAM CONNECTED 5406 -
unix 3 [ ] STREAM CONNECTED 5370 - /var/run/acpid.socket
unix 3 [ ] STREAM CONNECTED 5369 -
unix 3 [ ] STREAM CONNECTED 5364 - @/var/run/hald/dbus-VD8jlHSvyw
unix 3 [ ] STREAM CONNECTED 5363 -
unix 3 [ ] STREAM CONNECTED 4877 - @/var/run/hald/dbus-W3oEtHSudJ
unix 3 [ ] STREAM CONNECTED 4876 -
unix 2 [ ] DGRAM 4822 -
unix 3 [ ] STREAM CONNECTED 4732 - /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 4731 -
unix 2 [ ] DGRAM 4710 -
unix 2 [ ] DGRAM 4700 -
unix 3 [ ] STREAM CONNECTED 4665 -
unix 3 [ ] STREAM CONNECTED 4664 -
unix 3 [ ] STREAM CONNECTED 4623 -
unix 4 [ ] STREAM CONNECTED 4622 -
unix 2 [ ] DGRAM 4517 -
unix 2 [ ] DGRAM 4358 -
unix 3 [ ] STREAM CONNECTED 4296 -
unix 3 [ ] STREAM CONNECTED 4295 -
[sgupta@rhel55x86 socketpair]$ vim socketpair.c
***********************************************************/
No comments:
Post a Comment