/* Log garbage sent by a client. */ void log_garbage(t_session *session) { int i, spaces = 2; FILE *fp; char str[TIMESTAMP_SIZE + IP_ADDRESS_SIZE]; if ((session->config->garbage_logfile == NULL) || (session->request == NULL)) { return; } for (i = 0; i < session->bytes_in_buffer; i++) { if (session->request[i] == '\0') { if (spaces > 0) { session->request[i] = ' '; spaces--; } else { session->request[i] = '\r'; } } } if ((fp = fopen(session->config->garbage_logfile, "a")) == NULL) { return; } ip_to_str(str, &(session->ip_address), IP_ADDRESS_SIZE); strcat(str, "|"); print_timestamp(str + strlen(str)); fprintf(fp, "%s%s"EOL, str, session->request); fclose(fp); }
int accept_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = arg; if (timestamp) print_timestamp(fp); switch (n->nlmsg_type) { case RTM_NEWLINK: case RTM_DELLINK: if (prefix_banner) fprintf(fp, "[LINK]"); return print_linkinfo(who, n, arg); case RTM_NEWNEIGH: case RTM_DELNEIGH: if (prefix_banner) fprintf(fp, "[NEIGH]"); return print_fdb(who, n, arg); case 15: return show_mark(fp, n); default: return 0; } }
template<typename T> static void print_default_pajeLink_row(paje_event_t& event) { init_stream<T>(event); print_timestamp(event); stream << " " << static_cast<T>(event->data)->type->id << " " << static_cast<T>(event->data)->container->id << " " << static_cast<T>(event->data)->value; }
static double wiimote_timestamp2logicaltime(t_wiimote*x, struct timespec*timestamp) { double pddelay=clock_gettimesince(x->baselogicaltime); /* how long in logical time since we have connected to the wii */ double realdelay=0.; /* how long (in ms) after we connected to the wiimote this timestamp appeared */ double delay=0.; if(NULL==timestamp || NULL==x->basetime) return 0.; /* immediately */ realdelay= (timestamp->tv_sec - x->basetime->tv_sec) * 1000. + (timestamp->tv_nsec - x->basetime->tv_nsec) / 1000000.; delay=realdelay-pddelay; #if 0 print_timestamp(timestamp, x->basetime); post("logical time: %f = %f - %f", clock_gettimesince(x->baselogicaltime), now, x->baselogicaltime); #endif //post("diff = %f = %f - %f", realdelay-pddelay, realdelay, pddelay); if(delay<0) { return 0.; } return realdelay; }
static int xfrm_accept_msg(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE *)arg; if (timestamp) print_timestamp(fp); if (listen_all_nsid) { if (ctrl == NULL || ctrl->nsid < 0) fprintf(fp, "[nsid current]"); else fprintf(fp, "[nsid %d]", ctrl->nsid); } switch (n->nlmsg_type) { case XFRM_MSG_NEWSA: case XFRM_MSG_DELSA: case XFRM_MSG_UPDSA: case XFRM_MSG_EXPIRE: xfrm_state_print(who, n, arg); return 0; case XFRM_MSG_NEWPOLICY: case XFRM_MSG_DELPOLICY: case XFRM_MSG_UPDPOLICY: case XFRM_MSG_POLEXPIRE: xfrm_policy_print(who, n, arg); return 0; case XFRM_MSG_ACQUIRE: xfrm_acquire_print(who, n, arg); return 0; case XFRM_MSG_FLUSHSA: xfrm_state_flush_print(who, n, arg); return 0; case XFRM_MSG_FLUSHPOLICY: xfrm_policy_flush_print(who, n, arg); return 0; case XFRM_MSG_REPORT: xfrm_report_print(who, n, arg); return 0; case XFRM_MSG_NEWAE: xfrm_ae_print(who, n, arg); return 0; case XFRM_MSG_MAPPING: xfrm_mapping_print(who, n, arg); return 0; default: break; } if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && n->nlmsg_type != NLMSG_DONE) { fprintf(fp, "Unknown message: %08d 0x%08x 0x%08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); } return 0; }
int accept_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; if (timestamp) print_timestamp(fp); if (n->nlmsg_type == RTM_NEWROUTE || n->nlmsg_type == RTM_DELROUTE) { print_route(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWLINK || n->nlmsg_type == RTM_DELLINK) { ll_remember_index(who, n, NULL); print_linkinfo(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) { print_addrinfo(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWNEIGH || n->nlmsg_type == RTM_DELNEIGH) { print_neigh(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWPREFIX) { print_prefix(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWRULE || n->nlmsg_type == RTM_DELRULE) { print_rule(who, n, arg); return 0; } if (n->nlmsg_type == 15) { char *tstr; time_t secs = ((__u32*)NLMSG_DATA(n))[0]; long usecs = ((__u32*)NLMSG_DATA(n))[1]; tstr = asctime(localtime(&secs)); tstr[strlen(tstr)-1] = 0; fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs); return 0; } if (n->nlmsg_type == RTM_NEWQDISC || n->nlmsg_type == RTM_DELQDISC || n->nlmsg_type == RTM_NEWTCLASS || n->nlmsg_type == RTM_DELTCLASS || n->nlmsg_type == RTM_NEWTFILTER || n->nlmsg_type == RTM_DELTFILTER) return 0; if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && n->nlmsg_type != NLMSG_DONE) { fprintf(fp, "Unknown message: %08x %08x %08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); } return 0; }
// Wait for data to be read or written void double_buffering_wait( double_buffering *b, which_buffer wh_buff ) { int i; ssize_t nbytes; // Which buffer aiocb_list *buff = wh_buff == IO_BUFF ? b->io_l : b->comp_l; #if DEBUG printf("Waiting for %p\n%d operations issued\nLast chunk: %zu bytes\n", buff, buff->issued, buff->aiocb_l[buff->issued-1]->aio_nbytes); fflush(stdout); #endif for ( i = 0; i < buff->issued; i++ ) { buff->aux_l[0] = (struct aiocb *)buff->aiocb_l[i]; #if DEBUG printf("Waiting for chunk %d (of %d): %zu bytes\n", i, buff->issued, buff->aux_l[0]->aio_nbytes); printf("Start: "); print_timestamp(); fflush(stdout); #endif if ( aio_suspend( buff->aux_l, 1, NULL ) != 0 ) { // perror("aio_suspend error"); fprintf(stderr, "[ERROR] aio_suspend: %s", strerror(aio_error(buff->aux_l[0]))); exit( EXIT_FAILURE ); } nbytes = aio_return( (struct aiocb *)buff->aux_l[0] ); if ( nbytes != buff->aux_l[0]->aio_nbytes ) { fprintf(stderr, "[ERROR] aio_return: %s", strerror(aio_error(buff->aux_l[0]))); // perror("aio_suspend error - data not read completely"); printf("%zu bytes read/write - %zu bytes expected\n", nbytes, buff->aux_l[0]->aio_nbytes); exit( EXIT_FAILURE ); } #if DEBUG printf("End: "); print_timestamp(); fflush(stdout); #endif } }
void np_conn_respond(Npreq *req) { int n; Npconn *conn; Nptrans *trans; Npfcall *rc; trans = NULL; conn = req->conn; rc = req->rcall; pthread_mutex_lock(&conn->lock); if (conn->trans && !conn->resetting && rc) { if (conn->srv->debuglevel) { print_timestamp(stderr); fprintf(stderr, " >>> (%p) ", conn); np_printfcall(stderr, rc, conn->dotu); if ( req->tcall->encryptor ) fprintf(stderr, " (encrypted)"); fprintf(stderr, "\n"); } if ( req->tcall->encryptor ) { /* Request was encrypted => encrypt also the response */ rc->encryptor = req->tcall->encryptor; rc = np_encrypt_fcall(rc); req->rcall = rc; } n = np_trans_write(conn->trans, rc->pkt, rc->size); if (n <= 0) { trans = conn->trans; conn->trans = NULL; } } np_conn_free_incall(req->conn, req->tcall); free(req->rcall); req->tcall = NULL; req->rcall = NULL; pthread_mutex_unlock(&conn->lock); if (conn->resetting) { pthread_mutex_lock(&conn->srv->lock); pthread_cond_broadcast(&conn->resetcond); pthread_mutex_unlock(&conn->srv->lock); } if (trans) np_trans_destroy(trans); /* np_conn_read_proc will take care of resetting */ }
static int xfrm_accept_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; if (timestamp) print_timestamp(fp); if (n->nlmsg_type == XFRM_MSG_NEWSA || n->nlmsg_type == XFRM_MSG_DELSA || n->nlmsg_type == XFRM_MSG_UPDSA || n->nlmsg_type == XFRM_MSG_EXPIRE) { xfrm_state_print(who, n, arg); return 0; } if (n->nlmsg_type == XFRM_MSG_NEWPOLICY || n->nlmsg_type == XFRM_MSG_DELPOLICY || n->nlmsg_type == XFRM_MSG_UPDPOLICY || n->nlmsg_type == XFRM_MSG_POLEXPIRE) { xfrm_policy_print(who, n, arg); return 0; } if (n->nlmsg_type == XFRM_MSG_ACQUIRE) { xfrm_acquire_print(who, n, arg); return 0; } if (n->nlmsg_type == XFRM_MSG_FLUSHSA) { /* XXX: Todo: show proto in xfrm_usersa_flush */ fprintf(fp, "Flushed state\n"); return 0; } if (n->nlmsg_type == XFRM_MSG_FLUSHPOLICY) { fprintf(fp, "Flushed policy\n"); return 0; } if (n->nlmsg_type == XFRM_MSG_REPORT) { xfrm_report_print(who, n, arg); return 0; } if (n->nlmsg_type == XFRM_MSG_NEWAE) { xfrm_ae_print(who, n, arg); return 0; } if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && n->nlmsg_type != NLMSG_DONE) { fprintf(fp, "Unknown message: %08d 0x%08x 0x%08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); } return 0; }
void print_wim_direntry (const char *prefix, struct wim_direntry *dir) { printf ("%s.length = %" PRIu64 "\n", prefix, dir->length); printf ("%s.attributes = %" PRIu32, prefix, dir->attributes); if (dir->attributes) { printf (" ("); print_wim_file_attributes (dir->attributes); printf (")"); } printf ("\n"); printf ("%s.security_id = %" PRIu32 "\n", prefix, dir->security_id); printf ("%s.subidr_offset = %" PRIu64 "\n", prefix, dir->subdir_offset); printf ("%s.creation_time = %" PRIi64 " (", prefix, dir->creation_time); print_timestamp (dir->creation_time); printf (")\n"); printf ("%s.last_access_time = %" PRIi64 " (", prefix, dir->last_access_time); print_timestamp (dir->last_access_time); printf (")\n"); printf ("%s.last_write_time = %" PRIi64 " (", prefix, dir->last_write_time); print_timestamp (dir->last_write_time); printf (")\n"); printf ("%s.hash = ", prefix); print_hex (dir->hash, sizeof (dir->hash)); printf ("\n"); printf ("%s.reparse_tag = %" PRIu32 "\n", prefix, dir->reparse_tag); printf ("%s.hardlink = %" PRIu64 "\n", prefix, dir->hardlink); printf ("%s.streams = %" PRIu16 "\n", prefix, dir->streams); printf ("%s.short_name_length = %" PRIu16 "\n", prefix, dir->short_name_length); printf ("%s.file_name_length = %" PRIu16 "\n", prefix, dir->file_name_length); if (dir->file_name_length > 0) { printf ("%s.filename = ", prefix); print_utf16 (dir->filename, dir->file_name_length); printf ("\n"); } }
static void print_headers(FILE *fp, char *label, struct rtnl_ctrl_data *ctrl) { if (timestamp) print_timestamp(fp); if (listen_all_nsid) { if (ctrl == NULL || ctrl->nsid < 0) fprintf(fp, "[nsid current]"); else fprintf(fp, "[nsid %d]", ctrl->nsid); } if (prefix_banner) fprintf(fp, "%s", label); }
void print(int action, const char *fmt, ...) { char buf[80]; size_t len; va_list ap; const char success[] = " \e[1m[ OK ]\e[0m\n"; const char failure[] = " \e[7m[FAIL]\e[0m\n"; const char warning[] = " \e[7m[WARN]\e[0m\n"; const char pending[] = " \e[1m[ \\/ ]\e[0m\n"; const char dots[] = " ....................................................................."; if (silent) return; if (fmt) { va_start(ap, fmt); len = vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); delline(); print_timestamp(); write(STDERR_FILENO, "\r", 1); write(STDERR_FILENO, buf, len); write(STDERR_FILENO, dots, 60 - len); /* pad with dots. */ } switch (action) { case -1: break; case 0: write(STDERR_FILENO, success, sizeof(success)); break; case 1: write(STDERR_FILENO, failure, sizeof(failure)); break; case 2: write(STDERR_FILENO, warning, sizeof(warning)); break; default: write(STDERR_FILENO, pending, sizeof(pending)); break; } }
/* Log an unbanning. */ void log_unban(char *logfile, t_ip_addr *ip_address, unsigned long connect_attempts) { FILE *fp; char str[TIMESTAMP_SIZE + IP_ADDRESS_SIZE]; if ((logfile == NULL) || (ip_address == NULL)) { return; } else if ((fp = fopen(logfile, "a")) == NULL) { return; } ip_to_str(str, ip_address, IP_ADDRESS_SIZE); strcat(str, "|"); print_timestamp(str + strlen(str)); fprintf(fp, "%sUnbanned (%ld connect attempts during ban)"EOL, str, connect_attempts); fclose(fp); }
void RMDBGLOG_implementation(RMbool active,const RMascii *filename,RMint32 line,const RMascii *text,...) { if (active && (verbose_stderr != 0)) { va_list ap; snprintf((char *)str,RMDBG_MAX_STRING,"[%s:%ld] ", (char *)filename,line); va_start(ap, text); vsnprintf((char *)(str+strlen(str)), RMDBG_MAX_STRING-strlen(str), text, ap); va_end(ap); print_timestamp(NORMALMSG); fprintf(NORMALMSG,str); fflush(NORMALMSG); } }
lcb_error_t form_command(lcb_error_t err, lcb_t instance, const char * const key, const int count) { lcb_store_cmd_t cmd; const lcb_store_cmd_t* commands[1]; commands[0] = &cmd; memset(&cmd, 0, sizeof(cmd)); cmd.v.v0.operation = LCB_SET; cmd.v.v0.key = "foo"; if (key) cmd.v.v0.key = key; cmd.v.v0.nkey = 3; cmd.v.v0.bytes = "bar"; cmd.v.v0.nbytes = 3; print_timestamp(); for (int i=0; i < count; i++) err = lcb_store(instance, NULL, 1, commands); return err; }
static int xfrm_accept_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; if (timestamp) print_timestamp(fp); switch (n->nlmsg_type) { case XFRM_MSG_NEWSA: case XFRM_MSG_DELSA: case XFRM_MSG_UPDSA: case XFRM_MSG_EXPIRE: xfrm_state_print(who, n, arg); return 0; case XFRM_MSG_NEWPOLICY: case XFRM_MSG_DELPOLICY: case XFRM_MSG_UPDPOLICY: case XFRM_MSG_POLEXPIRE: xfrm_policy_print(who, n, arg); return 0; case XFRM_MSG_ACQUIRE: xfrm_acquire_print(who, n, arg); return 0; case XFRM_MSG_FLUSHSA: xfrm_state_flush_print(who, n, arg); return 0; case XFRM_MSG_FLUSHPOLICY: xfrm_policy_flush_print(who, n, arg); return 0; case XFRM_MSG_REPORT: xfrm_report_print(who, n, arg); return 0; case XFRM_MSG_NEWAE: xfrm_ae_print(who, n, arg); return 0; default: break; } if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && n->nlmsg_type != NLMSG_DONE) { fprintf(fp, "Unknown message: %08d 0x%08x 0x%08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); } return 0; }
/* Log a CGI error. */ void log_cgi_error(t_session *session, char *mesg) { FILE *fp; char *c, str[TIMESTAMP_SIZE + IP_ADDRESS_SIZE]; int len = 0; if ((session->host->error_logfile == NULL) || (mesg == NULL)) { return; } c = mesg; while (*c != '\0') { if (*c == '\n') { if (*(c + 1) == '\0') { *c = '\0'; } else { *c = '|'; } } else { len++; } c++; } if (len == 0) { return; } if ((fp = fopen(session->host->error_logfile, "a")) == NULL) { return; } if (session->config->anonymize_ip) { anonymized_ip_to_str(&(session->ip_address), str, IP_ADDRESS_SIZE); } else { ip_to_str(&(session->ip_address), str, IP_ADDRESS_SIZE); } strcat(str, "|"); print_timestamp(str + strlen(str)); if (session->file_on_disk == NULL) { fprintf(fp, "%s-|%s"EOL, str, secure_string(mesg)); } else { fprintf(fp, "%s%s|%s"EOL, str, session->file_on_disk, secure_string(mesg)); } fclose(fp); }
int recv_timestamp (int code, void *closure, struct sockaddr_in *dest, struct sockaddr_in *from, struct ip *ip, icmphdr_t * icmp, int datalen) { switch (code) { case PEV_RESPONSE: case PEV_DUPLICATE: print_timestamp (code == PEV_DUPLICATE, closure, dest, from, ip, icmp, datalen); break; case PEV_NOECHO:; print_icmp_header (from, ip, icmp, datalen); } return 0; }
static void get_callback(lcb_t instance, const void *cookie, lcb_error_t error, const lcb_get_resp_t *item) { if (error == LCB_SUCCESS) { print_timestamp(); fprintf(stderr, "GOT \""); fwrite(item->v.v0.key, sizeof(char), item->v.v0.nkey, stderr); fprintf(stderr, "\" CAS: %"PRIu64" FLAGS:0x%x SIZE:%lu\n", item->v.v0.cas, item->v.v0.flags, (unsigned long)item->v.v0.nbytes); fwrite(item->v.v0.bytes, sizeof(char), item->v.v0.nbytes, stderr); fprintf(stderr, "\n"); } else { fprintf(stderr, "GET ERROR: %s (0x%x)\n", lcb_strerror(instance, error), error); } (void)cookie; }
/* Log an error for a specific file */ void log_file_error(t_session *session, char *file, char *mesg, ...) { FILE *fp; va_list args; char str[TIMESTAMP_SIZE + IP_ADDRESS_SIZE + 2]; if (mesg == NULL) { return; } if (session->host == NULL) { if (session->config->first_host->error_logfile == NULL) { return; } fp = fopen(session->config->first_host->error_logfile, "a"); } else { if (session->host->error_logfile == NULL) { return; } fp = fopen(session->host->error_logfile, "a"); } if (fp == NULL) { return; } va_start(args, mesg); if (session->config->anonymize_ip) { anonymized_ip_to_str(&(session->ip_address), str, IP_ADDRESS_SIZE); } else { ip_to_str(&(session->ip_address), str, IP_ADDRESS_SIZE); } strcat(str, "|"); print_timestamp(str + strlen(str)); if (file == NULL) { fprintf(fp, "%s", str); } else { fprintf(fp, "%s%s|", str, file); } vfprintf(fp, mesg, args); fprintf(fp, EOL); fclose(fp); va_end(args); }
/* TODO: output addresses manually */ # warning "inet_ntop() not available, network addresses will not be included in debug output" # endif /* WITH_CONTIKI */ return 0; #endif } #endif /* NDEBUG */ #ifndef WITH_CONTIKI void dsrv_log(log_t level, char *format, ...) { static char timebuf[32]; va_list ap; FILE *log_fd; if (maxlog < (int)level) return; log_fd = level <= DTLS_LOG_CRIT ? stderr : stdout; if (print_timestamp(timebuf,sizeof(timebuf), time(NULL))) fprintf(log_fd, "%s ", timebuf); if (level <= DTLS_LOG_DEBUG) fprintf(log_fd, "%s ", loglevels[level]); va_start(ap, format); vfprintf(log_fd, format, ap); va_end(ap); fflush(log_fd); } #elif defined (HAVE_VPRINTF) /* WITH_CONTIKI */ void dsrv_log(log_t level, char *format, ...) { static char timebuf[32]; va_list ap; if (maxlog < level) return; if (print_timestamp(timebuf,sizeof(timebuf), clock_time())) PRINTF("%s ", timebuf); if (level <= DTLS_LOG_DEBUG) PRINTF("%s ", loglevels[level]); va_start(ap, format); vprintf(format, ap); va_end(ap); }
lcb_error_t form_command_get(int count, lcb_error_t err, lcb_t instance, char* key) { lcb_get_cmd_t cmd; const lcb_get_cmd_t* commands[1]; commands[0] = &cmd; memset(&cmd, 0, sizeof(cmd)); cmd.v.v0.key = "foo"; if (key) cmd.v.v0.key = key; cmd.v.v0.nkey = 3; print_timestamp(); for (int i = 0; i < count; i++) { err = lcb_get(instance, NULL, 1, commands); } return err; }
void vlog_message(int priority, const char *format, va_list args) { /* Get the timestamp before entering the lock for more honest times. */ struct timespec now; if (log_timestamps) clock_gettime(CLOCK_REALTIME, &now); LOCK(log_lock); if (daemon_mode) vsyslog(priority, format, args); else { if (log_timestamps) print_timestamp(&now); vfprintf(stderr, format, args); fprintf(stderr, "\n"); } UNLOCK(log_lock); }
void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend) { static char timebuf[32]; FILE *log_fd; int n = 0; if (maxlog < (int)level) return; log_fd = level <= DTLS_LOG_CRIT ? stderr : stdout; if (print_timestamp(timebuf, sizeof(timebuf), time(NULL))) fprintf(log_fd, "%s ", timebuf); if (level <= DTLS_LOG_DEBUG) fprintf(log_fd, "%s ", loglevels[level]); if (extend) { fprintf(log_fd, "%s: (%zu bytes):\n", name, length); while (length--) { if (n % 16 == 0) fprintf(log_fd, "%08X ", n); fprintf(log_fd, "%02X ", *buf++); n++; if (n % 8 == 0) { if (n % 16 == 0) fprintf(log_fd, "\n"); else fprintf(log_fd, " "); } } } else { fprintf(log_fd, "%s: (%zu bytes): ", name, length); while (length--) fprintf(log_fd, "%02X", *buf++); } fprintf(log_fd, "\n"); fflush(log_fd); }
int main(int argc, char **argv) { struct cserial_port port; int ret, i; #define SIZE 1 char buf[SIZE]; struct timespec now, rxtime; struct cserial_port_conf conf = { .baud = 19200, .parity = PARITY_NONE, .csize = 8, .stopbits = 1, }; char *tty; tty = (argc > 1 && argv[1] != NULL) ? argv[1] : "/dev/ttyUSB0"; if (ret = cserial_open(&port, &conf, tty)) fprintf(stderr, "cserial_open Error %d: %s\n", ret, strerror(ret)); clock_gettime(CLOCK_MONOTONIC, &rxtime); while ((ret = cserial_read(&port, buf, SIZE)) != -1) { clock_gettime(CLOCK_MONOTONIC, &now); print_timestamp(&rxtime, &now); printf(": "); for (i = 0; i < ret; i++) { if (i != 0) printf(" "); printf("%02x", buf[i]); } printf("\n"); clock_gettime(CLOCK_MONOTONIC, &rxtime); } if (ret) fprintf(stderr, "cserial_read Error %d: %s\n", ret, strerror(ret)); if (ret = cserial_close(&port)) fprintf(stderr, "cserial_close Error %d: %s\n", ret, strerror(ret)); return 0; }
void RMNOTIFY_implementation(void *cookie, RMstatus status, const RMascii *filename, RMint32 line, const RMascii *text,...) { va_list ap; if (RMFAILED(status)) { snprintf((char *)str, RMDBG_MAX_STRING, "%s[%s:%ld] ERROR(%s): ", SET_ERROR, (char *)filename, line, RMstatusToString(status)); } else { snprintf((char *)str, RMDBG_MAX_STRING, "[%s:%ld] ", (char *)filename, line); } va_start(ap, text); vsnprintf((char *)str+strlen(str), RMDBG_MAX_STRING, text, ap); va_end(ap); snprintf((char *)str+strlen(str), RMDBG_MAX_STRING, "%s", SET_STD); print_timestamp(ERRORMSG); fprintf(ERRORMSG, str); fflush(ERRORMSG); }
/* Log a text. */ void log_string(char *logfile, char *mesg, ...) { FILE *fp; va_list args; char str[TIMESTAMP_SIZE]; if (mesg == NULL) { return; } else if ((fp = fopen(logfile, "a")) == NULL) { return; } va_start(args, mesg); print_timestamp(str); fprintf(fp, "%s", str); vfprintf(fp, mesg, args); fprintf(fp, EOL); fclose(fp); va_end(args); }
/* * Append the DRTT to the payload * and send packet. The kernel will * attach the timestamp along the way. */ void send_cntp_packet() { unsigned char *pkt = malloc(C_HLEN + TIMESTAMP_LEN); memset(pkt, 0, C_HLEN + TIMESTAMP_LEN); struct sockaddr_ll sk; int send_sock_fd = create_sending_socket(globals.sender_inf, &sk); populate_header(globals.dest_node, globals.dest_node, globals.src_node, CNTP_PORT, &pkt); struct timestamp *drtt_st = (struct timestamp *)(pkt + C_HLEN); drtt_st->sec = 0; drtt_st->fsec = atoi(globals.drtt); send_packet(send_sock_fd, &sk, pkt, C_HLEN + TIMESTAMP_LEN); print_drtt_packet_net(pkt); print_timestamp((struct timestamp*)(pkt + C_HLEN)); }
void dsrv_log(log_t level, char *format, ...) { static char timebuf[32]; va_list ap; FILE *log_fd; if (maxlog < (int)level) return; log_fd = level <= DTLS_LOG_CRIT ? stderr : stdout; if (print_timestamp(timebuf,sizeof(timebuf), time(NULL))) fprintf(log_fd, "%s ", timebuf); if (level <= DTLS_LOG_DEBUG) fprintf(log_fd, "%s ", loglevels[level]); va_start(ap, format); vfprintf(log_fd, format, ap); va_end(ap); fflush(log_fd); }
/** dump as narrow string of hex digits */ void dump(unsigned char *buf, size_t len) { while (len--) printf("%02x", *buf++); } void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr) { char addrbuf[73]; int len; len = dsrv_print_addr(addr, addrbuf, sizeof(addrbuf)); if (!len) return; dsrv_log(level, "%s: %s\n", name, addrbuf); } #ifndef WITH_CONTIKI void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend) { static char timebuf[32]; FILE *log_fd; int n = 0; if (maxlog < (int)level) return; log_fd = level <= DTLS_LOG_CRIT ? stderr : stdout; if (print_timestamp(timebuf, sizeof(timebuf), time(NULL))) fprintf(log_fd, "%s ", timebuf); if (level <= DTLS_LOG_DEBUG) fprintf(log_fd, "%s ", loglevels[level]); if (extend) { fprintf(log_fd, "%s: (%zu bytes):\n", name, length); while (length--) { if (n % 16 == 0) fprintf(log_fd, "%08X ", n); fprintf(log_fd, "%02X ", *buf++); n++; if (n % 8 == 0) { if (n % 16 == 0) fprintf(log_fd, "\n"); else fprintf(log_fd, " "); } } } else { fprintf(log_fd, "%s: (%zu bytes): ", name, length); while (length--) fprintf(log_fd, "%02X", *buf++); } fprintf(log_fd, "\n"); fflush(log_fd); } #else /* WITH_CONTIKI */ void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend) { static char timebuf[32]; int n = 0; if (maxlog < level) return; if (print_timestamp(timebuf,sizeof(timebuf), clock_time())) PRINTF("%s ", timebuf); if (level >= 0 && level <= DTLS_LOG_DEBUG) PRINTF("%s ", loglevels[level]); if (extend) { PRINTF("%s: (%zu bytes):\n", name, length); while (length--) { if (n % 16 == 0) PRINTF("%08X ", n); PRINTF("%02X ", *buf++); n++; if (n % 8 == 0) { if (n % 16 == 0) PRINTF("\n"); else PRINTF(" "); } } } else { PRINTF("%s: (%zu bytes): ", name, length); while (length--) PRINTF("%02X", *buf++); } PRINTF("\n"); }