static int32_t camd33_send(uchar *buf, int32_t ml) { int32_t l; if (!cur_client()->pfd) return(-1); l=boundary(4, ml); memset(buf+ml, 0, l-ml); cs_ddump_mask(D_CLIENT, buf, l, "send %d bytes to client", l); if (cur_client()->crypted) aes_encrypt_idx(cur_client(), buf, l); return(send(cur_client()->pfd, buf, l, 0)); }
static int32_t camd33_send(uchar *buf, int32_t ml) { int32_t l; if(!cur_client()->pfd) { return (-1); } l = boundary(4, ml); memset(buf + ml, 0, l - ml); cs_log_dump_dbg(D_CLIENT, buf, l, "send %d bytes to client", l); if(cur_client()->crypted) { aes_encrypt_idx(cur_client()->aes_keys, buf, l); } return (send(cur_client()->pfd, buf, l, 0)); }
static int32_t __camd35_send(struct s_client *cl, uchar *buf, int32_t buflen, int answer_awaited) { int32_t l; unsigned char rbuf[REQ_SIZE + 15 + 4], *sbuf = rbuf + 4; if(!cl->udp_fd || !cl->crypted) { return (-1); } //exit if no fd or aes key not set! //Fix ECM len > 255 if(buflen <= 0) { buflen = ((buf[0] == 0) ? (((buf[21] & 0x0f) << 8) | buf[22]) + 3 : buf[1]); } l = 20 + (((buf[0] == 3) || (buf[0] == 4)) ? 0x34 : 0) + buflen; memcpy(rbuf, cl->ucrc, 4); memcpy(sbuf, buf, l); memset(sbuf + l, 0xff, 15); // set unused space to 0xff for newer camd3's i2b_buf(4, crc32(0L, sbuf + 20, buflen), sbuf + 4); l = boundary(4, l); cs_log_dump_dbg(cl->typ == 'c' ? D_CLIENT : D_READER, sbuf, l, "send %d bytes to %s", l, username(cl)); aes_encrypt_idx(cl->aes_keys, sbuf, l); int32_t status; if(cl->is_udp) { status = sendto(cl->udp_fd, rbuf, l + 4, 0, (struct sockaddr *)&cl->udp_sa, cl->udp_sa_len); if(status == -1) { set_null_ip(&SIN_GET_ADDR(cl->udp_sa)); } } else { status = send(cl->udp_fd, rbuf, l + 4, 0); if(cl->typ == 'p' && cl->reader) { if(status == -1) { network_tcp_connection_close(cl->reader, "can't send"); } } else if(cl->typ == 'c') { if(status == -1) { cs_disconnect_client(cl); } } } if(status != -1) { if(cl->reader && answer_awaited) { cl->reader->last_s = time(NULL); } if(cl->reader && !answer_awaited) { cl->reader->last_s = cl->reader->last_g = time(NULL); } cl->last = time(NULL); } return status; }
static int32_t camd33_recv(struct s_client * client, uchar *buf, int32_t l) { int32_t n; if (!client->pfd) return(-1); if ((n=recv(client->pfd, buf, l, 0))>0) { client->last=time((time_t *) 0); if (client->crypted) aes_encrypt_idx(cur_client(), buf, n); } cs_ddump_mask(D_CLIENT, buf, n, "received %d bytes from client", n); return(n); }
static int32_t camd33_recv(struct s_client *client, uchar *buf, int32_t l) { int32_t n; if(!client->pfd) { return (-1); } if((n = cs_recv(client->pfd, buf, l, 0)) > 0) { client->last = time((time_t *) 0); if(client->crypted) { aes_encrypt_idx(cur_client()->aes_keys, buf, n); } } cs_log_dump_dbg(D_CLIENT, buf, n, "received %d bytes from client", n); return (n); }
static int32_t camd35_send(uint8_t *buf, int32_t buflen) { int32_t l, status; unsigned char rbuf[REQ_SIZE + 15 + 4], *sbuf = rbuf + 4; //Fix ECM len > 255 if(buflen <= 0) { buflen = ((buf[0] == 0) ? (((buf[21] & 0x0f) << 8) | buf[22]) + 3 : buf[1]); } l = 20 + (((buf[0] == 3) || (buf[0] == 4)) ? 0x34 : 0) + buflen; memcpy(rbuf, cl_ucrc, 4); memcpy(sbuf, buf, l); memset(sbuf + l, 0xff, 15); // set unused space to 0xff for newer camd3's i2b_buf(4, crc32(0, sbuf + 20, buflen), sbuf + 4); l = boundary(4, l); cs_log_dbg(0, "send %d bytes to client", l); aes_encrypt_idx(&cl_aes_keys, sbuf, l); status = sendto(cl_sockfd, rbuf, l + 4, 0, (struct sockaddr *)&cl_socket, sizeof(cl_socket)); return status; }
int32_t monitor_send_idx(struct s_client *cl, char *txt) { int32_t l; unsigned char buf[256+32]; if (!cl->udp_fd) return -1; struct timespec req_ts; req_ts.tv_sec = 0; req_ts.tv_nsec = 500000; nanosleep (&req_ts, NULL);//avoid lost udp-pakkets if (!cl->crypted) return sendto(cl->udp_fd, txt, strlen(txt), 0, (struct sockaddr *)&cl->udp_sa, cl->udp_sa_len); buf[0]='&'; buf[9]=l=strlen(txt); l=boundary(4, l+5)+5; memcpy(buf+1, cl->ucrc, 4); cs_strncpy((char *)buf+10, txt, sizeof(buf)-10); uchar tmp[10]; memcpy(buf+5, i2b_buf(4, crc32(0L, buf+10, l-10), tmp), 4); aes_encrypt_idx(cl, buf+5, l-5); return sendto(cl->udp_fd, buf, l, 0, (struct sockaddr *)&cl->udp_sa, cl->udp_sa_len); }