Date: Tue, 12 Dec 2000 00:39:54 -0700 From: Wes Peters <wes@softweyr.com> To: Michael Yeung <micyeung1@yahoo.com> Cc: net@FreeBSD.ORG Subject: Re: IP aliases and TCP socket Message-ID: <3A35D64A.D85D863C@softweyr.com> References: <20001211191746.25563.qmail@web4903.mail.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Michael Yeung wrote: > > Hi, > I have a few of questions and would greatly > appreciate for some advise. > > 1) What I want to do is to create an application that > can receive packets destined to two IP addresses from > different subnet/network. Essentially have a host > sitting at the broader of two networks. I noticed IP > aliases restrict the alias IP address to be in the > same subnet/network as the primary IP address. Is > that a true restriction? If so, any advise on > alternative to IP alias? Use two physical interfaces? You have two different networks on the same wire? Ugh. > 2) Assume IP aliases works for my needs as stated in > question1. When I send a packet out over a TCP socket > connection, how can I specify which address to be used > as the source IP address (i.e. primary or alias > address)? By specifying the IP address that you bind the socket to. In other words, you need to completely fill in the AF_INET sockaddr in the bind call, rather than allowing the default all-zeroes address, which means "take any old address that fits." > 3) Assume I can use IP aliases technique to receive > packet destined to different IP addresses in the same > application. If I am to use a TCP socket to retrieve > the packet, how can I tell which IP address what the > packet destined to (i.e. the primary or alias > address)? Would packets for all addresses goes to the > same socket or would it be through multiple sockets? You would want to open a socket per address, by specifying the address as I outline above. You will know the packet was destined for the address you bound the socket to, or it wouldn't arrive on that socket. > 4) Is there direct API calls to the TCP/UDP for > connection creation, sending and receiving? Or do I > have to go thru the socket interface. Are they > tcp_open, udp_open, tcp_send, udp_send, tcp_receive > and udp_receive? Where can I find these APIs and > their function prototypes? I have no idea what tcp_* and udp_* are. The direct API calls ARE the sockets interface. In particular, see the following man pages: socket(2), bind(2), getsockname(2), getpeername(2), listen(2), accept(2), read(2), write(2), send(2), recv(2) and a good book on UNIX network programming. "UNIX Network Programming, Volume 1: Networking APIs" by W. Richard Stevens ISBN: 013490012X would be the canonical choice. (My copy of Stevens is so old it came in ONE volume. We're going to miss him when it comes time to teach people IPv6 programming from the ground up. Sigh. RIP WRS.) -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC wes@softweyr.com http://softweyr.com/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3A35D64A.D85D863C>