From owner-freebsd-net Mon Dec 11 23:39:25 2000 From owner-freebsd-net@FreeBSD.ORG Mon Dec 11 23:39:22 2000 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from homer.softweyr.com (bsdconspiracy.net [208.187.122.220]) by hub.freebsd.org (Postfix) with ESMTP id 389CF37B400 for ; Mon, 11 Dec 2000 23:36:11 -0800 (PST) Received: from [127.0.0.1] (helo=softweyr.com ident=Fools trust ident!) by homer.softweyr.com with esmtp (Exim 3.16 #1) id 145k2V-0000FX-00; Tue, 12 Dec 2000 00:39:55 -0700 Sender: wes@FreeBSD.ORG Message-ID: <3A35D64A.D85D863C@softweyr.com> Date: Tue, 12 Dec 2000 00:39:54 -0700 From: Wes Peters Organization: Softweyr LLC X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.12 i386) X-Accept-Language: en MIME-Version: 1.0 To: Michael Yeung Cc: net@FreeBSD.ORG Subject: Re: IP aliases and TCP socket References: <20001211191746.25563.qmail@web4903.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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