From owner-freebsd-questions@FreeBSD.ORG Mon Dec 4 13:12:18 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E0C7516A416 for ; Mon, 4 Dec 2006 13:12:18 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7AE5443CB5 for ; Mon, 4 Dec 2006 13:11:34 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (host5.bedc.ondsl.gr [62.103.39.229]) (authenticated bits=128) by igloo.linux.gr (8.13.8/8.13.8/Debian-2) with ESMTP id kB4DBWd3029223 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 4 Dec 2006 15:11:38 +0200 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.13.8/8.13.8) with ESMTP id kB4DBPgf003649 for ; Mon, 4 Dec 2006 15:11:25 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.13.8/8.13.8/Submit) id kB4DBPRf003637 for freebsd-questions@freebsd.org; Mon, 4 Dec 2006 15:11:25 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Date: Mon, 4 Dec 2006 15:11:25 +0200 From: Giorgos Keramidas To: freebsd-questions@freebsd.org Message-ID: <20061204131125.GA60955@kobe.laptop> References: <20061204124550.GA1766@host.my.domain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20061204124550.GA1766@host.my.domain> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-3.443, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.76, BAYES_00 -2.60, DNS_FROM_RFC_ABUSE 0.20) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Subject: Re: Is there a standard function for converting IP address to number? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Dec 2006 13:12:19 -0000 On 2006-12-04 14:45, a@zeos.net wrote: > Is there a standard function converting four numbers to one 32-bit > IP address? > > I mean a function like > > f(i, j, k, l) { > return (((((i << 8) | j) << 8) | k) << 8) | l; > } That's not even a complete, usable function, but if you are looking for a 'standard' function as in "part of libc already", the answer is no. Try something like the in_addr_t makeaddr(uint8_t, uint8_t, uint8_t, uint8_t); function from this sample program: http://people.freebsd.org/~keramida/files/addr.tar.gz which looks like this: #include #include #include "addr.h" in_addr_t makeaddr(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { return (htonl(((in_addr_t)a << 24) + ((in_addr_t)b << 16) + ((in_addr_t)c << 8) + (in_addr_t)d)); }