11

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.

kmdent
  • 1,577
  • 16
  • 32
  • On `OS X` the closest thing (that is built-in) would likely be `SO_ERROR`. – l'L'l May 01 '15 at 10:38
  • It doesn't look like it has a "TTL got to 0" error. – kmdent May 01 '15 at 20:08
  • When you're using `IP_RECVERR` what type of value does it return? If you want to get the actual `TTL` value you'll have to use something like `getsockopt(fd, SOL_SOCKET, SO_ERROR, &errcode, &len);` – l'L'l May 01 '15 at 21:27
  • Well, if you get a `IP_RECVERR`, you get the `sock_extended_err` struct, which you can then do things like `err->ee_origin == SO_EE_ORIGIN_ICMP` to see if the error came from the final destination. – kmdent May 01 '15 at 23:03
  • I don't think there's a direct C equivalent in Mac OS X. There might be something in the Mac-specific (or Objective-C) APIs, but I'm not sure of that. – Jonathan Leffler May 02 '15 at 05:27
  • I'll do the manual packet parsing and post the answer here for the next poor soul. – kmdent May 06 '15 at 20:49

1 Answers1

1

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.

Brijesh Valera
  • 1,085
  • 2
  • 9
  • 30