Sponsored Content
Top Forums Programming Get the file descriptor of a socket file. C vs Python. Post 302204451 by Perderabo on Wednesday 11th of June 2008 04:49:12 PM
Old 06-11-2008
Quote:
Originally Posted by goon12
I am still curious to know how to get the file descriptor of a socket file (/tmp/mapping-foo) though.
Try something like:
un.sun_family=AF_UNIX;
strcpy(un.sun_path, "(/tmp/mapping-foo");
fd=socket(AF_UNIX,SOCK_STREAM,0);
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

file activity (open/closed) file descriptor info using KORN shell scripting

I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)
Discussion started by: Gary Dunn
3 Replies

2. UNIX for Dummies Questions & Answers

File Descriptor Help

What is a file descriptor in Unix?? How to find a file descriptor of a file in Unix?? Does it have anything to do with the Inode numbers?? (3 Replies)
Discussion started by: rahulrathod
3 Replies

3. IP Networking

Can we write a multiple thread to receive from a single socket file descriptor

Hi Friends, I have written a program which will listener for more than 1000 requests per second from a single socket descriptor and then it will process those requestes. Its taking X amount of time. Now i want to reduce that time. Will I can write multiple threads to receive the... (2 Replies)
Discussion started by: pa.chidhambaram
2 Replies

4. Shell Programming and Scripting

File Descriptor

Hello All, Im opening a file desciptor in perl and sending data using print CMD "$xyz". is there a limit to the length of the string that I can give to this CMD at a time. (3 Replies)
Discussion started by: rimser9
3 Replies

5. UNIX for Dummies Questions & Answers

File Descriptor

Hi What the below path contains? /proc/<pid>/fd (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

6. Solaris

Polling on socket descriptor does not return pollhup

I have a query related to the functioning of poll() system call on solaris and linux platforms. When the client is abnormally terminated, it is observed that on Linux the socket is immediately closed and the server gets ECONNREFUSED. But in case of Solaris it is observed that the socket is not... (0 Replies)
Discussion started by: Amarjeet_7
0 Replies

7. UNIX for Dummies Questions & Answers

Difference between file descriptor and file pointer

hi...., can anyone tell me what is the exact difference between file descriptor and file pointer...... and why file descriptor takes integer value???:confused: (10 Replies)
Discussion started by: jimmyuk
10 Replies

8. Programming

Copying and overwriting a file using file descriptor

Hi , i have two basic requirement on linux platform . I am using C language to do this . 1) copying one file to another (assuming i know their file descriptors) 2) Overwriting a file using it file descriptor . Please guide. regards Aki (2 Replies)
Discussion started by: meet123321
2 Replies

9. Shell Programming and Scripting

file descriptor count

I am trying to write a script which will only show me the file descriptor count for a process/pid. My script will return me the count only not the whole output. For example, I would like my script to return the output 23 this case, not the whole output. Can anybody please help me how do I get... (11 Replies)
Discussion started by: mohullah
11 Replies

10. Solaris

18-Mar-2012 14:25:03.209 general: error: socket: file descriptor exceeds limit (4096/4096)

I have BIND 9.8.1-P1 cache only DNS server running in Solaris 10. I have upgraded the same from 9.6.1 to 9.8.1-P1. Now i am facing "file descriptor exceeds limit (4096/4096)" error frequently on the server. Please help me on this issue! (1 Reply)
Discussion started by: sandeep.tk
1 Replies
UNIX(7) 						     Linux Programmer's Manual							   UNIX(7)

