Annotation of sbbs/src/smblib/smbdump.c, revision 1.1.1.1

1.1       root        1: /* smbdump.c */
                      2: 
                      3: /* Synchronet message base (SMB) message header dumper */
                      4: 
                      5: /* $Id: smbdump.c,v 1.7 2005/10/19 18:24:45 rswindell Exp $ */
                      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:  *                                                                                                                                                     *
                     11:  * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html         *
                     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:        char tmp[128];
                     46:        int i;
                     47: 
                     48:        str[0]=0;
                     49:        for(i=0;i<length;i++)
                     50:                if(buf[i] && (buf[i]<' ' || buf[i]>=0x7f) 
                     51:                        && buf[i]!='\r' && buf[i]!='\n' && buf[i]!='\t')
                     52:                        break;
                     53:        if(i==length)           /* not binary */
                     54:                return((char*)buf);
                     55:        for(i=0;i<length;i++) {
                     56:                sprintf(tmp,"%02X ",buf[i]);
                     57:                strcat(str,tmp); 
                     58:                if(i>=100) {
                     59:                        strcat(str,"...");
                     60:                        break;
                     61:                }
                     62:        }
                     63:        return(str);
                     64: }
                     65: 
                     66: void SMBCALL smb_dump_msghdr(FILE* fp, smbmsg_t* msg)
                     67: {
                     68:        int i;
                     69: 
                     70:        fprintf(fp,"%-20.20s %ld\n"             ,"number"                       ,msg->hdr.number);
                     71: 
                     72:        /* convenience strings */
                     73:        if(msg->subj)
                     74:                fprintf(fp,"%-20.20s %s\n"      ,"subject"                      ,msg->subj);
                     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) {
                     84:                fprintf(fp,"%-20.20s %s"        ,"from"                         ,msg->from);
                     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) {
                     92:                fprintf(fp,"%-20.20s %s"        ,"reply-to"                     ,msg->replyto);
                     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)
                    100:                fprintf(fp,"%-20.20s %s\n"      ,"summary"                      ,msg->summary);
                    101: 
                    102:        /* convenience integers */
                    103:        if(msg->expiration)
                    104:                fprintf(fp,"%-20.20s %.24s\n","expiration"      
                    105:                        ,ctime((time_t *)&msg->expiration));
                    106: 
                    107:        /* fixed header fields */
                    108:        fprintf(fp,"%-20.20s %.24s  UTC%+d:%02d\n"      ,"when_written" 
                    109:                ,ctime((time_t *)&msg->hdr.when_written.time)   
                    110:                ,smb_tzutc(msg->hdr.when_written.zone)/60
                    111:                ,abs(smb_tzutc(msg->hdr.when_written.zone)%60));
                    112:        fprintf(fp,"%-20.20s %.24s  UTC%+d:%02d\n"      ,"when_imported"        
                    113:                ,ctime((time_t *)&msg->hdr.when_imported.time)  
                    114:                ,smb_tzutc(msg->hdr.when_imported.zone)/60
                    115:                ,abs(smb_tzutc(msg->hdr.when_imported.zone)%60));
                    116:        fprintf(fp,"%-20.20s %04Xh\n"   ,"type"                         ,msg->hdr.type);
                    117:        fprintf(fp,"%-20.20s %04Xh\n"   ,"version"                      ,msg->hdr.version);
                    118:        fprintf(fp,"%-20.20s %04Xh\n"   ,"attr"                         ,msg->hdr.attr);
                    119:        fprintf(fp,"%-20.20s %08lXh\n"  ,"auxattr"                      ,msg->hdr.auxattr);
                    120:        fprintf(fp,"%-20.20s %08lXh\n"  ,"netattr"                      ,msg->hdr.netattr);
                    121: 
                    122:        /* optional fixed fields */
                    123:        if(msg->hdr.thread_back)
                    124:                fprintf(fp,"%-20.20s %ld\n"     ,"thread_back"          ,msg->hdr.thread_back);
                    125:        if(msg->hdr.thread_next)
                    126:                fprintf(fp,"%-20.20s %ld\n"     ,"thread_next"          ,msg->hdr.thread_next);
                    127:        if(msg->hdr.thread_first)
                    128:                fprintf(fp,"%-20.20s %ld\n"     ,"thread_first"         ,msg->hdr.thread_first);
                    129:        if(msg->hdr.delivery_attempts)
                    130:                fprintf(fp,"%-20.20s %hu\n"     ,"delivery_attempts",msg->hdr.delivery_attempts);
                    131:        if(msg->hdr.times_downloaded)
                    132:                fprintf(fp,"%-20.20s %lu\n"     ,"times_downloaded"     ,msg->hdr.times_downloaded);
                    133:        if(msg->hdr.last_downloaded)
                    134:                fprintf(fp,"%-20.20s %.24s\n"   ,"last_downloaded"      ,ctime((time_t*)&msg->hdr.last_downloaded));
                    135: 
                    136:        fprintf(fp,"%-20.20s %06lXh\n"  ,"header offset"        ,msg->idx.offset);
                    137:        fprintf(fp,"%-20.20s %u\n"              ,"header length"        ,msg->hdr.length);
                    138:        fprintf(fp,"%-20.20s %lu\n"             ,"calculated length",smb_getmsghdrlen(msg));
                    139: 
                    140:        /* variable fields */
                    141:        for(i=0;i<msg->total_hfields;i++)
                    142:                fprintf(fp,"%-20.20s %s\n"
                    143:                        ,smb_hfieldtype(msg->hfield[i].type)
                    144:                        ,binstr((uchar *)msg->hfield_dat[i],msg->hfield[i].length));
                    145: 
                    146:        /* data fields */
                    147:        fprintf(fp,"%-20.20s %06lXh\n"  ,"data offset"          ,msg->hdr.offset);
                    148:        for(i=0;i<msg->hdr.total_dfields;i++)
                    149:                fprintf(fp,"data field[%u]        %s, offset %lu, length %lu\n"
                    150:                        ,i
                    151:                        ,smb_dfieldtype(msg->dfield[i].type)
                    152:                        ,msg->dfield[i].offset
                    153:                        ,msg->dfield[i].length);
                    154: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.