SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <netinet/in.h>
  4. #include <sys/types.h>
  5. #include <sys/socket.h>
  6. #include <arpa/inet.h>
  7. #include <netdb.h>
  8.  
  9.  
  10.  
  11.  
  12. int main(int argc, char **argv)
  13. {
  14.     struct sockaddr_in adr;
  15.     int gniazdo, r;
  16.     unsigned int port;
  17.     char abcd[512] = "150.254.79.243";
  18.     //
  19.     unsigned int index = htonl(444495);
  20.     char buffer[11] = "444495\n";
  21.     in_addr_t h, n;
  22.     memcpy(&buffer[7],(const void*)&index, 4);
  23.    
  24.     //sprintf(buffer,"0x%02X0x%02X0x%02X0x%02X0x%02X0x%02X", numer_indeksu[0],numer_indeksu[1],numer_indeksu[2], numer_indeksu[3], numer_indeksu[4], numer_indeksu[5]);
  25.     //sprintf(buffer,"%d%d%d%d%d%d", numer_indeksu[0],numer_indeksu[1],numer_indeksu[2], numer_indeksu[3], numer_indeksu[4], numer_indeksu[5]);
  26.     //sprintf(buffer, "%s%c%c",buffer,'0', 'A');
  27.    
  28.  
  29.    
  30.     //unsigned char *jako_bajty;
  31.     //h = 444495;
  32.     //n = htonl(h);
  33.     //jako_bajty = (unsigned char *) &n;
  34.     //sprintf(buffer, "%s%X%X%X%X", buffer, jako_bajty[0],jako_bajty[1], jako_bajty[2],jako_bajty[3]);
  35.     //
  36.     printf("Podaj numer portu odbiorcy: ");
  37.     scanf("%u", &port);
  38.    
  39.     gniazdo = socket(AF_INET, SOCK_DGRAM, 0);
  40.     adr.sin_family = AF_INET;
  41.    
  42.     adr.sin_port = htons(port);
  43.     adr.sin_addr.s_addr = inet_addr(abcd);
  44.     printf("%s", buffer);
  45.     r = sendto(gniazdo,
  46.                buffer,
  47.                11,
  48.                0,
  49.                (struct sockaddr*) &adr,
  50.                sizeof(adr));
  51.     if (r != 11) printf("sendto() nie powiodl sie\n");
  52.     else printf("Wiadomosc wyslana.\n");
  53.     close(gniazdo);
  54.     return 0;
  55. }
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