sockets - Distinguishing between 'destination of udp packet unreachable' and 'received packet with payload of length 0' in Objective C -


currently, when send udp packet unreachable destination (e.g. unbound local port), event can't seem distinguish receiving zero-length udp packet.

i creating socket this:

cfsocketcontext socketcontext = { 0, (__bridge void *)self, cfretain, cfrelease, null }; socket = cfsocketcreate(kcfallocatordefault, pf_inet, sock_dgram, ipproto_udp, kcfsocketdatacallback, (cfsocketcallback)onreceiveddata, &socketcontext); nsdata* localendpointdata = [[ipendpoint ipendpointatunspecifiedaddressonport:specifiedlocalport] sockaddrdata]; cfsocketsetaddress(socket, (__bridge cfdataref)localendpointdata); cfsocketconnecttoaddress(socket, (__bridge cfdataref)[remoteendpoint sockaddrdata], -1); 

and receiving events so:

void onreceiveddata(cfsocketref socket, cfsocketcallbacktype type, cfdataref address, const void *data, void *info) {     if(type == kcfsocketdatacallback && cfdatagetlength((cfdataref)data) == 0) {         nslog("received empty packet");     } } 

if there socket listening @ specifiedlocalport things work properly. sending data triggers no received events, receiving data triggers received event. if there's no socket listening @ specifiedlocalport, sending data triggers received event claiming empty udp packet received.

am doing stupid, cause behaviour? how can distinguish 'destination unreachable' 'destination sent empty udp packet'?


Comments