No such process (3) when not connected to a network (AF_ROUTE)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

up vote
2
down vote

favorite

When I am connected to a network, I can send a struct rt_msghdr* to the kernel and receive a corresponding route. However, when I disconnect from the network and try to send the same route message header, the socket fails at send() with errno = ESRCH (3) No such process.

Generic code: (Testing on MacOS)

int sd = create_socket(AF_ROUTE, IPPROTO_RAW, AF_UNSPEC);

memset(&buffer[0], 0, buffer.size());
struct rt_msghdr* rmh = (struct rt_msghdr*)(&buffer[0]);
rmh->rtm_msglen       = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in);
rmh->rtm_version      = RTM_VERSION;
rmh->rtm_type         = RTM_GET;
rmh->rtm_addrs        = RTA_DST;
rmh->rtm_pid          = getpid();
rmh->rtm_seq          = 1;
struct sockaddr_in* sa_in = (struct sockaddr_in*)(rmh + 1);
sa_in->sin_len            = sizeof(struct sockaddr_in);
sa_in->sin_family         = AF_INET;

int status;
if ((status = send(sd, rmh, rmh->rtm_msglen, 0) < 0) {
    // process errno
    // * issue happens here when not connected to a network
}

// receive kernel response(s)
// process responses

close(sd);

I verified that the process ID (pid) is being set correctly in the header. netstat -nr returns the default route without issue when not connected to a network. I’m having trouble understanding why this code is dependent on network connectivity.

share|improve this question

  • Don’t have a Mac OS X box to test on, but I’m somewhat surprised netstat shows a default route w/o a network — I’d expect there not to be one (and that the error you’re getting means as much). Curious what netstat gives as the default route.
    – derobert
    Nov 29 at 20:51

  • @derobert That’s reassuring to hear! These are the results of netstat on OSX without a network connection default - fe80::%utun0 - UGcI - utun0 in the format “Destination, Gateway, Flags, Netif Expire”
    – TekuConcept
    Nov 29 at 21:08

  • fe80:: is an IPv6 address, but you’re asking for IPv4 (AF_INET). So probably you’d get that if you asked for AF_INET6 (and changed to sockaddr_in6, etc.).
    – derobert
    Nov 29 at 21:13

  • [BTW: You’ll probably find much more knowledge about programming the OSX/BSD APIs on Stack Overflow — you should consider asking there, presuming of course someone else hasn’t already asked. ]
    – derobert
    Nov 29 at 21:38

  • Okay, I updated my code to try for the IPv6 route if the IPv4 route failed. Still no luck. 🙁 I was about to ask on SO, but figured this was more specific to BSD. I’ll ask there and see what I can dig up.
    – TekuConcept
    Nov 29 at 21:43

up vote
2
down vote

favorite

When I am connected to a network, I can send a struct rt_msghdr* to the kernel and receive a corresponding route. However, when I disconnect from the network and try to send the same route message header, the socket fails at send() with errno = ESRCH (3) No such process.

Generic code: (Testing on MacOS)

int sd = create_socket(AF_ROUTE, IPPROTO_RAW, AF_UNSPEC);

memset(&buffer[0], 0, buffer.size());
struct rt_msghdr* rmh = (struct rt_msghdr*)(&buffer[0]);
rmh->rtm_msglen       = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in);
rmh->rtm_version      = RTM_VERSION;
rmh->rtm_type         = RTM_GET;
rmh->rtm_addrs        = RTA_DST;
rmh->rtm_pid          = getpid();
rmh->rtm_seq          = 1;
struct sockaddr_in* sa_in = (struct sockaddr_in*)(rmh + 1);
sa_in->sin_len            = sizeof(struct sockaddr_in);
sa_in->sin_family         = AF_INET;

int status;
if ((status = send(sd, rmh, rmh->rtm_msglen, 0) < 0) {
    // process errno
    // * issue happens here when not connected to a network
}

// receive kernel response(s)
// process responses

close(sd);

I verified that the process ID (pid) is being set correctly in the header. netstat -nr returns the default route without issue when not connected to a network. I’m having trouble understanding why this code is dependent on network connectivity.

share|improve this question

  • Don’t have a Mac OS X box to test on, but I’m somewhat surprised netstat shows a default route w/o a network — I’d expect there not to be one (and that the error you’re getting means as much). Curious what netstat gives as the default route.
    – derobert
    Nov 29 at 20:51

  • @derobert That’s reassuring to hear! These are the results of netstat on OSX without a network connection default - fe80::%utun0 - UGcI - utun0 in the format “Destination, Gateway, Flags, Netif Expire”
    – TekuConcept
    Nov 29 at 21:08

  • fe80:: is an IPv6 address, but you’re asking for IPv4 (AF_INET). So probably you’d get that if you asked for AF_INET6 (and changed to sockaddr_in6, etc.).
    – derobert
    Nov 29 at 21:13

  • [BTW: You’ll probably find much more knowledge about programming the OSX/BSD APIs on Stack Overflow — you should consider asking there, presuming of course someone else hasn’t already asked. ]
    – derobert
    Nov 29 at 21:38

  • Okay, I updated my code to try for the IPv6 route if the IPv4 route failed. Still no luck. 🙁 I was about to ask on SO, but figured this was more specific to BSD. I’ll ask there and see what I can dig up.
    – TekuConcept
    Nov 29 at 21:43

up vote
2
down vote

favorite

up vote
2
down vote

favorite

When I am connected to a network, I can send a struct rt_msghdr* to the kernel and receive a corresponding route. However, when I disconnect from the network and try to send the same route message header, the socket fails at send() with errno = ESRCH (3) No such process.

Generic code: (Testing on MacOS)

int sd = create_socket(AF_ROUTE, IPPROTO_RAW, AF_UNSPEC);

memset(&buffer[0], 0, buffer.size());
struct rt_msghdr* rmh = (struct rt_msghdr*)(&buffer[0]);
rmh->rtm_msglen       = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in);
rmh->rtm_version      = RTM_VERSION;
rmh->rtm_type         = RTM_GET;
rmh->rtm_addrs        = RTA_DST;
rmh->rtm_pid          = getpid();
rmh->rtm_seq          = 1;
struct sockaddr_in* sa_in = (struct sockaddr_in*)(rmh + 1);
sa_in->sin_len            = sizeof(struct sockaddr_in);
sa_in->sin_family         = AF_INET;

int status;
if ((status = send(sd, rmh, rmh->rtm_msglen, 0) < 0) {
    // process errno
    // * issue happens here when not connected to a network
}

// receive kernel response(s)
// process responses

close(sd);

I verified that the process ID (pid) is being set correctly in the header. netstat -nr returns the default route without issue when not connected to a network. I’m having trouble understanding why this code is dependent on network connectivity.

share|improve this question

When I am connected to a network, I can send a struct rt_msghdr* to the kernel and receive a corresponding route. However, when I disconnect from the network and try to send the same route message header, the socket fails at send() with errno = ESRCH (3) No such process.

Generic code: (Testing on MacOS)

int sd = create_socket(AF_ROUTE, IPPROTO_RAW, AF_UNSPEC);

memset(&buffer[0], 0, buffer.size());
struct rt_msghdr* rmh = (struct rt_msghdr*)(&buffer[0]);
rmh->rtm_msglen       = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in);
rmh->rtm_version      = RTM_VERSION;
rmh->rtm_type         = RTM_GET;
rmh->rtm_addrs        = RTA_DST;
rmh->rtm_pid          = getpid();
rmh->rtm_seq          = 1;
struct sockaddr_in* sa_in = (struct sockaddr_in*)(rmh + 1);
sa_in->sin_len            = sizeof(struct sockaddr_in);
sa_in->sin_family         = AF_INET;

int status;
if ((status = send(sd, rmh, rmh->rtm_msglen, 0) < 0) {
    // process errno
    // * issue happens here when not connected to a network
}

// receive kernel response(s)
// process responses

close(sd);

I verified that the process ID (pid) is being set correctly in the header. netstat -nr returns the default route without issue when not connected to a network. I’m having trouble understanding why this code is dependent on network connectivity.

networking c route bsd

share|improve this question

share|improve this question

share|improve this question

share|improve this question

asked Nov 29 at 20:34

TekuConcept

1111

1111

  • Don’t have a Mac OS X box to test on, but I’m somewhat surprised netstat shows a default route w/o a network — I’d expect there not to be one (and that the error you’re getting means as much). Curious what netstat gives as the default route.
    – derobert
    Nov 29 at 20:51

  • @derobert That’s reassuring to hear! These are the results of netstat on OSX without a network connection default - fe80::%utun0 - UGcI - utun0 in the format “Destination, Gateway, Flags, Netif Expire”
    – TekuConcept
    Nov 29 at 21:08

  • fe80:: is an IPv6 address, but you’re asking for IPv4 (AF_INET). So probably you’d get that if you asked for AF_INET6 (and changed to sockaddr_in6, etc.).
    – derobert
    Nov 29 at 21:13

  • [BTW: You’ll probably find much more knowledge about programming the OSX/BSD APIs on Stack Overflow — you should consider asking there, presuming of course someone else hasn’t already asked. ]
    – derobert
    Nov 29 at 21:38

  • Okay, I updated my code to try for the IPv6 route if the IPv4 route failed. Still no luck. 🙁 I was about to ask on SO, but figured this was more specific to BSD. I’ll ask there and see what I can dig up.
    – TekuConcept
    Nov 29 at 21:43

  • Don’t have a Mac OS X box to test on, but I’m somewhat surprised netstat shows a default route w/o a network — I’d expect there not to be one (and that the error you’re getting means as much). Curious what netstat gives as the default route.
    – derobert
    Nov 29 at 20:51

  • @derobert That’s reassuring to hear! These are the results of netstat on OSX without a network connection default - fe80::%utun0 - UGcI - utun0 in the format “Destination, Gateway, Flags, Netif Expire”
    – TekuConcept
    Nov 29 at 21:08

  • fe80:: is an IPv6 address, but you’re asking for IPv4 (AF_INET). So probably you’d get that if you asked for AF_INET6 (and changed to sockaddr_in6, etc.).
    – derobert
    Nov 29 at 21:13

  • [BTW: You’ll probably find much more knowledge about programming the OSX/BSD APIs on Stack Overflow — you should consider asking there, presuming of course someone else hasn’t already asked. ]
    – derobert
    Nov 29 at 21:38

  • Okay, I updated my code to try for the IPv6 route if the IPv4 route failed. Still no luck. 🙁 I was about to ask on SO, but figured this was more specific to BSD. I’ll ask there and see what I can dig up.
    – TekuConcept
    Nov 29 at 21:43

Don’t have a Mac OS X box to test on, but I’m somewhat surprised netstat shows a default route w/o a network — I’d expect there not to be one (and that the error you’re getting means as much). Curious what netstat gives as the default route.
– derobert
Nov 29 at 20:51

Don’t have a Mac OS X box to test on, but I’m somewhat surprised netstat shows a default route w/o a network — I’d expect there not to be one (and that the error you’re getting means as much). Curious what netstat gives as the default route.
– derobert
Nov 29 at 20:51

@derobert That’s reassuring to hear! These are the results of netstat on OSX without a network connection default - fe80::%utun0 - UGcI - utun0 in the format “Destination, Gateway, Flags, Netif Expire”
– TekuConcept
Nov 29 at 21:08

@derobert That’s reassuring to hear! These are the results of netstat on OSX without a network connection default - fe80::%utun0 - UGcI - utun0 in the format “Destination, Gateway, Flags, Netif Expire”
– TekuConcept
Nov 29 at 21:08

fe80:: is an IPv6 address, but you’re asking for IPv4 (AF_INET). So probably you’d get that if you asked for AF_INET6 (and changed to sockaddr_in6, etc.).
– derobert
Nov 29 at 21:13

fe80:: is an IPv6 address, but you’re asking for IPv4 (AF_INET). So probably you’d get that if you asked for AF_INET6 (and changed to sockaddr_in6, etc.).
– derobert
Nov 29 at 21:13

[BTW: You’ll probably find much more knowledge about programming the OSX/BSD APIs on Stack Overflow — you should consider asking there, presuming of course someone else hasn’t already asked. ]
– derobert
Nov 29 at 21:38

[BTW: You’ll probably find much more knowledge about programming the OSX/BSD APIs on Stack Overflow — you should consider asking there, presuming of course someone else hasn’t already asked. ]
– derobert
Nov 29 at 21:38

Okay, I updated my code to try for the IPv6 route if the IPv4 route failed. Still no luck. 🙁 I was about to ask on SO, but figured this was more specific to BSD. I’ll ask there and see what I can dig up.
– TekuConcept
Nov 29 at 21:43

Okay, I updated my code to try for the IPv6 route if the IPv4 route failed. Still no luck. 🙁 I was about to ask on SO, but figured this was more specific to BSD. I’ll ask there and see what I can dig up.
– TekuConcept
Nov 29 at 21:43

active

oldest

votes

Your Answer

StackExchange.ready(function() {
var channelOptions = {
tags: “”.split(” “),
id: “106”
};
initTagRenderer(“”.split(” “), “”.split(” “), channelOptions);

StackExchange.using(“externalEditor”, function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using(“snippets”, function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: ‘answer’,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: “”,
imageUploader: {
brandingHtml: “Powered by u003ca class=”icon-imgur-white” href=”https://imgur.com/”u003eu003c/au003e”,
contentPolicyHtml: “User contributions licensed under u003ca href=”https://creativecommons.org/licenses/by-sa/3.0/”u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href=”https://stackoverflow.com/legal/content-policy”u003e(content policy)u003c/au003e”,
allowUrls: true
},
onDemand: true,
discardSelector: “.discard-answer”
,immediatelyShowMarkdownHelp:true
});

}
});

draft saved
draft discarded

StackExchange.ready(
function () {
StackExchange.openid.initPostLogin(‘.new-post-login’, ‘https%3a%2f%2funix.stackexchange.com%2fquestions%2f485015%2fno-such-process-3-when-not-connected-to-a-network-af-route%23new-answer’, ‘question_page’);
}
);

Post as a guest

Required, but never shown

active

oldest

votes

active

oldest

votes

active

oldest

votes

active

oldest

votes

draft saved
draft discarded

Thanks for contributing an answer to Unix & Linux Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

Some of your past answers have not been well-received, and you’re in danger of being blocked from answering.

Please pay close attention to the following guidance:

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

draft saved

draft discarded

StackExchange.ready(
function () {
StackExchange.openid.initPostLogin(‘.new-post-login’, ‘https%3a%2f%2funix.stackexchange.com%2fquestions%2f485015%2fno-such-process-3-when-not-connected-to-a-network-af-route%23new-answer’, ‘question_page’);
}
);

Post as a guest

Required, but never shown

Required, but never shown

Required, but never shown

Required, but never shown

Required, but never shown

Required, but never shown

Required, but never shown

Required, but never shown

Required, but never shown

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *