|
|
1.1 root 1: /* smbdump.c */
2:
3: /* Synchronet message base (SMB) message header dumper */
4:
1.1.1.2 ! root 5: /* $Id: smbdump.c,v 1.11 2009/03/24 09:33:28 rswindell Exp $ */
1.1 root 6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
1.1.1.2 ! root 11: * Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include <time.h> /* ctime */
39: #include <string.h> /* strcat */
40: #include "smblib.h"
41:
42: static char *binstr(uchar *buf, ushort length)
43: {
44: static char str[512];
45: int i;
46:
47: str[0]=0;
48: for(i=0;i<length;i++)
49: if(buf[i] && (buf[i]<' ' || buf[i]>=0x7f)
50: && buf[i]!='\r' && buf[i]!='\n' && buf[i]!='\t')
51: break;
52: if(i==length) /* not binary */
53: return((char*)buf);
54: for(i=0;i<length;i++) {
1.1.1.2 ! root 55: sprintf(str+strlen(str),"%02X ",buf[i]);
1.1 root 56: if(i>=100) {
57: strcat(str,"...");
58: break;
59: }
60: }
1.1.1.2 ! root 61: truncsp(str);
1.1 root 62: return(str);
63: }
64:
65: void SMBCALL smb_dump_msghdr(FILE* fp, smbmsg_t* msg)
66: {
67: int i;
1.1.1.2 ! root 68: time_t tt;
1.1 root 69:
70: fprintf(fp,"%-20.20s %ld\n" ,"number" ,msg->hdr.number);
71:
72: /* convenience strings */
73: if(msg->subj)
1.1.1.2 ! root 74: fprintf(fp,"%-20.20s \"%s\"\n" ,"subject" ,msg->subj);
1.1 root 75: if(msg->to) {
76: fprintf(fp,"%-20.20s %s" ,"to" ,msg->to);
77: if(msg->to_ext)
78: fprintf(fp," #%s",msg->to_ext);
79: if(msg->to_net.type)
80: fprintf(fp," <%s>",smb_netaddr(&msg->to_net));
81: fprintf(fp,"\n");
82: }
83: if(msg->from) {
1.1.1.2 ! root 84: fprintf(fp,"%-20.20s \"%s\"" ,"from" ,msg->from);
1.1 root 85: if(msg->from_ext)
86: fprintf(fp," #%s",msg->from_ext);
87: if(msg->from_net.type)
88: fprintf(fp," <%s>",smb_netaddr(&msg->from_net));
89: fprintf(fp,"\n");
90: }
91: if(msg->replyto) {
1.1.1.2 ! root 92: fprintf(fp,"%-20.20s \"%s\"" ,"reply-to" ,msg->replyto);
1.1 root 93: if(msg->replyto_ext)
94: fprintf(fp," #%s",msg->replyto_ext);
95: if(msg->replyto_net.type)
96: fprintf(fp," <%s>",smb_netaddr(&msg->replyto_net));
97: fprintf(fp,"\n");
98: }
99: if(msg->summary)
1.1.1.2 ! root 100: fprintf(fp,"%-20.20s \"%s\"\n" ,"summary" ,msg->summary);
1.1 root 101:
102: /* convenience integers */
1.1.1.2 ! root 103: if(msg->expiration) {
! 104: tt=msg->expiration;
1.1 root 105: fprintf(fp,"%-20.20s %.24s\n","expiration"
1.1.1.2 ! root 106: ,ctime(&tt));
! 107: }
1.1 root 108:
109: /* fixed header fields */
1.1.1.2 ! root 110: tt=msg->hdr.when_written.time;
1.1 root 111: fprintf(fp,"%-20.20s %.24s UTC%+d:%02d\n" ,"when_written"
1.1.1.2 ! root 112: ,ctime(&tt)
1.1 root 113: ,smb_tzutc(msg->hdr.when_written.zone)/60
114: ,abs(smb_tzutc(msg->hdr.when_written.zone)%60));
1.1.1.2 ! root 115: tt=msg->hdr.when_imported.time;
1.1 root 116: fprintf(fp,"%-20.20s %.24s UTC%+d:%02d\n" ,"when_imported"
1.1.1.2 ! root 117: ,ctime(&tt)
1.1 root 118: ,smb_tzutc(msg->hdr.when_imported.zone)/60
119: ,abs(smb_tzutc(msg->hdr.when_imported.zone)%60));
120: fprintf(fp,"%-20.20s %04Xh\n" ,"type" ,msg->hdr.type);
121: fprintf(fp,"%-20.20s %04Xh\n" ,"version" ,msg->hdr.version);
122: fprintf(fp,"%-20.20s %04Xh\n" ,"attr" ,msg->hdr.attr);
123: fprintf(fp,"%-20.20s %08lXh\n" ,"auxattr" ,msg->hdr.auxattr);
124: fprintf(fp,"%-20.20s %08lXh\n" ,"netattr" ,msg->hdr.netattr);
125:
126: /* optional fixed fields */
127: if(msg->hdr.thread_back)
128: fprintf(fp,"%-20.20s %ld\n" ,"thread_back" ,msg->hdr.thread_back);
129: if(msg->hdr.thread_next)
130: fprintf(fp,"%-20.20s %ld\n" ,"thread_next" ,msg->hdr.thread_next);
131: if(msg->hdr.thread_first)
132: fprintf(fp,"%-20.20s %ld\n" ,"thread_first" ,msg->hdr.thread_first);
133: if(msg->hdr.delivery_attempts)
134: fprintf(fp,"%-20.20s %hu\n" ,"delivery_attempts",msg->hdr.delivery_attempts);
135: if(msg->hdr.times_downloaded)
136: fprintf(fp,"%-20.20s %lu\n" ,"times_downloaded" ,msg->hdr.times_downloaded);
1.1.1.2 ! root 137: if(msg->hdr.last_downloaded) {
! 138: tt=msg->hdr.last_downloaded;
! 139: fprintf(fp,"%-20.20s %.24s\n" ,"last_downloaded" ,ctime(&tt));
! 140: }
1.1 root 141:
142: fprintf(fp,"%-20.20s %06lXh\n" ,"header offset" ,msg->idx.offset);
143: fprintf(fp,"%-20.20s %u\n" ,"header length" ,msg->hdr.length);
144: fprintf(fp,"%-20.20s %lu\n" ,"calculated length",smb_getmsghdrlen(msg));
145:
146: /* variable fields */
147: for(i=0;i<msg->total_hfields;i++)
1.1.1.2 ! root 148: fprintf(fp,"%-20.20s \"%s\"\n"
1.1 root 149: ,smb_hfieldtype(msg->hfield[i].type)
150: ,binstr((uchar *)msg->hfield_dat[i],msg->hfield[i].length));
151:
152: /* data fields */
153: fprintf(fp,"%-20.20s %06lXh\n" ,"data offset" ,msg->hdr.offset);
154: for(i=0;i<msg->hdr.total_dfields;i++)
155: fprintf(fp,"data field[%u] %s, offset %lu, length %lu\n"
156: ,i
157: ,smb_dfieldtype(msg->dfield[i].type)
158: ,msg->dfield[i].offset
159: ,msg->dfield[i].length);
160: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.