Advertisement
kator

send

Mar 21st, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <netdb.h>
  2. #include <netinet/in.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <sys/socket.h>
  6. #include <unistd.h>
  7.  
  8. int main(int argc, char** argv) {
  9.   int sfd, rc;
  10.   char buf[128];
  11.   struct sockaddr_in saddr;
  12.   struct hostent* addrent;
  13.  
  14.   addrent = gethostbyname(argv[1]);
  15.   sfd = socket(PF_INET, SOCK_STREAM, 0);
  16.   memset(&saddr, 0, sizeof(saddr));
  17.   saddr.sin_family = AF_INET;
  18.   saddr.sin_port = htons(atoi(argv[2]));
  19.   memcpy(&saddr.sin_addr.s_addr, addrent->h_addr, addrent->h_length);
  20.   connect(sfd, (struct sockaddr*) &saddr, sizeof(saddr));
  21.   rc = read(sfd, buf, 128);
  22.   write(1, buf, rc);
  23.   close(sfd);
  24.   return EXIT_SUCCESS;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement