int main() { write_montgomery(message, r2modm, modulus); montgomery(); read_r(); for (i = 0; i < SIZE; i++) { mont_message[i] = r[i]; } for (i = 0; i < SIZE; i++) { a[i] = rmodm[i]; } for (i = 0; i < 2; i++) { for (j = 0; j < 8; j++) { write_montgomery(a, a, modulus); montgomery(); read_r(); for (i = 0; i < SIZE; i++) { a[i] = r[i]; } if (get_bit_value(enc_exp[i], 7-j) == 1) { write_montgomery(a, mont_message, modulus); montgomery(); read_r(); for (i = 0; i < SIZE; i++) { a[i] = r[i]; } } } } write_montgomery(a, one, modulus); montgomery(); read_r(); for (i = 0; i < SIZE; i++) { a[i] = r[i]; } terminate(); return 0; }
int main(int argc, const char *argv[]) { struct sockaddr_in server_addr, client_addr; socklen_t client_addr_len; int connection_sock, listen_sock; char buf[MAXLINE]; char str[INET_ADDRSTRLEN]; int i,n; char bindmsg[1024]; int optval = 1; //struct sigaction { //void (*sa_handler)(int); //void (*sa_sigaction)(int, siginfo_t *, void *); //sigset_t sa_mask; //int sa_flags; //void (*sa_restorer)(void); //}; struct sigaction act, oact; //void *memcpy(void *dest, const void *src, size_t n); strcpy(bindmsg, argv[1]); strcat(bindmsg, " prot 8000"); if(argc != 2) err_sys("Usage ./server server_addr"); //int socket_r(int domain, int type, int protocol); listen_sock = socket(AF_INET, SOCK_STREAM, 0); //int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); setsockopt_r(listen_sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(SERVER_PORT); //int inet_pton(int af, const char *src, void *dst); inet_pton(AF_INET, argv[1], &server_addr.sin_addr); //void bind_r(int listening_socket, const struct sockaddr *addr, socklen_t addrlen, void *arg); bind_r(listen_sock, (struct sockaddr *)&server_addr, sizeof(server_addr), (void *)bindmsg); //void listen_r(int sockfd, int backlog, void *arg); listen_r(listen_sock, SERVER_BACKLOG, (void *)bindmsg); //int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) //siganl process act.sa_flags = 0; act.sa_handler = signal_handler; sigemptyset(&act.sa_mask); sigaction(SIGCHLD, &act, &oact); fprintf(stdout, "accepting connections ...\n"); pid_t pid; while(1){ client_addr_len = sizeof(client_addr); //int accept_r(int sockfd, struct sockaddr *addr, socklen_t *addrlen); connection_sock = accept_r(listen_sock, (struct sockaddr *)&client_addr, &client_addr_len); if(connection_sock < 0){ if(errno == EINTR) continue; err_ret("accept() failed"); } pid = fork(); if(pid < 0) err_sys("call to fork"); else if(pid == 0){ close_r(listen_sock); //ssize_t read_r(int fd, void *ptr, size_t nbytes); while(1){ n = read_r(connection_sock, buf, MAXLINE); if(n == 0) { fprintf(stdout, "peer side(%s port %d) has been closed.\n", inet_ntop(AF_INET, &client_addr.sin_addr, str, sizeof(str)), ntohs(client_addr.sin_port)); break; } fprintf(stdout, "reciveed from %s at port %d\n", inet_ntop(AF_INET, &client_addr.sin_addr, str, sizeof(str)), ntohs(client_addr.sin_port)); for (i = 0; i < n; i++) { buf[i] = toupper(buf[i]); } //ssize_t write_r(int fd, const void *ptr, size_t nbytes); write_r(connection_sock, buf, n); } close_r(connection_sock); exit(0); } else { close_r(connection_sock); } //void close_r(int fd); //close_r(connection_sock); } return 0; }
bool Color::read(yarp::os::idl::WireReader& reader) { if (!read_r(reader)) return false; if (!read_g(reader)) return false; if (!read_b(reader)) return false; return !reader.isError(); }