Thread: Hello and help!

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    4

    Smile Hello and help!

    Firstly hello all!

    I am writing an audit tool for a pet project to pass away the boredom at work (and so in future I just run the program and save hours of work)

    What I am trying to do is read in an IP address and then based on the subnet mask do calculations on the correct octect

    e.g. 192.168.2.60 with a 23 bit mask I would start my calculations on the 3rd octect (2).

    What I want to do is this. Let the user input the address and then read each octect into seperate integer values so that

    int1=192
    int2=168

    etc.

    The intial variable is a string but how do I scan for each of the elements. I would suspect the best way would be to search for the first to scan until the . then after the . for the next 3. Can anyone show me how to do this please?

    The code I have works but only if the user inputs the last octect (thus limiting me to calculations on 24 to 32 bit masks)

    Any help greatly appreciated. By the way I am using a gcc compiler so I can port over to any gcc platform.

    Stig

  2. #2
    Sayeh
    Guest
    Can you say 'delimiter'?

  3. #3
    Unregistered
    Guest
    Yes. Or a simple switching routine could do the trick. Hint: Encountering a '.' is your cue to copy...

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Hmm... maybe this example program will help...
    Code:
    #include <stdio.h>
    
    int main ()
    {
     int i;
     int o1, o2, o3, o4;
     i = scanf ("%d.%d.%d.%d", &o1, &o2, &o3, &o4);
     printf ("You entered %d octets.\n", i);
     return 0;
    }
    I'm not sure of exactly what you want, but this seems like it might have the answer.
    Callou collei we'll code the way
    Of prime numbers and pings!

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    4
    thanks guys

    Question, I tried something similar a while back but the gcc didnt like it, I prob missed something so will try yours. Will keep you posted on progress

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    4
    GRRRRRRRrrrrrrrrrrrrrrrrr guess who looked back at old code, found the obvious mistake!

    Cheers Q, that worked a bloody treat!

Popular pages Recent additions subscribe to a feed