static err_t low_level_output(struct netif *netif, struct pbuf *p) { struct pbuf *q; char buf[1514]; char *bufptr; struct udpif *udpif; struct sockaddr_in addr; struct s_compress_header *sh; size_t enc_size = 0; udpif = (struct udpif *)netif->state; #if 0 if(((double)rand()/(double)RAND_MAX) < 0.2) { printf("drop output\n"); return ERR_OK; } #endif /* initiate transfer(); */ sh = (struct s_compress_header *)(buf + sizeof(struct eth_hdr)); bufptr = buf + sizeof(struct s_compress_header) + sizeof(struct eth_hdr); for(q = p; q != NULL; q = q->next) { /* Send the data from the pbuf to the interface, one pbuf at a time. The size of the data in each pbuf is kept in the ->len variable. */ /* send data from(q->payload, q->len); */ memcpy(bufptr, q->payload, q->len); bufptr += q->len; } if(p->tot_len < sizeof(struct eth_hdr)) return ERR_OK; memcpy(buf, buf + sizeof(struct s_compress_header) + sizeof(struct eth_hdr), sizeof(struct eth_hdr)); /* dup ether header*/ sh->real_size = p->tot_len; if(udpif->peer_ip.addr != INADDR_ANY) { bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = udpif->peer_ip.addr; addr.sin_port = udpif->peer_port; s_compress(sh); enc_size = sh->comp_size + sizeof(struct s_compress_header); s_encrypt(udpif->enc_handle, (byte_t*)(sh), enc_size); if(sendto(udpif->fd, buf, enc_size + sizeof(struct eth_hdr), MSG_NOSIGNAL, (struct sockaddr *)&addr, sizeof(addr)) == -1) { perror("udpif: sendto"); } } return ERR_OK; }
char* bee_s_encrypt(void *b, char *clear, long len, long key, long *res_len) { CK_RV r; char *res; if ((r = s_encrypt(*((bee*) b), (CK_BYTE_PTR) clear, (CK_ULONG) len, (CK_OBJECT_HANDLE) key, (CK_BYTE_PTR*) &res, (CK_ULONG_PTR) res_len)) != CKR_OK) { last_error = r; return NULL; } return res; }