LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-21-2006, 06:02 PM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
C: manage IP addresses


Hi,

Is there an easy way to manage ip addresses? I need to store an ip address and work with increasements on it (ie 192.168.0.255 becomes 192.168.1.0). I would like to avoid the struggle of storing it as char and work with each character individually when increasing it.

Thanks.
 
Old 07-21-2006, 06:19 PM   #2
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
So an IPv4 address is 4 bytes. You can store that in a 32-bit integer, in big-endian order; then you can just increment the integer as you like.
 
Old 07-22-2006, 11:47 AM   #3
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Ok, but how do I store them in big-endian order?

Last edited by Ephracis; 07-22-2006 at 01:11 PM.
 
Old 07-22-2006, 01:18 PM   #4
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Never mind, this worked:
target.s_addr = htonl(ntohl(target.s_addr)+1);
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do YOU manage software? zetabill Slackware 48 07-02-2007 11:08 PM
manage x window stockerz Solaris / OpenSolaris 6 07-17-2005 10:41 AM
How to manage this problem ? sixth_sense Linux - Networking 5 05-03-2005 09:19 AM
How to manage encryption? Ephracis Linux - Wireless Networking 3 04-01-2005 03:45 AM
how to manage network ? tintin Linux - Networking 6 11-26-2002 12:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration