Changeset 87b490e3 in mainline for uspace/lib/pcap/src/pcap_dumper.c
- Timestamp:
- 2024-12-13T08:44:05Z (10 months ago)
- Children:
- 420b13d
- Parents:
- fb31682
- git-author:
- Nataliia Korop <n.corop08@…> (2024-11-30 19:08:32)
- git-committer:
- Nataliia Korop <n.corop08@…> (2024-12-13 08:44:05)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcap/src/pcap_dumper.c
rfb31682 r87b490e3 30 30 * @{ 31 31 */ 32 /** @file 33 * @brief pcap inteface: Dumping interface for the device which packets we want to dump 32 /** @file Pcap dumper. Structure is a part of every device that is in category PCAP and can dump packets. 34 33 */ 35 34 … … 43 42 /** Initialize writing to .pcap file. 44 43 * 45 * @param writer Interface for w orking with .pcap file.44 * @param writer Interface for writing data. 46 45 * @param filename Name of the file for dumping packets. 47 * @return EOK on success oran error code.46 * @return EOK on success, otherwise an error code. 48 47 * 49 48 */ … … 66 65 } 67 66 67 /** Open file for appending to the end of it. 68 * @param writer Interface for writing data. 69 * @param filename Path to the file. 70 * @return EOK on success, error code otherwise. 71 */ 68 72 static errno_t pcap_writer_to_file_init_append(pcap_writer_t *writer, const char *filename) 69 73 { … … 76 80 } 77 81 82 /** Initialize file for dumping usb packets. 83 * @param writer Interface for writing data. 84 * @param filename Path to the file. 85 * @return EOK on success, error code otherwise. 86 */ 78 87 static errno_t pcap_writer_to_file_usb_init(pcap_writer_t *writer, const char *filename) 79 88 { … … 94 103 } 95 104 105 /** Write 4B to the file. 106 * @param writer Interface for writing data. 107 * @param data Bytes to write. 108 * @return Size of successfully witten data. 109 */ 96 110 static size_t pcap_file_w32(pcap_writer_t *writer, uint32_t data) 97 111 { … … 99 113 } 100 114 115 /** Write 2B to the file. 116 * @param writer Interface for writing data. 117 * @param data Bytes to write. 118 * @return Size of successfully witten data. 119 */ 101 120 static size_t pcap_file_w16(pcap_writer_t *writer, uint16_t data) 102 121 { … … 104 123 } 105 124 125 /** Write block of bytes to the file. 126 * @param writer Interface for writing data. 127 * @param data Bytes to write. 128 * @param size Size of block of bytes. 129 * @return Size of successfully witten data. 130 */ 106 131 static size_t pcap_file_wbuffer(pcap_writer_t *writer, const void *data, size_t size) 107 132 { … … 110 135 } 111 136 137 /** Close file for writing. 138 * @param writer Interaface for writing data. 139 */ 112 140 static void pcap_file_close(pcap_writer_t *writer) 113 141 { … … 116 144 } 117 145 146 /** Write <= 60B of block of bytes. 147 * @param writer Interface for writing data. 148 * @param data Bytes to write. 149 * @param size Size of block of bytes. 150 * @return Size of successfully witten data. 151 */ 118 152 static size_t pcap_short_file_wbuffer(pcap_writer_t *writer, const void *data, size_t size) 119 153 { … … 121 155 } 122 156 157 /** Standard writer operations for writing data to a newly created file. */ 123 158 static const pcap_writer_ops_t file_ops = { 124 159 .open = &pcap_writer_to_file_init, … … 129 164 }; 130 165 166 /** Truncated writer operations. Only first 60 bytes of the packet are written. */ 131 167 static const pcap_writer_ops_t short_file_ops = { 132 168 .open = &pcap_writer_to_file_init, … … 138 174 }; 139 175 176 /** Append writer operations. Instead of creating new file open existing file and append packets. */ 140 177 static const pcap_writer_ops_t append_file_ops = { 141 178 .open = &pcap_writer_to_file_init_append, … … 146 183 }; 147 184 185 /** USB writer operations. Writing USB packets to the file. */ 148 186 static const pcap_writer_ops_t usb_file_ops = { 149 187 .open = &pcap_writer_to_file_usb_init, … … 154 192 }; 155 193 194 /** Default array of operations. Must be consistens with constants in /uspace/app/pcapctl/main.c */ 156 195 static pcap_writer_ops_t ops[4] = { file_ops, short_file_ops, append_file_ops, usb_file_ops }; 157 196 197 /** Get number of writer operations in @ref ops */ 158 198 int pcap_dumper_get_ops_number(void) 159 199 { … … 161 201 } 162 202 203 /** Open destination buffer for writing and set flag for dumping. 204 * @param dumper Structure responsible for dumping packets. Part of the driver. 205 * @param name Name of the destination buffer to dump packets to. 206 * @return EOK if successful, erro code otherwise. 207 */ 163 208 errno_t pcap_dumper_start(pcap_dumper_t *dumper, const char *name) 164 209 { … … 174 219 } 175 220 221 /** Set writer options for the writer. 222 * @param dumper Structure responsible for dumping packets. Part of the driver. 223 * @param index Index of the writer operations from array @ref ops. 224 * @return EOK if successful, erro code otherwise. 225 */ 176 226 errno_t pcap_dumper_set_ops(pcap_dumper_t *dumper, int index) 177 227 { … … 183 233 } 184 234 235 /** Write packet to destination buffer. 236 * @param dumper Structure responsible for dumping packets. Part of the driver. 237 * @param data Packet data to write. 238 * @param size Size of the packet. 239 */ 185 240 void pcap_dumper_add_packet(pcap_dumper_t *dumper, const void *data, size_t size) 186 241 { … … 196 251 } 197 252 253 /** Close destination buffer for writing and unset flag for dumping. 254 * @param dumper Structure responsible for dumping packets. Part of the driver. 255 */ 198 256 void pcap_dumper_stop(pcap_dumper_t *dumper) 199 257 {
Note:
See TracChangeset
for help on using the changeset viewer.