daily pastebin goal
46%
SHARE
TWEET

sirboderafael

a guest Mar 1st, 2009 619 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #include <netinet/in.h>
  4. #include <arpa/inet.h>
  5. #include <netdb.h>
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <errno.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11.  
  12. int main()
  13. {
  14.     int sock;
  15.     struct sockaddr_in server_addr;
  16.     struct hostent *host;
  17.     char send_data[1024];
  18.  
  19.     host = (struct hostent *) gethostbyname((char *)"SEU-HOST-OU-IP");
  20.  
  21.     if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
  22.         perror("Erro: Socket");
  23.         exit(1);
  24.     }
  25.  
  26.     server_addr.sin_family = AF_INET;
  27.     server_addr.sin_port = htons(25000);
  28.     server_addr.sin_addr = *((struct in_addr *)host->h_addr);
  29.     bzero(&(server_addr.sin_zero),8);
  30.  
  31.     while (1) {
  32.  
  33.         printf("Digite algo (\\s ou \\S para sair):");
  34.         gets(send_data);
  35.  
  36.         if ((strcmp(send_data , "\\s") == 0) || strcmp(send_data , "\\S") == 0) {
  37.             break;
  38.         } else {
  39.             sendto(
  40.                 sock,
  41.                 send_data,
  42.                 strlen(send_data),
  43.                 0,
  44.                 (struct sockaddr *)&server_addr,
  45.                 sizeof(struct sockaddr)
  46.             );
  47.         }
  48.     }
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top