/* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean _5views_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err) { _5views_dump_t *_5views = (_5views_dump_t *)wdh->priv; t_5VW_TimeStamped_Header HeaderFrame; /* Frame Header */ /* constant fields */ HeaderFrame.Key = htolel(CST_5VW_RECORDS_HEADER_KEY); HeaderFrame.HeaderSize = htoles(sizeof(t_5VW_TimeStamped_Header)); HeaderFrame.HeaderType = htoles(CST_5VW_TIMESTAMPED_HEADER_TYPE); HeaderFrame.RecType = htolel(CST_5VW_CAPTURES_RECORD | CST_5VW_SYSTEM_RECORD); HeaderFrame.RecSubType = htolel(CST_5VW_FRAME_RECORD); HeaderFrame.RecNb = htolel(1); /* record-dependent fields */ HeaderFrame.Utc = htolel(phdr->ts.secs); HeaderFrame.NanoSecondes = htolel(phdr->ts.nsecs); HeaderFrame.RecSize = htolel(phdr->len); HeaderFrame.RecInfo = htolel(0); /* write the record header */ if (!wtap_dump_file_write(wdh, &HeaderFrame, sizeof(t_5VW_TimeStamped_Header), err)) return FALSE; /* write the data */ if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) return FALSE; _5views->nframes ++; return TRUE; }
static gboolean _5views_dump_close(wtap_dumper *wdh, int *err) { _5views_dump_t *_5views = (_5views_dump_t *)wdh->priv; t_5VW_Capture_Header file_hdr; if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1) return FALSE; /* fill in the Info_Header */ file_hdr.Info_Header.Signature = htolel(CST_5VW_INFO_HEADER_KEY); file_hdr.Info_Header.Size = htolel(sizeof(t_5VW_Info_Header)); /* Total size of Header in bytes (included Signature) */ file_hdr.Info_Header.Version = htolel(CST_5VW_INFO_RECORD_VERSION); /* Identify version and so the format of this record */ file_hdr.Info_Header.DataSize = htolel(sizeof(t_5VW_Attributes_Header) + sizeof(guint32) + sizeof(t_5VW_Attributes_Header) + sizeof(guint32)); /* Total size of data included in the Info Record (except the header size) */ file_hdr.Info_Header.FileType = htolel(wtap_encap[wdh->encap]); /* Type of the file */ file_hdr.Info_Header.Reserved[0] = 0; /* Reserved for future use */ file_hdr.Info_Header.Reserved[1] = 0; /* Reserved for future use */ file_hdr.Info_Header.Reserved[2] = 0; /* Reserved for future use */ /* fill in the HeaderDateCreation */ file_hdr.HeaderDateCreation.Type = htolel(CST_5VW_IA_DATE_CREATION); /* Id of the attribute */ file_hdr.HeaderDateCreation.Size = htoles(sizeof(guint32)); /* Size of the data part of the attribute (not including header size) */ file_hdr.HeaderDateCreation.Nb = htoles(1); /* Number of elements */ /* fill in the Time field */ #ifdef _WIN32 _tzset(); #endif file_hdr.Time = htolel(time(NULL)); /* fill in the Time field */ file_hdr.HeaderNbFrames.Type = htolel(CST_5VW_IA_CAP_INF_NB_TRAMES_STOCKEES); /* Id of the attribute */ file_hdr.HeaderNbFrames.Size = htoles(sizeof(guint32)); /* Size of the data part of the attribute (not including header size) */ file_hdr.HeaderNbFrames.Nb = htoles(1); /* Number of elements */ /* fill in the number of frames saved */ file_hdr.TramesStockeesInFile = htolel(_5views->nframes); /* Write the file header. */ if (!wtap_dump_file_write(wdh, &file_hdr, sizeof(t_5VW_Capture_Header), err)) return FALSE; return TRUE; }
static int mb_put_acl(mbchain_t *mbp, i_ntacl_t *acl) { i_ntace_t **acep; uint16_t acl_len, *acl_len_p; int i, cnt0, error; cnt0 = mbp->mb_count; ERRCHK(mb_put_uint8(mbp, acl->acl_revision)); ERRCHK(mb_put_uint8(mbp, 0)); /* pad1 */ acl_len_p = mb_reserve(mbp, sizeof (*acl_len_p)); if (acl_len_p == NULL) { error = ENOMEM; goto errout; } ERRCHK(mb_put_uint16le(mbp, acl->acl_acecount)); ERRCHK(mb_put_uint16le(mbp, 0)); /* pad2 */ acep = &acl->acl_acevec[0]; for (i = 0; i < acl->acl_acecount; i++) { ERRCHK(mb_put_ace(mbp, *acep)); acep++; } /* Fill in acl_len_p */ acl_len = mbp->mb_count - cnt0; *acl_len_p = htoles(acl_len); /* Success! */ return (0); errout: return (error); }
void smb_strtouni(u_int16_t *dst, const char *src) { while (*src) { *dst++ = htoles(*src++); } *dst = 0; }
static int mb_put_ace(mbchain_t *mbp, i_ntace_t *ace) { int cnt0, error; uint16_t ace_len, *ace_len_p; if (ace == NULL) return (EINVAL); cnt0 = mbp->mb_count; /* * Put the (fixed-size) ACE header * Will fill in the length later. */ ERRCHK(mb_put_uint8(mbp, ace->ace_hdr.ace_type)); ERRCHK(mb_put_uint8(mbp, ace->ace_hdr.ace_flags)); ace_len_p = mb_reserve(mbp, sizeof (*ace_len_p)); if (ace_len_p == NULL) { error = ENOMEM; goto errout; } switch (ace->ace_hdr.ace_type) { case ACCESS_ALLOWED_ACE_TYPE: case ACCESS_DENIED_ACE_TYPE: case SYSTEM_AUDIT_ACE_TYPE: case SYSTEM_ALARM_ACE_TYPE: /* Put type-specific data. */ ERRCHK(mb_put_uint32le(mbp, ace->ace_v2.ace_rights)); ERRCHK(mb_put_sid(mbp, ace->ace_v2.ace_sid)); break; /* other types todo */ default: error = EIO; goto errout; } /* Fill in the (OtW) ACE length. */ ace_len = mbp->mb_count - cnt0; *ace_len_p = htoles(ace_len); /* Success! */ return (0); errout: return (error); }
/* Finish writing to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean netmon_dump_close(wtap_dumper *wdh, int *err) { netmon_dump_t *netmon = (netmon_dump_t *)wdh->priv; size_t n_to_write; struct netmon_hdr file_hdr; const char *magicp; size_t magic_size; struct tm *tm; /* Write out the frame table. "netmon->frame_table_index" is the number of entries we've put into it. */ n_to_write = netmon->frame_table_index * sizeof *netmon->frame_table; if (!wtap_dump_file_write(wdh, netmon->frame_table, n_to_write, err)) return FALSE; /* Now go fix up the file header. */ fseek(wdh->fh, 0, SEEK_SET); memset(&file_hdr, '\0', sizeof file_hdr); switch (wdh->file_type) { case WTAP_FILE_NETMON_1_x: magicp = netmon_1_x_magic; magic_size = sizeof netmon_1_x_magic; /* NetMon file version, for 1.x, is 1.1 */ file_hdr.ver_major = 1; file_hdr.ver_minor = 1; break; case WTAP_FILE_NETMON_2_x: magicp = netmon_2_x_magic; magic_size = sizeof netmon_2_x_magic; /* * NetMon file version, for 2.x, is 2.0; * for 3.0, it's 2.1. * * If the file encapsulation is WTAP_ENCAP_PER_PACKET, * we need version 2.1. * * XXX - version 2.3 supports UTC time stamps; when * should we use it? According to the file format * documentation, NetMon 3.3 "cannot properly * interpret" the UTC timestamp information; does * that mean it ignores it and uses the local-time * start time and time deltas, or mishandles them? * Also, NetMon 3.1 and earlier can't read version * 2.2, much less version 2.3. */ file_hdr.ver_major = 2; file_hdr.ver_minor = (wdh->encap == WTAP_ENCAP_PER_PACKET) ? 1 : 0; break; default: /* We should never get here - our open routine should only get called for the types above. */ if (err != NULL) *err = WTAP_ERR_UNSUPPORTED_FILE_TYPE; return FALSE; } if (!wtap_dump_file_write(wdh, magicp, magic_size, err)) return FALSE; if (wdh->encap == WTAP_ENCAP_PER_PACKET) { /* * We're writing NetMon 2.1 format, so the media * type in the file header is irrelevant. Set it * to 1, just as Network Monitor does. */ file_hdr.network = htoles(1); } else file_hdr.network = htoles(wtap_encap[wdh->encap]); tm = localtime(&netmon->first_record_time.secs); if (tm != NULL) { file_hdr.ts_year = htoles(1900 + tm->tm_year); file_hdr.ts_month = htoles(tm->tm_mon + 1); file_hdr.ts_dow = htoles(tm->tm_wday); file_hdr.ts_day = htoles(tm->tm_mday); file_hdr.ts_hour = htoles(tm->tm_hour); file_hdr.ts_min = htoles(tm->tm_min); file_hdr.ts_sec = htoles(tm->tm_sec); } else { file_hdr.ts_year = htoles(1900 + 0); file_hdr.ts_month = htoles(0 + 1); file_hdr.ts_dow = htoles(0); file_hdr.ts_day = htoles(0); file_hdr.ts_hour = htoles(0); file_hdr.ts_min = htoles(0); file_hdr.ts_sec = htoles(0); } file_hdr.ts_msec = htoles(netmon->first_record_time.nsecs/1000000); file_hdr.frametableoffset = htolel(netmon->frame_table_offset); file_hdr.frametablelength = htolel(netmon->frame_table_index * sizeof *netmon->frame_table); if (!wtap_dump_file_write(wdh, &file_hdr, sizeof file_hdr, err)) return FALSE; return TRUE; }
/* Write a record for a packet to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const union wtap_pseudo_header *pseudo_header, const guint8 *pd, int *err) { netmon_dump_t *netmon = (netmon_dump_t *)wdh->priv; struct netmonrec_1_x_hdr rec_1_x_hdr; struct netmonrec_2_x_hdr rec_2_x_hdr; void *hdrp; size_t rec_size; struct netmonrec_2_1_trlr rec_2_x_trlr; size_t hdr_size; struct netmon_atm_hdr atm_hdr; int atm_hdrsize; gint64 secs; gint32 nsecs; if (wdh->encap == WTAP_ENCAP_PER_PACKET) { /* * Is this network type supported? */ if (phdr->pkt_encap < 0 || (unsigned) phdr->pkt_encap >= NUM_WTAP_ENCAPS || wtap_encap[phdr->pkt_encap] == -1) { /* * No. Fail. */ *err = WTAP_ERR_UNSUPPORTED_ENCAP; return FALSE; } /* * Fill in the trailer with the network type. */ phtoles(rec_2_x_trlr.network, wtap_encap[phdr->pkt_encap]); } /* * Will the file offset of this frame fit in a 32-bit unsigned * integer? */ if (netmon->no_more_room) { /* * No, so the file is too big for NetMon format to * handle. */ *err = EFBIG; return FALSE; } /* * NetMon files have a capture start time in the file header, * and have times relative to that in the packet headers; * pick the time of the first packet as the capture start * time. * * That time has millisecond resolution, so chop any * sub-millisecond part of the time stamp off. */ if (!netmon->got_first_record_time) { netmon->first_record_time.secs = phdr->ts.secs; netmon->first_record_time.nsecs = (phdr->ts.nsecs/1000000)*1000000; netmon->got_first_record_time = TRUE; } if (wdh->encap == WTAP_ENCAP_ATM_PDUS) atm_hdrsize = sizeof (struct netmon_atm_hdr); else atm_hdrsize = 0; secs = (gint64)(phdr->ts.secs - netmon->first_record_time.secs); nsecs = phdr->ts.nsecs - netmon->first_record_time.nsecs; while (nsecs < 0) { /* * Propagate a borrow into the seconds. * The seconds is a time_t, and can be < 0 * (unlikely, as neither UN*X nor DOS * nor the original Mac System existed * before January 1, 1970, 00:00:00 UTC), * while the nanoseconds should be positive, * as in "nanoseconds since the instant of time * represented by the seconds". * * We do not want t to be negative, as, according * to the C90 standard, "if either operand [of / * or %] is negative, whether the result of the * / operator is the largest integer less than or * equal to the algebraic quotient or the smallest * greater than or equal to the algebraic quotient * is implementation-defined, as is the sign of * the result of the % operator", and we want * the result of the division and remainder * operations to be the same on all platforms. */ nsecs += 1000000000; secs--; } switch (wdh->file_type) { case WTAP_FILE_NETMON_1_x: rec_1_x_hdr.ts_delta = htolel(secs*1000 + (nsecs + 500000)/1000000); rec_1_x_hdr.orig_len = htoles(phdr->len + atm_hdrsize); rec_1_x_hdr.incl_len = htoles(phdr->caplen + atm_hdrsize); hdrp = &rec_1_x_hdr; hdr_size = sizeof rec_1_x_hdr; break; case WTAP_FILE_NETMON_2_x: rec_2_x_hdr.ts_delta = htolell(secs*1000000 + (nsecs + 500)/1000); rec_2_x_hdr.orig_len = htolel(phdr->len + atm_hdrsize); rec_2_x_hdr.incl_len = htolel(phdr->caplen + atm_hdrsize); hdrp = &rec_2_x_hdr; hdr_size = sizeof rec_2_x_hdr; break; default: /* We should never get here - our open routine should only get called for the types above. */ *err = WTAP_ERR_UNSUPPORTED_FILE_TYPE; return FALSE; } /* * Keep track of the record size, as we need to update * the current file offset. */ rec_size = 0; if (!wtap_dump_file_write(wdh, hdrp, hdr_size, err)) return FALSE; rec_size += hdr_size; if (wdh->encap == WTAP_ENCAP_ATM_PDUS) { /* * Write the ATM header. * We supply all-zero destination and source addresses. */ memset(&atm_hdr.dest, 0, sizeof atm_hdr.dest); memset(&atm_hdr.src, 0, sizeof atm_hdr.src); atm_hdr.vpi = g_htons(pseudo_header->atm.vpi); atm_hdr.vci = g_htons(pseudo_header->atm.vci); if (!wtap_dump_file_write(wdh, &atm_hdr, sizeof atm_hdr, err)) return FALSE; rec_size += sizeof atm_hdr; } if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) return FALSE; rec_size += phdr->caplen; if (wdh->encap == WTAP_ENCAP_PER_PACKET) { /* * Write out the trailer. */ if (!wtap_dump_file_write(wdh, &rec_2_x_trlr, sizeof rec_2_x_trlr, err)) return FALSE; rec_size += sizeof rec_2_x_trlr; } /* * Stash the file offset of this frame. */ if (netmon->frame_table_size == 0) { /* * Haven't yet allocated the buffer for the frame table. */ netmon->frame_table = g_malloc(1024 * sizeof *netmon->frame_table); netmon->frame_table_size = 1024; } else { /* * We've allocated it; are we at the end? */ if (netmon->frame_table_index >= netmon->frame_table_size) { /* * Yes - double the size of the frame table. */ netmon->frame_table_size *= 2; netmon->frame_table = g_realloc(netmon->frame_table, netmon->frame_table_size * sizeof *netmon->frame_table); } } netmon->frame_table[netmon->frame_table_index] = htolel(netmon->frame_table_offset); /* * Is this the last record we can write? * I.e., will the frame table offset of the next record not fit * in a 32-bit frame table offset entry? * * (We don't bother checking whether the number of frames * will fit in a 32-bit value, as, even if each record were * 1 byte, if there were more than 2^32-1 packets, the frame * table offset of at least one of those packets will be > * 2^32 - 1.) * * Note: this also catches the unlikely possibility that * the record itself is > 2^32 - 1 bytes long. */ if ((guint64)netmon->frame_table_offset + rec_size > G_MAXUINT32) { /* * Yup, too big. */ netmon->no_more_room = TRUE; } netmon->frame_table_index++; netmon->frame_table_offset += (guint32) rec_size; return TRUE; }
/* Finish writing to a dump file. Returns TRUE on success, FALSE on failure. */ static gboolean visual_dump_close(wtap_dumper *wdh, int *err) { struct visual_write_info * visual = (struct visual_write_info *)wdh->priv; size_t n_to_write; struct visual_file_hdr vfile_hdr; const char *magicp; size_t magic_size; /* If the visual structure was never allocated then nothing useful can be done. */ if (visual == 0) return FALSE; /* Write out the frame table at the end of the file. */ if (visual->index_table) { /* Write the index table to the file. */ n_to_write = visual->index_table_index * sizeof *visual->index_table; if (!wtap_dump_file_write(wdh, visual->index_table, n_to_write, err)) { visual_dump_free(wdh); return FALSE; } } /* Write the magic number at the start of the file. */ fseek(wdh->fh, 0, SEEK_SET); magicp = visual_magic; magic_size = sizeof visual_magic; if (!wtap_dump_file_write(wdh, magicp, magic_size, err)) { visual_dump_free(wdh); return FALSE; } /* Initialize the file header with zeroes for the reserved fields. */ memset(&vfile_hdr, '\0', sizeof vfile_hdr); vfile_hdr.num_pkts = htolel(visual->index_table_index); vfile_hdr.start_time = htolel(visual->start_time); vfile_hdr.max_length = htoles(65535); vfile_hdr.file_flags = htoles(1); /* indexes are present */ vfile_hdr.file_version = htoles(1); g_strlcpy(vfile_hdr.description, "Wireshark file", 64); /* Translate the encapsulation type */ switch (wdh->encap) { case WTAP_ENCAP_ETHERNET: vfile_hdr.media_type = htoles(6); break; case WTAP_ENCAP_TOKEN_RING: vfile_hdr.media_type = htoles(9); break; case WTAP_ENCAP_LAPB: vfile_hdr.media_type = htoles(16); break; case WTAP_ENCAP_PPP: /* PPP is differentiated from CHDLC in PktHdr */ case WTAP_ENCAP_PPP_WITH_PHDR: case WTAP_ENCAP_CHDLC_WITH_PHDR: vfile_hdr.media_type = htoles(22); break; case WTAP_ENCAP_FRELAY_WITH_PHDR: vfile_hdr.media_type = htoles(32); break; } /* Write the file header following the magic bytes. */ if (!wtap_dump_file_write(wdh, &vfile_hdr, sizeof vfile_hdr, err)) { visual_dump_free(wdh); return FALSE; } /* Deallocate the file write data */ visual_dump_free(wdh); return TRUE; }
/* Write a packet to a Visual dump file. Returns TRUE on success, FALSE on failure. */ static gboolean visual_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err) { const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header; struct visual_write_info * visual = (struct visual_write_info *)wdh->priv; struct visual_pkt_hdr vpkt_hdr; size_t hdr_size = sizeof vpkt_hdr; guint delta_msec; guint32 packet_status; /* If the visual structure was never allocated then nothing useful can be done. */ if (visual == 0) return FALSE; /* Zero out unused and reserved fields in the packet header. */ memset(&vpkt_hdr, 0, hdr_size); /* Visual UpTime capture files have a capture start time in the file header. Each packet has a capture time (in msec) relative to the file start time. Use the time of the first packet as the file start time. */ if (visual->index_table_index == 0) { /* This is the first packet. Save its start time as the file time. */ visual->start_time = (guint32) phdr->ts.secs; /* Initialize the index table */ visual->index_table = (guint32 *)g_malloc(1024 * sizeof *visual->index_table); visual->index_table_size = 1024; } /* Calculate milliseconds since capture start. */ delta_msec = phdr->ts.nsecs / 1000000; delta_msec += ( (guint32) phdr->ts.secs - visual->start_time) * 1000; vpkt_hdr.ts_delta = htolel(delta_msec); /* Fill in the length fields. */ vpkt_hdr.orig_len = htoles(phdr->len); vpkt_hdr.incl_len = htoles(phdr->caplen); /* Fill in the encapsulation hint for the file's media type. */ switch (wdh->encap) { case WTAP_ENCAP_ETHERNET: /* Ethernet */ vpkt_hdr.encap_hint = 2; break; case WTAP_ENCAP_TOKEN_RING: /* Token Ring */ vpkt_hdr.encap_hint = 3; break; case WTAP_ENCAP_PPP: /* PPP */ case WTAP_ENCAP_PPP_WITH_PHDR: vpkt_hdr.encap_hint = 14; break; case WTAP_ENCAP_CHDLC_WITH_PHDR: /* HDLC Router */ vpkt_hdr.encap_hint = 13; break; case WTAP_ENCAP_FRELAY_WITH_PHDR: /* Frame Relay Auto-detect */ vpkt_hdr.encap_hint = 12; break; case WTAP_ENCAP_LAPB: /* Unknown */ default: vpkt_hdr.encap_hint = 1; break; } /* Set status flags. The only status currently supported for all encapsulations is direction. This either goes in the p2p or the X.25 pseudo header. It would probably be better to move this up into the phdr. */ packet_status = 0; switch (wdh->encap) { case WTAP_ENCAP_CHDLC_WITH_PHDR: packet_status |= (pseudo_header->p2p.sent ? PS_SENT : 0x00); break; case WTAP_ENCAP_FRELAY_WITH_PHDR: case WTAP_ENCAP_LAPB: packet_status |= ((pseudo_header->x25.flags & FROM_DCE) ? 0x00 : PS_SENT); break; } vpkt_hdr.status = htolel(packet_status); /* Write the packet header. */ if (!wtap_dump_file_write(wdh, &vpkt_hdr, hdr_size, err)) return FALSE; /* Write the packet data */ if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) return FALSE; /* Store the frame offset in the index table. */ if (visual->index_table_index >= visual->index_table_size) { /* End of table reached. Reallocate with a larger size */ visual->index_table_size *= 2; visual->index_table = (guint32 *)g_realloc(visual->index_table, visual->index_table_size * sizeof *visual->index_table); } visual->index_table[visual->index_table_index] = htolel(visual->next_offset); /* Update the table index and offset for the next frame. */ visual->index_table_index++; visual->next_offset += (guint32) hdr_size + phdr->caplen; return TRUE; }
/* * Generic routine that handles open/creates. */ int smbio_ntcreatex(void *smbctx, const char *path, const char *streamName, struct open_inparms *inparms, struct open_outparm *outparms, int *fid) { uint16_t *namelenp; struct smb_usr_rq *rqp; mbchain_t mbp; mdchain_t mdp; uint8_t wc; size_t nmlen; int error; u_int16_t fid16; /* * Since the reply will fit in one mbuf, pass zero which will cause a normal * mbuf to get created. */ error = smb_usr_rq_init(smbctx, SMB_COM_NT_CREATE_ANDX, 0, &rqp); if (error != 0) { return error; } mbp = smb_usr_rq_getrequest(rqp); smb_usr_rq_wstart(rqp); mb_put_uint8(mbp, 0xff); /* secondary command */ mb_put_uint8(mbp, 0); /* MBZ */ mb_put_uint16le(mbp, 0); /* offset to next command (none) */ mb_put_uint8(mbp, 0); /* MBZ */ namelenp = (uint16_t *)mb_reserve(mbp, sizeof(uint16_t)); /* * XP to W2K Server never sets the NTCREATEX_FLAGS_OPEN_DIRECTORY * for creating nor for opening a directory. Samba ignores the bit. * * Request the extended reply to get maximal access */ mb_put_uint32le(mbp, NTCREATEX_FLAGS_EXTENDED); /* NTCREATEX_FLAGS_* */ mb_put_uint32le(mbp, 0); /* FID - basis for path if not root */ mb_put_uint32le(mbp, inparms->rights); mb_put_uint64le(mbp, inparms->allocSize); /* "initial allocation size" */ mb_put_uint32le(mbp, inparms->attrs); /* attributes */ mb_put_uint32le(mbp, inparms->shareMode); mb_put_uint32le(mbp, inparms->disp); mb_put_uint32le(mbp, inparms->createOptions); mb_put_uint32le(mbp, NTCREATEX_IMPERSONATION_IMPERSONATION); /* (?) */ mb_put_uint8(mbp, 0); /* security flags (?) */ smb_usr_rq_wend(rqp); smb_usr_rq_bstart(rqp); nmlen = 0; if (streamName) { size_t snmlen = 0; error = smb_usr_put_dmem(smbctx, mbp, path, strlen(path), SMB_UTF_SFM_CONVERSIONS | SMB_FULLPATH_CONVERSIONS, &nmlen); if (!error) { /* Make sure the stream name starts with a colon */ if (*streamName != ':') { mb_put_uint16le(mbp, ':'); nmlen += 2; } error = smb_usr_rq_put_dstring(smbctx, mbp, streamName, strlen(streamName), NO_SFM_CONVERSIONS, &snmlen); } nmlen += snmlen; } else { error = smb_usr_rq_put_dstring(smbctx, mbp, path, strlen(path), SMB_UTF_SFM_CONVERSIONS | SMB_FULLPATH_CONVERSIONS, &nmlen); } if (error) { smb_log_info("%s: smb_usr_rq_put_dstring failed syserr = %s", ASL_LEVEL_DEBUG, __FUNCTION__, strerror(error)); goto done; } /* Now the network name length into the reserved location */ *namelenp = htoles((uint16_t)nmlen); smb_usr_rq_bend(rqp); error = smb_usr_rq_simple(rqp); if (error != 0) { smb_log_info("%s: smb_usr_rq_simple failed, syserr = %s", ASL_LEVEL_DEBUG, __FUNCTION__, strerror(error)); goto done; } mdp = smb_usr_rq_getreply(rqp); /* * Spec say 26 for word count, but 34 words are defined and observed from * all servers. * * The spec is wrong and word count should always be 34 unless we request * the extended reply. Now some server will always return 42 even it the * NTCREATEX_FLAGS_EXTENDED flag is not set. * * From the MS-SMB document concern the extend response: * * The word count for this response MUST be 0x2A (42). WordCount in this * case is not used as the count of parameter words but is just a number. */ if (md_get_uint8(mdp, &wc) != 0 || ((wc != NTCREATEX_NORMAL_WDCNT) && (wc != NTCREATEX_EXTENDED_WDCNT))) { error = EIO; smb_log_info("%s: bad word count, syserr = %s", ASL_LEVEL_DEBUG, __FUNCTION__, strerror(error)); goto done; } md_get_uint8(mdp, NULL); /* secondary cmd */ md_get_uint8(mdp, NULL); /* mbz */ md_get_uint16le(mdp, NULL); /* andxoffset */ md_get_uint8(mdp, NULL); /* oplock lvl granted */ md_get_uint16le(mdp, &fid16); /* FID */ *fid = fid16; error = md_get_uint32le(mdp, NULL); /* create_action */ /* Only get the rest of the parameter values if they want request them */ if (outparms) { /* Should we convert the time, current we don't */ md_get_uint64le(mdp, &outparms->createTime); md_get_uint64le(mdp, &outparms->accessTime); md_get_uint64le(mdp, &outparms->writeTime); md_get_uint64le(mdp, &outparms->changeTime); md_get_uint32le(mdp, &outparms->attributes); md_get_uint64le(mdp, &outparms->allocationSize); md_get_uint64le(mdp, &outparms->fileSize); md_get_uint16le(mdp, NULL); /* file type */ md_get_uint16le(mdp, NULL); /* device state */ error = md_get_uint8(mdp, NULL); /* directory (boolean) */ /* Supports extended word count, so lets get them */ if (wc == NTCREATEX_EXTENDED_WDCNT) { md_get_mem(mdp, (caddr_t)outparms->volumeGID, sizeof(outparms->volumeGID), MB_MSYSTEM); md_get_uint64le(mdp, &outparms->fileInode); md_get_uint32le(mdp, &outparms->maxAccessRights); error = md_get_uint32le(mdp, &outparms->maxGuessAccessRights); } } done: smb_usr_rq_done(rqp); return error; }
UtlBoolean MprRecorder::doProcessFrame(MpBufPtr inBufs[], MpBufPtr outBufs[], int inBufsSize, int outBufsSize, UtlBoolean isEnabled, int samplesPerFrame, int samplesPerSecond) { int numBytes = 0; int numSamples = 0; MpBufPtr in = NULL; Sample* input; // Lock so that mFileDescriptor and file contents cannot be changed out // from under us while we are updating the file. OsLock lock(mMutex); //try to pass along first input if (inBufsSize > 0) { in = *inBufs; } if (numOutputs() > 0) { if (inBufsSize > 0) *inBufs = NULL; *outBufs = in; } if (!isEnabled) { return TRUE; } if (mFileDescriptor < 0) { OsSysLog::add(FAC_MP, PRI_DEBUG, "MprRecorder::doProcessFrame to disable recording because mFileDescriptor=%d, mStatus=%d", mFileDescriptor, mStatus); disable(RECORD_STOPPED); // just in case... } if (inBufsSize == 0) { // no input buffers, indicate config error disable(INVALID_SETUP); return TRUE; } // maximum record time reached or final silence timeout. if ((0 >= mFramesToRecord--) || (mSilenceLength <= mConsecutiveInactive)) { // Get previous MinVoiceEnergy for debug printouts, and reset it to MIN_SPEECH_ENERGY_THRESHOLD. unsigned long prevValue = MpBuf_setMVE(MIN_SPEECH_ENERGY_THRESHOLD); OsSysLog::add(FAC_MP, PRI_INFO, "MprRecorder::doProcessFrame to disable recording because" " mFramesToRecord=%d, mStatus=%d mSilenceLength=%d," " mConsecutiveInactive=%d, MinVoiceEnergy=%lu", mFramesToRecord, mStatus, mSilenceLength, mConsecutiveInactive, prevValue); disable(RECORD_FINISHED); } else { int bytesWritten = 0; //now write the buffer out if (NULL == in) { in = MpBuf_getFgSilence(); } else { MpBuf_addRef(in); } if (MpBuf_isActiveAudio(in)) { mConsecutiveInactive = 0; } else { mConsecutiveInactive++; } input = MpBuf_getSamples(in); numSamples = MpBuf_getNumSamples(in); numBytes = numSamples * sizeof(Sample); if (mFileDescriptor > -1) { #ifdef __BIG_ENDIAN__ //We are running on a big endian processor - 16-bit samples are in the big endian //byte order - convert them to little endian before writing them to the file. unsigned short *pData; int index; for ( index = 0, pData = (unsigned short *)input; index < numSamples; index++, pData++ ) *pData = htoles(*pData); #endif bytesWritten = write(mFileDescriptor, (char *)input, numBytes); #ifdef __BIG_ENDIAN__ if (numOutputs() > 1) { //There is more than one output - convert the samples back to big endian for ( index = 0, pData = (unsigned short *)input; index < numSamples; index++, pData++ ) *pData = letohs(*pData); } #endif } if (bytesWritten != numBytes) { disable(WRITE_ERROR); } else { mTotalBytesWritten += numBytes; mTotalSamplesWritten += samplesPerFrame; } MpBuf_delRef(in); } return TRUE; }
/*--------------------------------------------------- * *---------------------------------------------------*/ static gboolean lanalyzer_dump_header(wtap_dumper *wdh, int *err) { LA_TmpInfo *itmp = (LA_TmpInfo*)(wdh->priv); guint16 board_type = itmp->encap == WTAP_ENCAP_TOKEN_RING ? BOARD_325TR /* LANalyzer Board Type */ : BOARD_325; /* LANalyzer Board Type */ time_t secs; struct tm *fT; /* The secs variable is needed to work around 32/64-bit time_t issues. itmp->start is a timeval struct, which declares its tv_sec field (itmp->start.tv_sec) as a long (typically 32 bits). time_t can be 32 or 64 bits, depending on the platform. Invoking as follows could pass a pointer to a 32-bit long where a pointer to a 64-bit time_t is expected: localtime((time_t*) &(itmp->start.tv_sec)) */ secs = itmp->start.tv_sec; fT = localtime(&secs); if (fT == NULL) return FALSE; fseek(wdh->fh, 0, SEEK_SET); if (!wtap_dump_file_write(wdh, &LA_HeaderRegularFake, sizeof LA_HeaderRegularFake, err)) return FALSE; if (!wtap_dump_file_write(wdh, &LA_RxChannelNameFake, sizeof LA_RxChannelNameFake, err)) return FALSE; if (!wtap_dump_file_write(wdh, &LA_TxChannelNameFake, sizeof LA_TxChannelNameFake, err)) return FALSE; if (!wtap_dump_file_write(wdh, &LA_RxTemplateNameFake, sizeof LA_RxTemplateNameFake, err)) return FALSE; if (!wtap_dump_file_write(wdh, &LA_TxTemplateNameFake, sizeof LA_TxTemplateNameFake, err)) return FALSE; if (!wtap_dump_file_write(wdh, &LA_DisplayOptionsFake, sizeof LA_DisplayOptionsFake, err)) return FALSE; /*-----------------------------------------------------------------*/ if (!s16write(wdh, htoles(RT_Summary), err)) /* rid */ return FALSE; if (!s16write(wdh, htoles(SummarySize), err)) /* rlen */ return FALSE; if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.datcre.day */ return FALSE; if (!s8write(wdh, (guint8) (fT->tm_mon+1), err)) /* s.datcre.mon */ return FALSE; if (!s16write(wdh, htoles(fT->tm_year + 1900), err)) /* s.datcre.year */ return FALSE; if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.datclo.day */ return FALSE; if (!s8write(wdh, (guint8) (fT->tm_mon+1), err)) /* s.datclo.mon */ return FALSE; if (!s16write(wdh, htoles(fT->tm_year + 1900), err)) /* s.datclo.year */ return FALSE; if (!s8write(wdh, (guint8) fT->tm_sec, err)) /* s.timeopn.second */ return FALSE; if (!s8write(wdh, (guint8) fT->tm_min, err)) /* s.timeopn.minute */ return FALSE; if (!s8write(wdh, (guint8) fT->tm_hour, err)) /* s.timeopn.hour */ return FALSE; if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.timeopn.mday */ return FALSE; if (!s0write(wdh, 2, err)) return FALSE; if (!s8write(wdh, (guint8) fT->tm_sec, err)) /* s.timeclo.second */ return FALSE; if (!s8write(wdh, (guint8) fT->tm_min, err)) /* s.timeclo.minute */ return FALSE; if (!s8write(wdh, (guint8) fT->tm_hour, err)) /* s.timeclo.hour */ return FALSE; if (!s8write(wdh, (guint8) fT->tm_mday, err)) /* s.timeclo.mday */ return FALSE; if (!s0write(wdh, 2, err)) return FALSE; if (!s0write(wdh, 6, err)) /* EAddr == 0 */ return FALSE; if (!s16write(wdh, htoles(1), err)) /* s.mxseqno */ return FALSE; if (!s16write(wdh, htoles(0), err)) /* s.slcoffo */ return FALSE; if (!s16write(wdh, htoles(1514), err)) /* s.mxslc */ return FALSE; if (!s32write(wdh, htolel(itmp->pkts), err)) /* s.totpktt */ return FALSE; /* * statrg == 0; ? -1 * stptrg == 0; ? -1 * s.mxpkta[0]=0 */ if (!s0write(wdh, 12, err)) return FALSE; if (!s32write(wdh, htolel(itmp->pkts), err)) /* sr.s.mxpkta[1] */ return FALSE; if (!s0write(wdh, 34*4, err)) /* s.mxpkta[2-33]=0 */ return FALSE; if (!s16write(wdh, htoles(board_type), err)) return FALSE; if (!s0write(wdh, 20, err)) /* board_version == 0 */ return FALSE; /*-----------------------------------------------------------------*/ if (!s16write(wdh, htoles(RT_SubfileSummary), err)) /* ssr.rid */ return FALSE; if (!s16write(wdh, htoles(LA_SubfileSummaryRecordSize-4), err)) /* ssr.rlen */ return FALSE; if (!s16write(wdh, htoles(1), err)) /* ssr.seqno */ return FALSE; if (!s32write(wdh, htolel(itmp->pkts), err)) /* ssr.totpkts */ return FALSE; /*-----------------------------------------------------------------*/ if (!wtap_dump_file_write(wdh, &LA_CyclicInformationFake, sizeof LA_CyclicInformationFake, err)) return FALSE; /*-----------------------------------------------------------------*/ if (!s16write(wdh, htoles(RT_Index), err)) /* rid */ return FALSE; if (!s16write(wdh, htoles(LA_IndexRecordSize -4), err)) /* rlen */ return FALSE; if (!s16write(wdh, htoles(LA_IndexSize), err)) /* idxsp */ return FALSE; if (!s0write(wdh, LA_IndexRecordSize - 6, err)) return FALSE; return TRUE; }
/*--------------------------------------------------- * Write a record for a packet to a dump file. * Returns TRUE on success, FALSE on failure. *---------------------------------------------------*/ static gboolean lanalyzer_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr, const guint8 *pd, int *err) { double x; int i; int len; struct timeval tv; LA_TmpInfo *itmp = (LA_TmpInfo*)(wdh->priv); struct timeval td; int thisSize = phdr->caplen + LA_PacketRecordSize + LA_RecordHeaderSize; if (wdh->bytes_dumped + thisSize > LA_ProFileLimit) { /* printf(" LA_ProFileLimit reached\n"); */ *err = EFBIG; return FALSE; /* and don't forget the header */ } len = phdr->caplen + (phdr->caplen ? LA_PacketRecordSize : 0); if (!s16write(wdh, htoles(0x1005), err)) return FALSE; if (!s16write(wdh, htoles(len), err)) return FALSE; tv.tv_sec = (long int) phdr->ts.secs; tv.tv_usec = phdr->ts.nsecs / 1000; if (!itmp->init) { /* collect some information for the * finally written header */ /* XXX - this conversion could probably improved, if the start uses ns */ itmp->start = tv; itmp->pkts = 0; itmp->init = TRUE; itmp->encap = wdh->encap; itmp->lastlen = 0; } my_timersub(&(tv),&(itmp->start),&td); x = (double) td.tv_usec; x += (double) td.tv_sec * 1000000; x *= 2; if (!s16write(wdh, htoles(0x0001), err)) /* pr.rx_channels */ return FALSE; if (!s16write(wdh, htoles(0x0008), err)) /* pr.rx_errors */ return FALSE; if (!s16write(wdh, htoles(phdr->len + 4), err)) /* pr.rx_frm_len */ return FALSE; if (!s16write(wdh, htoles(phdr->caplen), err)) /* pr.rx_frm_sln */ return FALSE; for (i = 0; i < 3; i++) { if (!s16write(wdh, htoles((guint16) x), err)) /* pr.rx_time[i] */ return FALSE; x /= 0xffff; } if (!s32write(wdh, htolel(++itmp->pkts), err)) /* pr.pktno */ return FALSE; if (!s16write(wdh, htoles(itmp->lastlen), err)) /* pr.prlen */ return FALSE; itmp->lastlen = len; if (!s0write(wdh, 12, err)) return FALSE; if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err)) return FALSE; wdh->bytes_dumped += thisSize; return TRUE; }
int mb_put_uint16le(struct mbchain *mbp, u_int16_t x) { x = htoles(x); return mb_put_mem(mbp, (caddr_t)&x, sizeof(x), MB_MSYSTEM); }