1753321 Members
6666 Online
108792 Solutions
New Discussion юеВ

Re: help in C

 
SAMI AHMAD
Regular Advisor

Re: help in C

one thing more ..is iam not intersted in printf..that is just for diagnosis. my need is to construct this string dynamically
(the part marked with ^^^)

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\" \"msg\"";
^^^
SAMI AHMAD
Regular Advisor

Re: help in C

to make things even simpler

#include
#include

main()
{
char *cmd ="write sys$output msg";
printf( " cmd: >%s<.\n", cmd);
}

SUNNY2$ xx :== $sys$login:x.exe
SUNNY2$ xx
cmd: >write sys$output msg<.

I want to be able to do this

main( argument)
{
char *cmd ="write sys$output printf( " cmd: >%s<.\n", cmd);
}

SUNNY2$ xx :== $sys$login:x.exe
SUNNY2$ xx "test msg"
cmd: >write sys$output test msg<.



SAMI AHMAD
Regular Advisor

Re: help in C

ok I found the solution :

#include
#include

int main(int argc, char *argv[])
{
int sts;
char msg;

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\" \"*msg\"";

printf("program: %s\n",argv[1]);
/* printf( " cmd: >%s<.\n", cmd); */
sts = system( cmd);

printf( " sts = %%x%08x.\n", sts);
}


SUNNY2$ sndsnmp testing
program: testing
sts = %x00000001.

but I cant replace the 'msg' with the argument passed .. any ideas ?
Hoff
Honored Contributor

Re: help in C

Use sprintf(). That's the formatted string conversion routine; it looks and works very much like the C printf() call, but dumps the results into a string buffer. Your command-level string would be a parameter passed into the sprintf() here.
SAMI AHMAD
Regular Advisor

Re: help in C

but Hoff I dont need to print anything i need to assign like below

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\" \"*msg\"";
^^^^

how can i do this by sprintf ?
RBrown_1
Trusted Contributor
Joseph Huber_1
Honored Contributor

Re: help in C

Sami, do You mean something like this ?

tsprintf.c:

#include stdio
int main(int argc, char *argv[]) {
char cmd[256];
sprintf(cmd,"mcr sys$system:tcpip$snmp_trapsnd.exe"\
" 0.0 local 0 0 0 -h %s v2c"\
"1.3.6.1.6.3.1.1.4.1.0 \"D\" \"*msg\"",argv[1]);

printf(" %s\n",cmd); /show result*/

}

Test the program:
$ mcr []tsprintf 10.1.222.1
mcr sys$system:tcpip$snmp_trapsnd.exe 0.0 local 0 0 0 -h 10.1.222.1 v2c1.3.6.1.
6.3.1.1.4.1.0 "D" "*msg"


http://www.mpp.mpg.de/~huber
Steven Schweda
Honored Contributor

Re: help in C

Boy, this is painful to watch.

> Sami, do You mean something like this ?

Probably more like this:

alp $ type snmp2.c
#include
#include

int main( int argc, char **argv)
{
int sts;
char cmd[ 1024];

sprintf( cmd, "mcr tcpip$snmp_trapsnd.exe\
1.3.6.1.6.3.1.1.4.1.0 local 0 0 0 -v2c -h 10.100.10.112 \"D\" \"%s\"",
argv[ 1]);

printf( " cmd: >%s<.\n", cmd);
sts = system( cmd);

printf( " sts = %%x%08x.\n", sts);
}

alp $ cc snmp2
alp $ link snmp2
alp $ mcr []snmp2 "my message text"
cmd: >mcr tcpip$snmp_trapsnd.exe 1.3.6.1.6.3.1.1.4.1.0 local 0 0 0 -v2c -h 10.1
00.10.112 "D" "my message text"<.
Invalid variable name OID syntax: D
Invalid variable list.
#snmp_trapsnd enterprise agent-address generic specific timeticks
[-v version] [-c community] [-h host] [-p port] [-tcp] {variable [type value]}
sts = %x00000001.
alp $

Looks as if the command itself may need a
little work.

The 'D' must be '"D"' to keep it upper-case
when snmp_trapsnd sees it.

Note that no one is checking to see if you
really have a command-line argument (argc >
1), so it'll behave badly if you don't
specify one.
Joseph Huber_1
Honored Contributor

Re: help in C

I know nothing about the snmp... command syntax, the question was how to use sprintf to replace a part by commandline arguments, and Sami
marked 10.100.18.245 by ^^^^, so I assumed this IP address should be the variable argument.
http://www.mpp.mpg.de/~huber
Jon Pinkley
Honored Contributor

Re: help in C

ITRC forum wrapping makes it appear that it is pointing to ip address, but it is really pointing at the "char".

Cut and paste into (for example notepad), and you will see.

But what does this whole topic have to do with VMS?

Sami, if you need to learn C, this isn't the place to learn.

See Hoff's response to your question about snmp traps.

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1325393
it depends