- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- calling C from java
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 09:12 AM
тАО04-06-2009 09:12 AM
Re: calling C from java
i wouldnt love to make the current method work as this would open ways of interfacing.
but can you point me to a sample code using such snmp trap java calls?
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 10:05 AM
тАО04-06-2009 10:05 AM
Re: calling C from java
http://www.google.com/search?q=java+send+snmp+trap
I'm sure this could be further refined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 10:13 AM
тАО04-06-2009 10:13 AM
Re: calling C from java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 10:15 AM
тАО04-06-2009 10:15 AM
Re: calling C from java
I changed the code to use Getstringchars but I am still getting the same problem, string is not being translated..
SUNNY2$ TYPE sndsnmp_c.c;
#include "SYSTEMCALL.H"
#include
#include
#include
#define size 512
static char cmdbuffer[size];
/* main(int argc, char **argv ) */
JNIEXPORT jint JNICALL Java_SYSTEMCALL_SNMPTRAP
(JNIEnv *env, jobject obj , jstring msg) {
int i;
int sts;
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\"";
jboolean *iscopy;
jstring ret;
jint len;
const jchar *fmt;
fmt = (*env)->GetStringChars(env, msg, iscopy);
len = (*env)->GetStringLength(env, msg);
ret = (*env)->NewString(env, fmt,len);
printf("%s","now in C routine");
printf("%s", ret);
return 0;
}
SUNNY2$ java "SYSTEMCALL"
Warning: JIT compiler "SUNCOMPILER" not found. Will use interpreter.
This is java ..calling the C routing
now in C routineh├В┬▓Ux├В┬▓U├Г `U├о┬д┬╗U0l├Е┬╕z;l├Е┬╕z6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 11:12 AM
тАО04-06-2009 11:12 AM
Re: calling C from java
jboolean *iscopy=0;
jstring ret;
jint len;
const jchar *fmt; << it wont lt me use
jstring here .
fmt = (*env)->GetStringChars(env, msg, iscopy);
len = (*env)->GetStringLength(env, msg);
printf("%d\n", len);
printf("%s\n","now in C routine");
printf("%s", fmt);
SUNNY2$ java "SYSTEMCALL"
Warning: JIT compiler "SUNCOMPILER" not found. Will use interpreter.
This is java ..calling the C routing
18 <<<<< correct string length
now in C routine
N <<<<< only the first char of msg string
which is 'NEW TEST TRAP MSGS'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 12:29 PM
тАО04-06-2009 12:29 PM
Re: calling C from java
N <<<<< only the first char of msg string
<<<<<<<<<<<
I know nothing about this but I think you should run this in the debugger to see what fmt really looks like. Are these wide characters?
>>>>>>>>>>>
printf("%s", fmt);
<<<<<<<<<<<
Why no '\n' here?
GetStringLength told you the length was 18. But if the length is only 18, there may not be a terminating NULL in the string.
Seeing what the program is doing from the inside will be really useful to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 12:34 PM
тАО04-06-2009 12:34 PM
Re: calling C from java
it seems I was too sure about everything. GetStringChars returns a Unicode string. If the string contains Latin-1 characters, every second byte will be zero. That's why you only see the first character of your string.
The correct function is indeed GetStringUTFChars. That one returns a const char* that you can use in a C program (without resorting to wchar_t etc.)
Sorry for causing confusion.
cu,
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 12:34 PM
тАО04-06-2009 12:34 PM
Re: calling C from java
here is the java program thats sending the string, how do I null terminate the string? :
SUNNY2$ TYPE SND_SNMP.JAVA
class SYSTEMCALL {
public native int SNMPTRAP (String msg);
static {
System.loadLibrary("SNDSNMP_C");
}
public static void main (String[] args) {
System.out.println("This is java ..calling the C routing");
int result = new SYSTEMCALL().SNMPTRAP("NEW TEST TRAP MSGS");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 12:35 PM
тАО04-06-2009 12:35 PM
Re: calling C from java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2009 01:03 PM
тАО04-06-2009 01:03 PM
Re: calling C from java
Thanks everyone for your support .
JNIEXPORT jint JNICALL Java_SYSTEMCALL_SNMPTRAP
(JNIEnv *env, jobject obj , jstring msg) {
int i;
int sts;
char *cmd = "mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.100.18.245 -v2c 1.3.6.1.6.3.1.1.4.1.0 \"D\"";
const char *tmp = (*env)->GetStringUTFChars(env,msg,0);
char retstring[512];
strcpy(retstring,tmp);
printf("%s\n","now in C routine");
printf("%s\n", retstring);
(*env)->ReleaseStringUTFChars(env, msg, tmp);
fflush(stdout);
$ java "SYSTEMCALL"
Warning: JIT compiler "SUNCOMPILER" not found. Will use interpreter.
This is java ..calling the C routing
now in C routine
NEW TEST TRAP MSGS
- « Previous
- Next »