kmdent
kmdent

Reputation: 1587

OSX equivalent for IP_RECVERR

I'm trying to port a TraceRoute program from Linux to OSX, and i'm having trouble finding the IP_RECVERR equivalent.

The way most people do the packet parsing is:

setsockopt (sock, IPPROTO_IPV4, IP_RECVERR, &on, sizeof (on))

And then when the packet comes in do something along the lines of:

sock_extended_err* err = nullptr;
for (cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
  switch (cmsg->cmsg_level) {
    case IPPROTO_IPV4:
      if (cmsg->cmsg_type == IP_RECVERR) {
        err = (sock_extended_err*)CSMSG_DATA(cmsg);
      }
      break;
  }
}

There also isn't an sock_extended_err on OSX which is problematic. I really just need to know if have had an error, and where the error originated.

Upvotes: 11

Views: 1087

Answers (1)

Brijesh Valera
Brijesh Valera

Reputation: 1117

Sorry to say but OS X is not supporting extended IP_RECVERR socket capabilities.

You can use: #ifdef IP_RECVERRto make it build on OS X where RECVERR/ERRQUEUE don't exist.

But if you are looking for that particular code execution, I think you have to port IP_RECVERR socket capability & MSG_ERRQUEUE in mac OS X. Thats sound like "I got new things to play". Happy coding.

Upvotes: 1

Related Questions