ccplusplus.com
Learn C, C++ Concepts
Tuesday, September 20, 2011
socketpair example c
/*********************************************************************************** * Program Name : socketPair.c * Author : Saurabh Gupta * Discription : socketpair example in c * Source : http://ccplusplus.com/2011/07/socket.html * Created : 08:49 PM 10/11/2009 * Modified : PM 09:55 20 September 2011 ************************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> int main(int argc, char** argv) { int socketPairResult; int s[2]; socketPairResult = socketpair(AF_LOCAL, SOCK_STREAM, 0, s); if(socketPairResult) { printf ("socketPair failed !\n"); printf (" with an ERROR of %d\n", errno); fprintf(stderr,"%s: socketpair(AF_LOCAL,SOCK_STREAM,0)\n",strerror(errno)); } else { printf ("socketPair success !\n"); } printf ("socket descriptor s[0] = %d\n", s[0]); printf ("socket descriptor s[1] = %d\n", s[1]); system("netstat --unix -p"); return 0; } /* * OUTPUT * [sgupta@rhel55x86 socket]$ gcc socketPair.c -o socketPair [sgupta@rhel55x86 socket]$ / [sgupta@rhel55x86 socket]$ ./socketPair socketPair success ! socket descriptor s[0] = 3 socket descriptor 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 socket]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment