Thursday, February 27, 2014

jni layer calls socket (AF_INET, SOCK_DGRAM, 0) failed


Such as the title,

Java application layer sequence I wrote a CAN bus for the upper JNI library calls.

Since the kernel is the underlying driver can apply socketcan architecture, so JNI library which is suitable for linux socket programming to call the driver.

I found the call socket (AF_INET, SOCK_DGRAM, 0) failed JNI library inside, the return value is 0xffffffff.

Will the heroes who have not encountered a similar problem? Give some advice?<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
This root socket does not matter, it is estimated sokcet after receiving the results of the command processing returns wrong
Reply:
cited a floor guoyoulei520 reply:
this root socket does not matter, it is estimated sokcet after receiving the results of the command processing returns wrong


Then why, "after receiving the results of the command processing returns sokcet wrong"?
Reply:
reference to the second floor suck666 reply:
Quote: references to a floor guoyoulei520 reply:

This root socket does not matter, it is estimated sokcet after receiving the results of the command processing returns wrong


Then why, "after receiving the results of the command processing returns sokcet wrong"?


In this way, you would first make sure that the entire call flow is correct socket
Then you look at the socket receive command processing piece is correct.
Reply:
reference to the third floor guoyoulei520 reply:
Quote: references to the second floor suck666 reply:

Quote: references to a floor guoyoulei520 reply:

This root socket does not matter, it is estimated sokcet after receiving the results of the command processing returns wrong


Then why, "after receiving the results of the command processing returns sokcet wrong"?


In this way, you would first make sure that the entire call flow is correct socket
Then you look at the socket after receiving the command processing piece is correct.


I was the top JNI code, socket is linux standard API, I do not need to manage socket inside to achieve it?

Anyway, I run the "socket (AF_INET, SOCK_DGRAM, 0)" should not fail, right?


Reply:
references, 4th Floor suck666 reply:
Quote: references to the third floor guoyoulei520 reply:

Quote: references to the second floor suck666 reply:

Quote: references to a floor guoyoulei520 reply:

This root socket does not matter, it is estimated sokcet after receiving the results of the command processing returns wrong


Then why, "after receiving the results of the command processing returns sokcet wrong"?


In this way, you would first make sure that the entire call flow is correct socket
Then you look at the socket after receiving the command processing piece is correct.


I was the top JNI code, socket is linux standard API, I do not need to manage socket inside to achieve it?

Anyway, I run the "socket (AF_INET, SOCK_DGRAM, 0)" should not fail, right?



Ah, it should not fail, I think adb shell and jni tune inside a big difference there is the adb shell with root privileges ...

Other I do not know your code, so it is not very clear.
Reply:
references, 5th Floor guoyoulei520 reply:
Quote: references to the 4th floor suck666 reply:

Quote: references to the third floor guoyoulei520 reply:

Quote: references to the second floor suck666 reply:

Quote: references to a floor guoyoulei520 reply:

This root socket does not matter, it is estimated sokcet after receiving the results of the command processing returns wrong


Then why, "after receiving the results of the command processing returns sokcet wrong"?


In this way, you would first make sure that the entire call flow is correct socket
Then you look at the socket after receiving the command processing piece is correct.


I was the top JNI code, socket is linux standard API, I do not need to manage socket inside to achieve it?

Anyway, I run the "socket (AF_INET, SOCK_DGRAM, 0)" should not fail, right?



Ah, it should not fail, I think adb shell and jni tune inside a big difference there is the adb shell with root privileges ...

Other I do not know your code, so it is not very clear.


Is not right, like a long time, not your code, do not know what the problem
Reply:
reference to the 6th floor guoyoulei520 reply:
Quote: references, 5th Floor guoyoulei520 reply:

Quote: references to the 4th floor suck666 reply:

Quote: references to the third floor guoyoulei520 reply:

Quote: references to the second floor suck666 reply:

Quote: references to a floor guoyoulei520 reply:

This root socket does not matter, it is estimated sokcet after receiving the results of the command processing returns wrong


Then why, "after receiving the results of the command processing returns sokcet wrong"?


In this way, you would first make sure that the entire call flow is correct socket
Then you look at the socket after receiving the command processing piece is correct.


I was the top JNI code, socket is linux standard API, I do not need to manage socket inside to achieve it?

Anyway, I run the "socket (AF_INET, SOCK_DGRAM, 0)" should not fail, right?



Ah, it should not fail, I think adb shell and jni tune inside a big difference there is the adb shell with root privileges ...

Other I do not know your code, so it is not very clear.


Is not right, like a long time, not your code, do not know what the problem


How to pass the code you see? You have mail?

Reply:

unsigned int if_nametoindex (const char * ifname)
{
int index;
int ctl_sock;
struct ifreq ifr;

memset (& ifr, 0, sizeof (struct ifreq));
strncpy (ifr.ifr_name, ifname, IFNAMSIZ);
ifr.ifr_name [IFNAMSIZ - 1] = 0;

index = 0;
if ((ctl_sock = socket (AF_INET, SOCK_DGRAM, 0))> = 0) {
if (ioctl (ctl_sock, SIOCGIFINDEX, & ifr)> = 0) {
index = ifr.ifr_ifindex;
}
close (ctl_sock);
}
return index;
}


static int do_set_nl_link (int fd, __ u8 if_state, const char * name,
struct req_info * req_info)
{
struct set_req req;

const char * type = "can";

memset (& req, 0, sizeof (req));

req.n.nlmsg_len = NLMSG_LENGTH (sizeof (struct ifinfomsg));
req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
req.n.nlmsg_type = RTM_NEWLINK;
req.i.ifi_family = 0;

fprintf (stdout, "1if_nametoindex% s \ n", name);
req.i.ifi_index = if_nametoindex (name);
/ / Req.i.ifi_index = devicesindex;
fprintf (stdout, "22245if_nametoindex% s% d \ n", name, req.i.ifi_index);
if (req.i.ifi_index == 0) {
fprintf (stderr, "Cannot find device \"% s \ "\ n", name);
return -1;
}

if (if_state) {
switch (if_state) {
case IF_DOWN:
req.i.ifi_change | = IFF_UP;
req.i.ifi_flags & = ~ IFF_UP;
break;
case IF_UP:
req.i.ifi_change | = IFF_UP;
req.i.ifi_flags | = IFF_UP;
break;
default:
fprintf (stderr, "unknown state \ n");
return -1;
}
}

if (req_info! = NULL) {
/ * Setup linkinfo section * /
struct rtattr * linkinfo = NLMSG_TAIL (& req.n);
addattr_l (& req.n, sizeof (req), IFLA_LINKINFO, NULL, 0);
addattr_l (& req.n, sizeof (req), IFLA_INFO_KIND, type,
strlen (type));
/ * Setup data section * /
struct rtattr * data = NLMSG_TAIL (& req.n);
addattr_l (& req.n, sizeof (req), IFLA_INFO_DATA, NULL, 0);

if (req_info-> restart_ms> 0 | | req_info-> disable_autorestart)
addattr32 (& req.n, 1024, IFLA_CAN_RESTART_MS,
req_info-> restart_ms);

if (req_info-> restart)
addattr32 (& req.n, 1024, IFLA_CAN_RESTART, 1);

if (req_info-> bittiming! = NULL) {
addattr_l (& req.n, 1024, IFLA_CAN_BITTIMING,
req_info-> bittiming,
sizeof (struct can_bittiming));
}

if (req_info-> ctrlmode! = NULL) {
addattr_l (& req.n, 1024, IFLA_CAN_CTRLMODE,
req_info-> ctrlmode,
sizeof (struct can_ctrlmode));
}

/ * Mark end of data section * /
data-> rta_len = (void *) NLMSG_TAIL (& req.n) - (void *) data;

/ * Mark end of link info section * /
linkinfo-> rta_len =
(Void *) NLMSG_TAIL (& req.n) - (void *) linkinfo;
}

return send_mod_request (fd, & req.n);
}

Reply:
cited landlord suck666 reply:
such as title,

Java application layer sequence I wrote a CAN bus for the upper JNI library calls.

Since the kernel is the underlying driver can apply socketcan architecture, so JNI library which is suitable for linux socket programming to call the driver.

I found the call socket (AF_INET, SOCK_DGRAM, 0) failed JNI library inside, the return value is 0xffffffff.

Will the heroes who have not encountered a similar problem? Give some advice?


You run adb shell in which it is a bin file, you now to transform this into a bin jni call is not successful and you have a system source code of it.
I think you do not reform, made init.rc inside the bin file services, in jni start this service by ctrl.start in this way, with you in the adb shell which is the same effect.
Reply:
reference to the 9th floor guoyoulei520 reply:
Quote: references landlord suck666 reply:

Such as the title,

Java application layer sequence I wrote a CAN bus for the upper JNI library calls.

Since the kernel is the underlying driver can apply socketcan architecture, so JNI library which is suitable for linux socket programming to call the driver.

I found the call socket (AF_INET, SOCK_DGRAM, 0) failed JNI library inside, the return value is 0xffffffff.

Will the heroes who have not encountered a similar problem? Give some advice?


You run adb shell in which it is a bin file, you now to transform this into a bin jni call is not successful and you have a system source code of it.
I think you do not reform, made init.rc inside the bin file services, in jni start this service by ctrl.start in this way, with you in the adb shell which is the same effect.


Your analysis is right. My bin file to run properly.
Thank you for your suggestion. But I want to do it yourself JAVA UI's. How my java application data to be sent and received from the CAN bus data to the JAVA code?
Reply:
I know the answer to that question is a permissions issue.

When I call the JNI library java program which added, , socket (AF_INET, SOCK_DGRAM, 0) to run successful

AndroidManifest.xml


package = "com.samkoon.can"
android: versionCode = "1"
android: versionName = "1.0"
android: sharedUserId = "android.uid.system">





android: minSdkVersion = "8"
android: targetSdkVersion = "16" />

android: allowBackup = "true"
android: icon = "@ drawable / ic_launcher"
android: label = "@ string / app_name"
android: theme = "@ style / AppTheme">
Reply:

Reply:
The landlord, ask you a question
rc = ioctl (sockfd, SIOCSARP, & req);
I tried to set the arp binding android found above this function is always executed unsuccessful, the landlord can help analyze it?

No comments:

Post a Comment