SolarCapture C Bindings
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
sc_writer.h
1 
2 #ifndef __SC_WRITER_H__
3 #define __SC_WRITER_H__
4 
5 
6 enum on_error {
7  ON_ERROR_EXIT,
8  ON_ERROR_ABORT,
9  ON_ERROR_MESSAGE,
10  ON_ERROR_SILENT,
11 };
12 
13 /* This is set to the same as tcpdump (4.5.1) */
14 #define MAX_SNAPLEN 262144
15 
16 #define SC_PARTIAL_BUFFER (1 << 12) /* sc_packet flag */
17 
18 static inline int on_error_from_str(const char* str, enum on_error* on_error_out)
19 {
20  if( ! strcasecmp(str, "exit") ) {
21  *on_error_out = ON_ERROR_EXIT;
22  return 1;
23  }
24  if( ! strcasecmp(str, "abort") ) {
25  *on_error_out = ON_ERROR_ABORT;
26  return 1;
27  }
28  if( ! strcasecmp(str, "message") ) {
29  *on_error_out = ON_ERROR_MESSAGE;
30  return 1;
31  }
32  if( ! strcasecmp(str, "silent") ) {
33  *on_error_out = ON_ERROR_SILENT;
34  return 1;
35  }
36  return 0;
37 }
38 
39 static inline int ts_type_from_str(const char* str, enum ts_type* ts_type_out)
40 {
41  if( ! strcasecmp(str, "pcap") ) {
42  *ts_type_out = ts_micro;
43  return 1;
44  }
45  if( ! strcasecmp(str, "pcap-ns") ) {
46  *ts_type_out = ts_nano;
47  return 1;
48  }
49  return 0;
50 }
51 
52 static inline int sc_pcap_filename(char* buf, int buf_len, const char* template_in,
53  bool timed, bool indexed,
54  struct timespec ts, int index)
55 {
56  char tmpl[buf_len];
57  if( indexed ) {
58  const char* needle = "$i";
59  const char* p = strstr(template_in, needle);
60  if( p ) {
61  if( snprintf(tmpl, buf_len, "%.*s%d%s", (int)(p-template_in), template_in,
62  index, p + strlen(needle)) == buf_len )
63  return -1;
64  }
65  else {
66  if( snprintf(tmpl, buf_len, "%s%d", template_in, index) == buf_len )
67  return -1;
68  }
69  }
70  else {
71  /*template_in can have valid escape characters so must use %s*/
72  if( snprintf(tmpl, buf_len, "%s", template_in) == buf_len )
73  return -1;
74  }
75 
76  if( timed ) {
77  struct tm tm;
78  if( strftime(buf, buf_len,
79  tmpl, localtime_r(&ts.tv_sec, &tm)) == 0 )
80  return -1;
81  }
82  else {
83  if( snprintf(buf, buf_len, "%s", tmpl) == buf_len )
84  return -1;
85  }
86  return 0;
87 }
88 
89 struct sc_pcap_packer_state;
90 
91 int sc_perf_writer_init(struct sc_node* node, const struct sc_attr* attr,
92  const struct sc_node_factory* factory);
93 
94 void sc_pcap_packer_set_file_byte_count(struct sc_pcap_packer_state* st,
95  uint64_t file_byte_count);
96 
97 void sc_pcap_packer_pack_list(struct sc_node* node, struct sc_packet_list* pl,
98  struct sc_packet_list* done, int* frame_bytes,
99  int* cap_bytes);
100 
101 void sc_pcap_packer_end_of_stream(struct sc_node* node);
102 
103 void sc_pcap_packer_add_input(struct sc_node* packer_node, struct sc_node* input_node);
104 
105 #endif /* __SC_WRITER_H__ */
106 
Attribute object.
Struct to hold information about how to create an instance of this node.
Definition: ext_node.h:69
A list of packets or packet buffers.
Definition: ext_packet_list.h:14
Description of a node.
Definition: ext_node.h:17