• 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
Re: Receive UDP broadcast packets with OTRcvUData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Receive UDP broadcast packets with OTRcvUData


  • Subject: Re: Receive UDP broadcast packets with OTRcvUData
  • From: "Matthieu Beghin" <email@hidden>
  • Date: Tue, 9 Nov 2004 15:04:16 +0100

Title: Re: Receive UDP broadcast packets with OTRcvUData
Hi Quinn,
I noticed that using Open Transport on OSX would work for brodcast only if I don't set the socket Synchronous.
My code works fine with Mac OS9, but on Mac OSX if I set my socket synchronous on Mac OSX, I get a T_NOTSUPPORT success code when setting the option IP_BROADCAST_IFADDR. I found no documentation on this option. Can I find any doc about the option somewhere ? With this option on, I can send broadcast packets.
 
Below is the simplest code I could write to reproduce the problem. Just have to change LOCAL_IP / BROADCAST_IP definitions and comment the IS_SYNCHRONE_SOCKET def.
Thanks a lot Quinn
Matthieu Beghin
 
//-----------------------------------------------------------
#include <Carbon/Carbon.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
#define LOCAL_IP  0xC0A8015A
#define BROADCAST_IP 0xC0A801FF
#define IS_SYNCHRONE_SOCKET

static OTResult SetFourByteOption(EndpointRef ep,
 OTXTILevel level,
 OTXTIName name,
 UInt32 value)
{
 OTResult err;
 TOption option;
 TOptMgmt request;
 TOptMgmt result;
 
 option.len = kOTFourByteOptionSize;
 option.level = level;
 option.name = name;
 option.status = 0;
 option.value[0] = value;
 
 request.opt.buf = (UInt8 *) &option;
 request.opt.len = sizeof(option);
 request.flags = T_NEGOTIATE;
 
 result.opt.buf = (UInt8 *) &option;
 result.opt.maxlen = sizeof(option);
 
 err = OTOptionManagement(ep, &request, &result);
 
 if (err == noErr) {
  if (option.status != T_SUCCESS) {
   err = option.status;
  }
 }
 
 return err;
}
 
int main(void)
{
 /***********************************
 whole initialisation
 ***********************************/
 EndpointRef sock;
 long osErr_;
 InetAddress ipAddress;
 
 if((osErr_ = InitOpenTransportInContext(kInitOTForApplicationMask, NULL))!=noErr)
  return -1;
 
 sock = OTOpenEndpointInContext(OTCreateConfiguration(kUDPName), 0,nil,&osErr_, NULL);
 if(osErr_!=noErr || sock == kOTInvalidEndpointRef)
  return -1;
 #ifdef IS_SYNCHRONE_SOCKET
 if((osErr_=OTSetSynchronous(sock))!=noErr)
  return -1;
 #endif

 OTInitInetAddress(&ipAddress, 12345, kOTAnyInetAddress);
 
 osErr_ = SetFourByteOption(sock, INET_IP, IP_REUSEADDR, 1);
 if (osErr_ != noErr)
  return -1;
 
 TBind bindReq;
 OTMemzero(&bindReq, sizeof(bindReq));
 bindReq.addr.buf = (UInt8 *) &ipAddress;
 bindReq.addr.len = sizeof(ipAddress);
 bindReq.qlen = 1;
 
 if((osErr_ = OTBind(sock, &bindReq, nil))!=noErr)
  return -1;
 
 #define IP_BROADCAST_IFADDR 0x1018 /* Set interface addr for broadcasts */
 
 osErr_ = SetFourByteOption(sock, INET_IP, IP_BROADCAST_IFADDR, LOCAL_IP);
 if (osErr_ != noErr)
  return -1;
 
 
 /*****************************
 SendTo
 *****************************/
 TUnitData data;
 InetAddress host;
 char buffer[512];
 
 OTInitInetAddress(&host, 0x1936, BROADCAST_IP);
 data.addr.len = sizeof(host);
 data.addr.buf = (UInt8 *) &host;
 data.opt.len = 0;
 data.opt.buf = NULL;
 data.udata.len = 512;
 data.udata.buf = (UInt8 *)buffer;
 OSStatus status = OTSndUData(sock,&data);
 
 if (status < 0)
  return -1;
 
 return 0;
}
//-----------------------------------------------------------
----- Original Message -----
From: Quinn
To: apple network dev
Sent: Thursday, November 04, 2004 12:09 AM
Subject: Re: Receive UDP broadcast packets with OTRcvUData

At 14:50 +0100 3/11/04, Matthieu Beghin wrote:
I create a Synchrone socket and set it non blockling. It receives broadcast on 2.255.255.255.
Sometimes I have to answer by broadcast and I get the error
kEACCESErr -3212 Permission denied
when calling OTSndUData.

I just tried sending UDP broadcasts under OT on Mac OS X, and it worked as easily as I remember.  I'm not sure what's going on with your code, but you might want to compare it with mine.  I've included my test program at the end of this email.  Try it out on your machine and see what you get.

You should just be able to paste it into an Xcode CoreServices command line tool project.

S+E
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware

 _______________________________________________
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

References: 
 >Re: Receive UDP broadcast packets with OTRcvUData (From: "Matthieu Beghin" <email@hidden>)
 >Re: Receive UDP broadcast packets with OTRcvUData (From: Quinn <email@hidden>)

  • Prev by Date: Re: Receive UDP broadcast packets with OTRcvUData
  • Next by Date: Re: Connecting a client to a tcp server?
  • Previous by thread: Re: Receive UDP broadcast packets with OTRcvUData
  • Next by thread: Character device synchronization with network interface
  • Index(es):
    • Date
    • Thread