• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
callback access to a Global
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

callback access to a Global


  • Subject: callback access to a Global
  • From: Dalton Hamilton <email@hidden>
  • Date: Wed, 5 Apr 2006 14:26:06 +0200

Hello -
I'm running across the wierdiest problem.  I'm converting resolving a Bonjour discovered name to get it's IP address and when this works fine.  However, I need to save the IP address so I'm trying to copy it to a global variable.  When I'm in the callback, I do the strcpy and then follow it up with a printf to verify the copy is done and all shows fine.  However, as soon as I exit the callback, the global is still got the defaul value of "0.0.0.0".  I have other callbacks which access globals.  Why can't I copy this data into a globa???
Below is a small piece of code that shows the global and the callback C function.
Thanks
Dalton Hamilton
============================
// Global defined here
char service_ipaddress[256]="0.0.0.0";

static void
MyResolveCallback(CFNetServiceRef service, CFStreamError* error, void* info)
{
NSAutoreleasePool      *pool = [[NSAutoreleasePool alloc] init];

struct sockaddr *socketAddress;
CFArrayRef addresses;
uint16_t port;
int count;
char buffer[256];


addresses = CFNetServiceGetAddressing(service);


/* Search for the IPv4 addresses in the array. */
for (count = 0; count < CFArrayGetCount(addresses); count++) {


socketAddress = (struct sockaddr *)CFDataGetBytePtr(CFArrayGetValueAtIndex(addresses, count));


/* Only continue if this is an IPv4 address. */
if (socketAddress && socketAddress->sa_family == AF_INET) {


if (inet_ntop(AF_INET, &((struct sockaddr_in *)socketAddress)->sin_addr, buffer, sizeof(buffer))) 
{


port = ntohs(((struct sockaddr_in *)socketAddress)->sin_port);

strcpy(service_ipaddress,buffer);


printf("[buffer] IP Address = %s\n", buffer);
printf("Port Number = %d\n", port);
printf("[ip] IP Address = %s\n", service_ipaddress);


/* Now that you know the IP address and port number, you
should attempt to connect to the service. If the connection
succeeds, then cancel the Resolve operation. If the connection
fails, keep the Resolve running just in case your Resolve
    callback gets called again with another IPv4 address, and then
try connecting to the new address. */
}
}
}
[pool release];
return;
}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Slow launch of Mail.app and Safari, [NSHost currentHost],
  • Next by Date: callback access to Global (take 2) Answered
  • Previous by thread: Re: Slow launch of Mail.app and Safari, [NSHost currentHost],
  • Next by thread: callback access to Global (take 2) Answered
  • Index(es):
    • Date
    • Thread