#include #include #include #include #include /* usage: recuento */ int main(int argc, char * argv[]) { int n, s, len; char preferencia; char input[10]; struct hostent *hp; struct sockaddr_in name; hp = gethostbyname(argv[1]); s = socket(AF_INET, SOCK_DGRAM, 0); name.sin_family = AF_INET; name.sin_port = htons(atoi(argv[2])); memcpy(&name.sin_addr, hp->h_addr_list[0], hp->h_length); len = sizeof(struct sockaddr_in); printf(" Ingrese \n a: voto por A \n b: voto por B\n f: fin de recuento.\n"); while ((n=read(0, input, sizeof(input))) > 0) { input[n]='\0'; input[0] = input[0]-'a'+'A'; /* upercase*/ if (input[0] == 'A' || input[0] =='B') { printf("Sending \"%s\"\n", input); sendto(s, input, 1, 0, (struct sockaddr*) &name, len); } else if (input[0]=='F') exit(0); else printf(" Ingrese \n a: voto por A \n b: voto por B\n f: fin de recuento.\n"); } }