NAME
unix, PF_UNIX, AF_UNIX, PF_LOCAL, AF_LOCAL - Sockets for local interprocess communication. SYNOPSIS
#include <sys/socket.h> #include <sys/un.h> unix_socket = socket(PF_UNIX, type, 0); error = socketpair(PF_UNIX, type, 0, int *sv); DESCRIPTION
The PF_UNIX (also known as PF_LOCAL) socket family is used to communicate between processes on the same machine efficiently. Unix sockets can be either anonymous (created by socketpair(2)) or associated with a file of socket type. Linux also supports an abstract namespace which is independent of the file system. Valid types are SOCK_STREAM for a stream oriented socket and SOCK_DGRAM for a datagram oriented socket that preserves message boundaries. Unix sockets are always reliable and don't reorder datagrams. Unix sockets support passing file descriptors or process credentials to other processes as ancillary data to datagrams. ADDRESS FORMAT
A unix address is defined as a filename in the filesystem or as a unique string in the abstract namespace. Sockets created by socketpair(2) are anonymous. For non-anonymous sockets the target address can be set using connect(2). The local address can be set using bind(2). When a socket is connected and it doesn't already have a local address a unique address in the abstract namespace will be generated automati- cally. #define UNIX_PATH_MAX 108 struct sockaddr_un { sa_family_t sun_family; /* AF_UNIX */ char sun_path[UNIX_PATH_MAX]; /* pathname */ }; sun_family always contains AF_UNIX. sun_path contains the zero-terminated pathname of the socket in the file system. If sun_path starts with a zero byte it refers to the abstract namespace maintained by the Unix protocol module. The socket's address in this namespace is given by the rest of the bytes in sun_path. Note that names in the abstract namespace are not zero-terminated. SOCKET OPTIONS
For historical reasons these socket options are specified with a SOL_SOCKET type even though they are PF_UNIX specific. They can be set with setsockopt(2) and read with getsockopt(2) by specifying SOL_SOCKET as the socket family. SO_PASSCRED enables the receiving of the credentials of the sending process ancillary message. When this option is set and the socket is not connected yet an unique name in the abstract namespace will be generated automatically. Expects an integer boolean flag. ANCILLARY MESSAGES
For historical reasons these ancillary message type are specified with a SOL_SOCKET type even though they are PF_UNIX specific. To send them set the cmsg_level field of the struct cmsghdr to SOL_SOCKET and the cmsg_type field to the type. For more information see cmsg(3). SCM_RIGHTS Send or receive a set of open file descriptors from another process. The data portion contains a integer array of the file descrip- tors. The passed file descriptors behave as like they have been created with dup(2). SCM_CREDENTIALS Send or receive unix credentials. This can be used for authentication. The credentials are passed as a struct ucred ancillary mes- sage. struct ucred { pid_t pid; /* process id of the sending process */ uid_t uid; /* user id of the sending process */ gid_t gid; /* group id of the sending process */ }; The credentials which the sender specifies are checked by the kernel. A process with effective user id 0 is allowed to specify values that do not match his own. The sender must specify its own process id (unless it has CAP_SYS_ADMIN), its user id, effective user id or set user id (unless it has CAP_SETUID), and its group id, effective group id or set group id (unless it has CAP_SETGID). To receive a struct ucred message the SO_PASSCRED option must be enabled on the socket. VERSIONS
SCM_CREDENTIALS and the abstract namespace were introduced with Linux 2.2 and should not be used in portable programs. NOTES
In the Linux implementation, sockets which are visible in the filesystem honour the permissions of the directory they are in. Their owner, group and their permissions can be changed. Creation of a new socket will fail if the process does not have write and search (execute) permission on the directory the socket is created in. Connecting to the socket object requires read/write permission. This behavior dif- fers from many BSD derived systems which ignore permissions for Unix sockets. Portable programs should not rely on this feature for secu- rity. Binding to a socket with a filename creates a socket in the file system that must be deleted by the caller when it is no longer needed (using unlink(2)). The usual Unix close-behind semantics apply; the socket can be unlinked at any time and will be finally removed from the file system when the last reference to it is closed. To pass file descriptors or credentials you need to send/read at least one byte. ERRORS
ENOMEM Out of memory. ECONNREFUSED connect(2) called with a socket object that isn't listening. This can happen when the remote socket does not exist or the filename is not a socket. EINVAL Invalid argument passed. A common cause is the missing setting of AF_UNIX in the sun_type field of passed addresses or the socket being in an invalid state for the applied operation. EOPNOTSUPP Stream operation called on non-stream oriented socket or tried to use the out-of-band data option. EPROTONOSUPPORT Passed protocol is not PF_UNIX. ESOCKTNOSUPPORT Unknown socket type. EPROTOTYPE Remote socket does not match the local socket type (SOCK_DGRAM vs. SOCK_STREAM) EADDRINUSE Selected local address is already taken or filesystem socket object already exists. EISCONN connect(2) called on an already connected socket or a target address was specified on a connected socket. ENOTCONN Socket operation needs a target address, but the socket is not connected. ECONNRESET Remote socket was unexpectedly closed. EPIPE Remote socket was closed on a stream socket. If enabled, a SIGPIPE is sent as well. This can be avoided by passing the MSG_NOSIGNAL flag to sendmsg(2) or recvmsg(2). EFAULT User memory address was not valid. EPERM The sender passed invalid credentials in the struct ucred. Other errors can be generated by the generic socket layer or by the filesystem while generating a filesystem socket object. See the appro- priate manual pages for more information. SEE ALSO
recvmsg(2), sendmsg(2), socket(2), socketpair(2), cmsg(3), socket(7) CREDITS
This man page was written by Andi Kleen. Linux Man Page 1999-05-07 UNIX(7)
All times are GMT -4. The time now is 05:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy