Re: How to get UDP destination address on incoming packets
From: Michael Fuhr (mfuhr_at_fuhr.org)
Date: 11/17/03
- Next message: Nils O. Selåsdal: "Re: Linux and Threads"
- Previous message: Erik Max Francis: "Re: libg++ vs libstdc++"
- In reply to: Coleman Brumley: "Re: How to get UDP destination address on incoming packets"
- Next in thread: Coleman Brumley: "Re: How to get UDP destination address on incoming packets"
- Reply: Coleman Brumley: "Re: How to get UDP destination address on incoming packets"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Nov 2003 22:51:14 -0700
coleman.brumley@aamatrix.com (Coleman Brumley) writes:
> mfuhr@fuhr.org (Michael Fuhr) wrote in message news:<3fb7be41$1_2@omega.dimensional.com>...
>
> > for (cmsgptr = CMSG_FIRSTHDR(&msg);
> > cmsgptr != NULL;
> > cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) {
> >
> > if (cmsgptr->cmsg_level == IPPROTO_IP &&
> > cmsgptr->cmsg_type == DSTADDR_SOCKOPT) {
> >
> > printf("destination: %s\n", inet_ntoa(*dstaddr(cmsgptr)));
> > }
> > }
>
> Ok, after looking at the man pages for cmsg and recvmsg, I can see how
> to get to this information via the msghdr structure. I'm guessing
> that I can just PEEK at the incoming mesg using recvmsg and then do
> the cmsg/dstaddr thing from above?
You could use MSG_PEEK if you don't want to read the data yet, or
you could read the data and do whatever you want with it.
> Is there anything special I have to do to the socket for this to work?
> I'm opening the socket using:
> sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
> ...
> bind(sock_fd, ...);
>
> I would also guess that I'll need to do setsockopt(DSTADDR_SOCKOPT)?
Yep, with a level of IPPROTO_IP.
-- Michael Fuhr http://www.fuhr.org/~mfuhr/
- Next message: Nils O. Selåsdal: "Re: Linux and Threads"
- Previous message: Erik Max Francis: "Re: libg++ vs libstdc++"
- In reply to: Coleman Brumley: "Re: How to get UDP destination address on incoming packets"
- Next in thread: Coleman Brumley: "Re: How to get UDP destination address on incoming packets"
- Reply: Coleman Brumley: "Re: How to get UDP destination address on incoming packets"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|