String (hostname) to unique integer.

This is a discussion on String (hostname) to unique integer. within the C Programming forums, part of the General Programming Boards category; Hey All, I need to convert a string (hostname) to an unique integer, much like how inet_addr(ip) converts the ip ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    16

    Thumbs up String (hostname) to unique integer.

    Hey All,

    I need to convert a string (hostname) to an unique integer, much like how inet_addr(ip) converts the ip address to an integer.

    I was looking at some related posts and I am sure there has got to be a simpler, cleaner solution. Any suggestions?

    Thanks!

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Why on earth would you want to do that?

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Quote Originally Posted by looza View Post
    Hey All,

    I need to convert a string (hostname) to an unique integer, much like how inet_addr(ip) converts the ip address to an integer.

    I was looking at some related posts and I am sure there has got to be a simpler, cleaner solution. Any suggestions?

    Thanks!
    Convert the hostname to an IP address, then convert the IP address to an integer.
    bit∙hub [bit-huhb] n. A source and destination for information.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    16
    Because I can have several hosts and I need to identify requests coming from each of them, so every request will have a unique id, based on what host it is coming from. This unique id will be used to classify the requests, etc. The unique id has got to be int, because I am using a library function which requires an integer as the unique parameter to do classify stuff..

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Why don't you just use the IP address?

    Each machine's IP is guaranteed to be unique on any network segment... host names are not.

    Very nicely you can harvest this directly from the received packets if you use recvfrom()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting a string with an integer
    By ominub in forum C Programming
    Replies: 3
    Last Post: 12-05-2009, 04:08 AM
  2. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  3. Custom String class gives problem with another prog.
    By I BLcK I in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2006, 02:40 AM
  4. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2003, 11:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21