Determining which ip address and port an inbound packet was sent to

Determining which ip address and port an inbound packet was sent to

Post by Raja Sambasiv » Sat, 12 Jul 2003 05:01:45



Hello,

For various reasons, I need to be able to determine the ip address and
port that an RPC request was sent to (though trivial on a machine with
just one network card, if a RPC request is sent to a multi-homed
machine, then determining which network interface received the request
becomes a bit harder, I think.)

So machine A sends say a RPC read request to machine B.  Machine B
gets the request and wishes to determine which network interface
received the request.  What I do now, to get this information is call
getsockname on the SVCXPRT* parameter of the server side transport
handle...

So if svc_req *rqstp is the server side transport handle, I call
getsockname on the socket defined by rqstp->rq_xprt->xp_sock in order
to find the port and ip the RPC packet was sent to on machine B.
Unfortunately, the resulting sock_addr structure gives me an IP of
zero, and a rather interesting port...

Is there a better way of doing this?  Please bear with me, as I'm
rather new at all this socket based stuff:(

 
 
 

Determining which ip address and port an inbound packet was sent to

Post by Barry Margoli » Sat, 12 Jul 2003 06:22:47




>Hello,

>For various reasons, I need to be able to determine the ip address and
>port that an RPC request was sent to (though trivial on a machine with
>just one network card, if a RPC request is sent to a multi-homed
>machine, then determining which network interface received the request
>becomes a bit harder, I think.)

>So machine A sends say a RPC read request to machine B.  Machine B
>gets the request and wishes to determine which network interface
>received the request.  What I do now, to get this information is call
>getsockname on the SVCXPRT* parameter of the server side transport
>handle...

>So if svc_req *rqstp is the server side transport handle, I call
>getsockname on the socket defined by rqstp->rq_xprt->xp_sock in order
>to find the port and ip the RPC packet was sent to on machine B.
>Unfortunately, the resulting sock_addr structure gives me an IP of
>zero, and a rather interesting port...

That means the socket will accept packets for any of the system's
addresses.

What you have to do is create a separate socket for each interface, and
bind it to the address of that interface.  Then use select() or poll() to
listen for incoming packets on all of them at once.

Another solution might be to use TCP rather than UDP.  This will cause a
new socket to be created for each client connection, and its local address
will be the address they connected to.

--

Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. how a packet calls the loopback driver..when i send with same host ip address...

Hi,
      I am sending through same ipaddress of my machine ( using
ping..).
Here my doubt is the ethernet driver is internally calls ( by seeing
the destination address from the ping..is same of the interface of the
host)
loopback driver.... or it goes upto NIC and through some mechanism in
NIC,
it puts back to RX from TX buffer, and from there to ethernet driver
and
then to IP stack and finally it recognises as ICMP echo and ping
succeeds..

Which one is correct......I am trying to go through the ne.c and
8390.c
and loopback.c, but you help can provide me in faster learning...

thanks,
srinivas.
http://nagasrinivasv.reach.at

2. XFIG: EPS export problem

3. Determining IP address from MAC address

4. debian 1.2 install: where is an root image to find?

5. How to determine a mac address on a remote computer with only ip address known?

6. looking for X (esp Xlib) development info

7. SPAK(Send PAcKets)- tools to send arbitrary packets

8. Use of machine name

9. How do you determine IP:port that caused an ICMP port unreachable?

10. Determining IP:port corresponding to an ICMP port unreachable

11. Send IP traffic to own IP address over first router/gateway

12. specifying a port number to a network address/ip address

13. sending packets from alias address