Say I've got a file descriptor from socket(2) and I've done a connect(2) on it -- is there any way later to determine (from inside the running program) what network device might be in use for the underlying transport? A call to stat(2) on the fd gives a device number of 0; none of the ioctl(2) or getsockopt(2) options seem applicable.
Can I find what network interface/device is handling my socket?
843 Views Asked by jhfrontz At
2
There are 2 best solutions below
2
Gil Hamilton
On
There's no foolproof way to do so -- certainly not a posix-compliant way.
However, in practice, you can easily determine the interface 99% of the time. After you've done the connect, use getsockname to obtain the IP address, then look through the list of available interfaces on the box for one with a matching IP address.
Related Questions in SOCKETS
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- My server TCP doesn't receive messages from the client in C
- how is strncpy able to copy from source to empty destination?
- Python Multicast packet receiver stops receiving multicast packets when computer is connected to WiFi
- Python Client-Server Communication with Protocol
- Reversed TLS re-connection issue
- Android 13 & 14 seem to close WebSocket connection, if i put app in background, after ~20s
- Java SocketException: Connection reset,. What is the cause?
- Multipart/form-data with chunked data transfer (ICAP protocol)
- View Socket View
- Client connection timeout during Android & Windows PC communication via sockets
- Browser connect to raw sockets even possible?
- Protocol 43200 after unpacking received data
- Unity SocketIo using Best http2 plugin want to use in webgl
- How does pre-allocating a pool of SocketAsyncEventArgs objects upfront improve the performance of a server application in c#
Related Questions in POSIX
- Is it safe to assume 8-bit char on Linux and FreeBSD, based on POSIX?
- How many senders and receivers of a notification are possible in a POSIX message queue
- Does opendir() / FindFirstFile() get a snapshot of a directory?
- Differences in behavior of kill(pid, SIGINT) between Debian and Red Hat based distros
- select() always returns 0 Serial Port (UART) vxWorks
- some questions about posix_trace_* function
- In LDAP: Differentiating via OU or via attribute?
- recvmsg returns EAGAIN after select reports file descriptor is ready
- Can close of pipe's write end fail leaving reading process blocked?
- Why, on Linux (specifically Ubuntu 20.04 LTS), a POSIX shared memory object survives reboot and then suddenly belongs to the "root" user?
- file.tell() after a write is not correct in append mode?
- Map UNIX "nobody" and "nogroup" to Win32 Accounts/SIDs?
- POSIX Message Queue - "Message too long" on send
- Does the POSIX Standard really mean that a non-thread safe function can break the thread-safety of every other function?
- awk dot in regex doesn't match space
Related Questions in IOCTL
- Socket:When I use over 15 socket , perror will tell:no such device
- How to allocate 500MB+ physically contiguous memory in a Linux kernel module and copy data to that memory from a userspace process?
- Why does `echo 0 >> /dev/mydevice` trigger `unlocked_ioctl` in linux driver
- Pinned GCHandle of array corrupted only when Debugger is attached
- Was there a previous version of tty_ldisc_ops.ioctl() that also required a file argument?
- The difference between SPI_IOC_RD_MODE and SPI_IOC_RD_MODE32?
- Is there any way to determine on which disk does a particular logical offset of a spanned volume resides?
- How to send HID commands and read HID data from Linux Kernel Module?
- Peculiarities of grabbing keys and scancodes different methods LINUX
- Why does TIOCSTI take pointer to char instead of char?
- What does Windows IOCTL code 0x83350048 do?
- I need send raw buffer of data on I2c In fedora OS
- Using IOCTL to get WiFi Client RSSI information
- Can I trigger an auto-negotiation of an interface using the ethtool userspace API with NETLINK sockets?
- How can a Windows filter driver send IOCTL_HID_SET_FEATURE request to hidusb/HID minidriver?
Related Questions in GETSOCKOPT
- can't retrieve error through getsockopt while errno = 13
- What is tcp_info->tcpi_rtt field and how it is calculated?
- In socket programming using C language, how to set time limit on server for accepting client to establish connection?
- Why getsockopt optlen is zero?
- printf("%m") reports an error yet errno is set to 0
- Get SO_RCVBUF socket option value from Qt
- How to know 'sequence number' wiht getsockopt?
- getsockopt api design questions
- Which direction (inbound or outbound) does TCP_INFO returned from getsockopt give?
- socket option TCP_NODELAY on windows requires 8bit Bool?
- Why does TCP_INFO option on getsockopt() return contradicting values?
- Dial tcp 127.0.0.1:8500: getsockopt: connection refused in consul
- getsockopt return negative mss (on CLion)
- Can I find what network interface/device is handling my socket?
- Where do the function pointers point to in struct "proto_ops"?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
From the
acceptcall you should be able to get the remote client's ip address (seen here on Beej's). Assuming you do not have any asymmetric routes, you can look up the route to that address in your local routing table. The routing table should tell you what ethernet device is used to send packets to the remote client.EDIT:
you could use the following command line tool to query your local routing table with the remote client's address: