How to know which network path my program is using? - networking

How to know which network path my program is using ?
I have a program running on solaris, this machine has multiple network interfaces few connected to 1Gig and few 10 gig. Suppose my application with PID P is running. IS there any command which display which network interface my program is submitting packets.

Not really. Your program is delegating to the kernel the task to choose which network interface(s) to use. If there is no ambiguity, i.e. if only one interface is suitable for the job, you can then identify it.
To get what IP addresses your program is connected to, you can use this command:
pfilepid| grep AF_INET
ifconfig -a and netstat -rn will help knowing what interfaces are there and what routes use what interfaces.

Related

How to check if a device is using RS232 or RS422?

Suppose we have a device which can operate on both RS232 and RS422 protocols. we know which serial port is connected to the device, lets say /dev/ttyS4.
In Linux environment using setserial, dmesg and proc file-system (following commands) helps to identify the serial ports and some hardware/software configurations of them but not much about the device connected to them. (am I missing something here?)
dmesg | grep tty
cat /proc/tty/driver/serial
setserial -a /dev/ttyS[0-4]
My question being, Is there a good way in which we can point out exactly which protocol the device is using?

OpenMPI: Multiple Ethernet Interfaces Failure

I wanted to setup a 3-node ring network, each connects to the other 2 using 2 Ethernet ports directly without a switch/router.
The interface configurations looks like this:
I've used ifconfig on each node to configure each port, and made sure I can ssh from each node to the other 2 nodes.
But a simple ring_c example doesn't work... So I turn on --mca btl_base_verbose 30, I could see that node1 was trying to use 23.0.0.2 (linke between node2 and 3) to get to node2 though there is a direct link to node 2.
The output log is like:
[node1:01828] btl: tcp: attempting to connect() to [[19529,1],1]
address 23.0.0.2 on port 1024
[[19529,1],0][btl_tcp_endpoint.c:606:mca_btl_tcp_endpoint_start_connect]
from node1 to: node2 Unable to connect to the peer 23.0.0.2 on port
4: Network is unreachable
I've read the following posts and FAQs but still couldn't understand this kind of behavior.
How does Open MPI know which IP addresses are routable to each other in Open MPI 1.3 (and beyond)?
How do I tell Open MPI which IP interfaces / networks to use?
Open MPI User's Mailing List Archives
Any pointers would be appreciated! Thanks in advance!
My open-mpi info:
Open MPI: 1.0.0.22
Open RTE: 1.0.0.22
OPAL: 1.0.0.22
MPI API: 2.1
Best,
Shang

Multiple programs on a machine should receive the network traffic arriving on one port

I have UDP network traffic arriving on my machine (OSC traffic from an iPad, to be exact) and I want two programs to be able to receive that traffic. The problem is that I can't bind to the same network port with two programs at once and I can't send to multiple ports with the iOS app I'm using. How can I solve this problem?
You can use the power of the command line for this. The following snippet uses socat (probably needs to be installed beforehand) and tee (should be preinstalled on any OS X or Linux).
socat -u UDP4-RECVFROM:8123,fork - | tee >(socat -u - UDP4-SENDTO:localhost:8223) | socat -u - UDP4-SENDTO:localhost:8323
Explanation: socat listens for traffic on UDP port 8123, pipes it to tee, which pipes it to two other instances of socat forwarding it to ports 8223 and 8323 on localhost respectively. With your two programs you need to listen to those ports on localhost.
While the answer with using socat is elegant it is not clear for me, what you are trying to do:
both programs should receive all parts of the traffic and they will only receive and not reply. This can be done with the proposed socat way
both program should receive all parts of the traffic and there reply will be mixed together (how?)
each of the programs should only receive parts of the traffic, e.g. the one which the other did not get. This should be possible if both of your programs use SO_REUSEADDR, SO_REUSEPORT. Replies will then be mixed together.
or do you actually want to communicate with each of the programs seperatly - then you would have to use either multiple sockets in the iOS app (which you don't want to do) or built your own protocol which does multiplexing, e.g. each message is prefixed with there target app and on the target machine a demultiplexer application will receive all packets and forward them to the appropriate application and wrap the replies back in the multiplexing protocol.
In summary: please describe the problem your are trying to solve, not only one small technical detail of it.
The problem is that I can't bind to the same network port with two programs at once
Yes you can. Just set SO_REUSEADDR and maybe SO_REUSEPORT on both of them before you bind.

How to implement virtual network interface

I am trying to write a program to simulate some virtual network interfaces. My program runs on a Linux PC, denoted A, connected to a router, denoted R, and A has one physical network interface eth0 with an IPv4 address, say, 192.168.1.2. My program can obtain multiple different IPv4 addresses from the router via DHCP, say, 192.168.1.3, 192.168.1.4, ... (I have done this part by making up some virtual MAC address). What I need to do next is that, when another physical PC, denoted B, which is also connected to the router R, tries to communicate with one of the IPv4 addresses obtained by my program (not the one assigned to the physical interface, eth0, of A), say, 192.168.1.3 it should appear to B that 192.168.1.3 is a "real" network interface. For example, if B ping 192.168.1.3, it should be able to receive response from 192.168.1.3 (even thought the packet actually pass through A's physical network interface eht0). In addition, my program should be able to extract the IP packet on the virtual interface where the whole packet is received.
In other words, what my program wants to accomplish is like the "Bridged Network" in virtual machines like VirutalBox or VMWare Player.
Can someone please tell me what I should start with? Should I use TAP? Are there any existing libraries which I could use? Or should I just create a link layer socket for my purpose? (I read "Datalink Access" in Richard Stevens's Unix Network Programming, but the info is not quite detailed.)
Thanks,
Tom
From my understanding of your requirement, you can use the subinterfaces. You can split the eth0 to multiple interfaces like eth0:1 eth0:2 etc. Then you can assign IP for each of these interfaces and use them as regular interfaces. You can run run tcpdump/wireshark on these subinterfaces and capture the packets as you wish.

Using socat to relay one TTY stream to multiple TCP/IP destinations, plus to one 'sniffer' program

Using an embedded Linux development board, I need to put together a widget that does the following:
Reads packets in via physical serial port, and relays those packets to a number of IP addresses (up to 20 of them; with IP destinations read from a configuration file).
Also 'sniff' those serial packets using a custom program, perhaps written in c.
As someone with a programming background, the most obvious solution (to me) would be to create a c program from scratch to achieve the above. However, as this is something I need to throw together quickly, and because I need an excuse to learn more about existing Linux command-line programs and script writing (which I'm not so good at), I'm wondering if much of this could be achieved with existing command-line programs and a shell script. Then, the only part I write from scratch is my packet sniffer (call it sniffer.c).
I understand that netcat and socat can be used for relaying between devices and addresses, and I have started experimenting with both. The thought occurs to me that I could avoid having to develop and test TCP/IP software by running multiple instances of socat to relay serial data from the TTY port to remote IP addresses. Each instance of socat could handle a particular remote IP address.
Does this sound feasible, and if so, how could I effectively 'multiplex' a stream from /dev/ttyS0 (say) as the source for multiple instances of socat plus one instance of sniffer.c? Could one way be to relay data read from /dev/ttyS0 to a cache file, and then have my socat instances and sniffer.c all have a read-only access to that file?

Resources