How to identify a client connected to AF_UNIX socket?

Al Berger

What is the meaning of the "client address" in case of AF_UNIX sockets in Python?

sock = socket.socket( socket.AF_UNIX, socket.SOCK_STREAM )
sock.bind( "/tmp/sock" )
sock.listen( 1 )
while True:
    connection, client_address = sock.accept()
    print( client_address ) # prints : b''

Is there a way to obtain on the server side any information about the connected client?

James Mills

For UNIX Sockets; socket.acept() will return socket, (). i.e: An empty tuple.

You can get some information about the "client" socket by looking at socket.fileno() for example.

For example with a modified echoserverunix.py:

$ python examples/echoserverunix.py 
<registered[*] (<Debugger/* 19377:MainThread (queued=0) [S]>, <EchoServer/server 19377:MainThread (queued=2) [R]> )>
<started[server] (<EchoServer/server 19377:MainThread (queued=1) [R]> )>
<registered[select] (<Select/select 19377:MainThread (queued=0) [S]>, <EchoServer/server 19377:MainThread (queued=2) [R]> )>
<ready[server] (<EchoServer/server 19377:MainThread (queued=1) [R]>, ('/tmp/test.sock', None) )>
<_read[server] (<socket._socketobject object at 0x7fa4c0b8a210> )>
<connect[server] (<socket._socketobject object at 0x7fa4c0b8a1a0> )>
<socket._socketobject object at 0x7fa4c0b8a1a0>
6
()

According to the accept() man page hwoever:

Return Value

On success, these system calls return a nonnegative integer that is a descriptor for the accepted socket. On error, -1 is returned, and errno is set appropriately.

So at the C level you get back the "file descriptor" which Python creates a socket object out of. But there is no peer address or path that th client connected from other than the file descriptor.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

AF_UNIXでsocket()があるのに、なぜsocketpair()が必要なのですか?

分類Dev

How to make client socket wait for server socket

分類Dev

How to disconnect a client from NIO server socket

分類Dev

How to identify (un)successful authentication in Socket.IO (via socketio-auth)?

分類Dev

How to store client associated data in socket.io 1.0

分類Dev

How to reconnect to a Web Socket when I refresh the client web page

分類Dev

ThreadingTCPServer won't exit when client connected

分類Dev

UDP Client/Server Socket in Python

分類Dev

UDP Client/Server Socket in Python

分類Dev

Listen in server to a socket emit by a client

分類Dev

Ionic Client network socket disconnected

分類Dev

synchronous multiple socket client clarification

分類Dev

AF_UNIXソケットを使用した双方向通信

分類Dev

How to check if MQ is connected

分類Dev

How are these nested vectors connected?

分類Dev

How to view that Advertiser is connected

分類Dev

How to inform and update a client when a new record inserted in mysql database using node js and socket.io

分類Dev

How do I get my asyncio client to call a socket server and waiting for response

分類Dev

How to communicate a Rust and a Ruby process using a Unix socket pair

分類Dev

how get socket port number from an accept call (C UNIX)

分類Dev

How to identify the process locking a file?

分類Dev

How to identify the stack size of goroutine?

分類Dev

How to identify Bimodal Histograms automatically?

分類Dev

how to identify if a xmlnode has no value?

分類Dev

How to identify a sentences related to a topic?

分類Dev

How identify an AMR file with PHP?

分類Dev

How to identify visual studio symbols?

分類Dev

How to identify the terminal from a script?

分類Dev

How to identify and upgrade current installations?

Related 関連記事

  1. 1

    AF_UNIXでsocket()があるのに、なぜsocketpair()が必要なのですか?

  2. 2

    How to make client socket wait for server socket

  3. 3

    How to disconnect a client from NIO server socket

  4. 4

    How to identify (un)successful authentication in Socket.IO (via socketio-auth)?

  5. 5

    How to store client associated data in socket.io 1.0

  6. 6

    How to reconnect to a Web Socket when I refresh the client web page

  7. 7

    ThreadingTCPServer won't exit when client connected

  8. 8

    UDP Client/Server Socket in Python

  9. 9

    UDP Client/Server Socket in Python

  10. 10

    Listen in server to a socket emit by a client

  11. 11

    Ionic Client network socket disconnected

  12. 12

    synchronous multiple socket client clarification

  13. 13

    AF_UNIXソケットを使用した双方向通信

  14. 14

    How to check if MQ is connected

  15. 15

    How are these nested vectors connected?

  16. 16

    How to view that Advertiser is connected

  17. 17

    How to inform and update a client when a new record inserted in mysql database using node js and socket.io

  18. 18

    How do I get my asyncio client to call a socket server and waiting for response

  19. 19

    How to communicate a Rust and a Ruby process using a Unix socket pair

  20. 20

    how get socket port number from an accept call (C UNIX)

  21. 21

    How to identify the process locking a file?

  22. 22

    How to identify the stack size of goroutine?

  23. 23

    How to identify Bimodal Histograms automatically?

  24. 24

    how to identify if a xmlnode has no value?

  25. 25

    How to identify a sentences related to a topic?

  26. 26

    How identify an AMR file with PHP?

  27. 27

    How to identify visual studio symbols?

  28. 28

    How to identify the terminal from a script?

  29. 29

    How to identify and upgrade current installations?

ホットタグ

アーカイブ