Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7938313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:46:31+00:00 2026-06-03T22:46:31+00:00

I’ve been writing C code for quite some time but am very new to

  • 0

I’ve been writing C code for quite some time but am very new to Objective-C and OO program design. I am having trouble wrapping my head around how to design my program and it’s classes — my standby procedural programming paradigm of passing an opaque pointer to everything just won’t die a quiet death. I am writing a simple program in Xcode4 in Objective-C and I have some questions on design and convention. I’ve designed two classes “PacketCapture” and “IPGeo”. The first is a light wrapper around libpcap with some added parsing logic and the second is a light wrapper around MaxMind’s GeoIP C API. In my main module, I instantiate the PacketCapture class and pass control to the packet capture loop:

int main(int argc, const char *argv[])
{
    @autoreleasepool
    {
        PacketCapture *_PacketCapture = [[PacketCapture alloc] init:"en1" withFilter:""];
        if (_PacketCapture == nil)
        {
            NSLog(@"Can't instantiate PacketCapture class");
            return (-1);
        }
        IPGeo *_IPGeo = [[IPGeo alloc] init:"/usr/local/share/GeoIP/GeoIPCity.dat"];
        if (_IPGeo == nil)
        {
            NSLog(@"Can't instantiate IPGeo class");
            return (-1);
        }

        NSLog(@"entering packet loop...");
        [_PacketCapture packetCapture];
    }
    return (0);
}

Inside of the packetCapture method a parsing function is called that chops up the packet and displays it. I need to use the GeoIP logic down inside the parsing code to lookup the IP addresses against the geo database. Therein lies my problem and general confusion.

My questions:

  • Where should I instantiate the GeoIP class?

  • Is having an infinite loop inside an object in a class bad OO design? Feels like it could be. Perhaps if I restructure this problem will be easily solved?

Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:46:33+00:00Added an answer on June 3, 2026 at 10:46 pm

    Where should I instantiate the GeoIP class?

    If PacketCapture requires an IPGeo object to function, I would recommend instantiating it within PacketCapture‘s -init method. If you need to configure the IPGeo object (by passing a different path when initialized, for example) before using it in PacketCapture, and the path to use is determined in a way PacketCapture shouldn’t be aware of, have the class responsible for managing the two (or, in your case, the main loop of the program) create an instance and pass it as an argument to a custom initializer method on the PacketCapture class.

    A bit of nitpicking–your initializer for IPGeo doesn’t follow Objective-C conventions for expressive method names. -initWithPathToDatabase: would look a lot better in my opinion.

    In a similar vein, you can add a -initWithIPGeo: method to your PacketCapture class.

    Is having an infinite loop inside an object in a class bad OO design?

    If this is an iOS or Cocoa application, then definitely yes. If it’s a command line tool, then maybe. Furthermore, if that infinite loop is being run on the main thread, it will block all UI elements, which will make your program look unresponsive.

    A better alternative would be to use the protocol/delegate pattern, a staple of Objective-C programs. Create a protocol with something like the following method:

    - (void)packetCapture:(PacketCapture *)packetCapture didReceiveDataFromIPAddress:(NSString *)ipAddress;
    

    Then create a delegate object that implements this protocol and performs an action on receiving the packets. If you’re making a command line tool, you can instantiate that delegate and wait to receive messages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.