Advertisement
waelsy123

Untitled

Apr 15th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. // Client TCP
  2. #define _GNU_SOURCE
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <errno.h>
  7. #include <string.h>
  8. #include <sys/types.h>
  9. #include <sys/socket.h>
  10. #include <sys/time.h>
  11. #include <netinet/in.h>
  12. #include <signal.h>
  13. #include <netdb.h>
  14. #define ERR(source) (perror(source),\
  15. fprintf(stderr,"%s:%d\n",__FILE__,__LINE__),\
  16. exit(EXIT_FAILURE))
  17. #define HERR(source) (fprintf(stderr,"%s(%d) at %s:%d\n",source,h_errno,__FILE__,__LINE__),\
  18. exit(EXIT_FAILURE))
  19.  
  20. int sethandler( void (*f)(int), int sigNo) {
  21. struct sigaction act;
  22. memset(&act, 0, sizeof(struct sigaction));
  23. act.sa_handler = f;
  24. if (-1==sigaction(sigNo, &act, NULL))
  25. return -1;
  26. return 0;
  27. }
  28. struct sockaddr_in make_address(char *address, uint16_t port){
  29. struct sockaddr_in addr;
  30. struct hostent *hostinfo;
  31. addr.sin_family = AF_INET;
  32. addr.sin_port = htons (port);
  33. hostinfo = gethostbyname(address);
  34. if(hostinfo == NULL)HERR("gethostbyname");
  35. addr.sin_addr = *(struct in_addr*) hostinfo->h_addr;
  36. return addr;
  37. }
  38.  
  39.  
  40. void usage(char * name){
  41. fprintf(stderr,"USAGE: %s domain port operand1 operand2 operation \n",name);
  42. }
  43.  
  44. int main(int argc, char** argv) {
  45. int fd;
  46. int32_t data[5];
  47. if(argc!=6) {
  48. usage(argv[0]);
  49. return EXIT_FAILURE;
  50. }
  51.  
  52. // HERE
  53. return EXIT_SUCCESS;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement