BUG: smfp.c does not handle RDW correctly

General discussion of the Co:Z Toolkit
Post Reply
DavidCrayford
Posts: 6
Joined: Sun Jul 06, 2008 11:14 pm

BUG: smfp.c does not handle RDW correctly

Post by DavidCrayford »

Unless my understanding of SMF records is incorrect, I think your example SMF program smfp.c has a bug. The RDW length is a halfword which includes the length of the RDW itself.

I've patched it for you (not tested!)...

Code: Select all

uint32_t getrdw() {
	struct {
		uint16_t length; // record length (including RDW)
		uint16_t zz;     // reserved 
	} rdw;

	ssize_t bytes_read = readfully(0, &rdw, sizeof rdw);
	if (bytes_read == 0) {
		return 0;
	}
	if (bytes_read == -1) {
		fprintf(stderr, "Error reading RDW: (%d)%s\n", errno, strerror(errno));
		exit(1);
	}
	return ntohs(rdw.length) - sizeof rdw; // record length adjusted for RDW
}
coz
Posts: 391
Joined: Fri Jul 30, 2004 5:29 pm

Post by coz »

The Co:Z example JCL that drives this code specifies the -rdw switch, which is a 4 byte length. So, the provided smfp.c sample code will work properly (see http://www.dovetail.com/docs/coz/cookbook.html#4_5).

However, you can get your version to work if you specify the -ibmrdw option on the fromdsn call, which will give you the IBM style RDWs.

Code: Select all

//RUNCOZ EXEC PROC=COZPROC,ARGS='user@linux1.myco.com'
//SMFUNLD  DD   DSN=&&SMFUNLD,DISP=(OLD,DELETE,DELETE) 
//STDIN    DD   * 
fromdsn -b -l ibmrdw //DD:SMFUNLD | smfp
//
DavidCrayford
Posts: 6
Joined: Sun Jul 06, 2008 11:14 pm

Post by DavidCrayford »

Thanks steve, now I understand. I like the design, it simplifies a tricky header. I think you should mention -ibmrdw on the cookbook page to
avoid any more confusion.

When fiddling about with well known protocols you have to be a LOT more specfic in your docs...
coz
Posts: 391
Joined: Fri Jul 30, 2004 5:29 pm

Post by coz »

David,

Good suggestion - we'll update our documentation to more specifically call out these differences.

Thanks for your feedback,
--Steve
Post Reply