Re: getting all interface addresses in the system
Re: getting all interface addresses in the system
- Subject: Re: getting all interface addresses in the system
- From: Josh Graessley <email@hidden>
- Date: Wed, 7 Sep 2005 16:23:13 -0700
On Sep 6, 2005, at 11:43 PM, Herry Wiputra wrote:
Josh,
Thanks. That seems to do the trick.
What do you normally expect in sin_port and sin_zero field of
sockaddr_in?
Are they normally just zeros?
I would expect sin_zero to be zero. sin_port would be the UDP or TCP
port number where appropriate. In the case of a sockaddr_in
representing an address on an interface, the port number is not
appropriate and it's value is undefined (should be zero).
I got another question for you.
soreceive used to return the sockaddress of the packet it receives
from.
However, the sock_receive KPI doesn't.
It does. Read the documentation again. You can specify a buffer the
source will be copied in to when you fill out the msghdr. For more
information on how to fill out the msghdr, look up recvmsg.
I could use sock_getpeername if the connection is TCP but
unfortunately,
the connection is UDP and I can't see any easy way of getting the
address of the sender.
Do you have any idea how? or is this just a limitation in the KPI?
Read up on recvmsg to learn how to use sock_receive:
The recvmsg() call uses a msghdr structure to minimize the
number of
directly supplied parameters. This structure has the following
form, as
defined in <sys/socket.h>:
struct msghdr {
caddr_t msg_name; /* optional address */
socklen_t msg_namelen; /* size of address */
struct iovec *msg_iov; /* scatter/gather array */
u_int msg_iovlen; /* # elements in
msg_iov */
caddr_t msg_control; /* ancillary data, see
below */
socklen_t msg_controllen; /* ancillary data
buffer len */
int msg_flags; /* flags on received
message */
};
Here msg_name and msg_namelen specify the source address if the
socket is
unconnected; msg_name may be given as a null pointer if no
names are
desired or required. Msg_iov and msg_iovlen describe scatter
gather
locations, as discussed in read(2). Msg_control, which has length
msg_controllen, points to a buffer for other protocol control
related
messages or other miscellaneous ancillary data.
-josh
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden