Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Client TCP
- #define _GNU_SOURCE
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <errno.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <sys/time.h>
- #include <netinet/in.h>
- #include <signal.h>
- #include <netdb.h>
- #define ERR(source) (perror(source),\
- fprintf(stderr,"%s:%d\n",__FILE__,__LINE__),\
- exit(EXIT_FAILURE))
- #define HERR(source) (fprintf(stderr,"%s(%d) at %s:%d\n",source,h_errno,__FILE__,__LINE__),\
- exit(EXIT_FAILURE))
- int sethandler( void (*f)(int), int sigNo) {
- struct sigaction act;
- memset(&act, 0, sizeof(struct sigaction));
- act.sa_handler = f;
- if (-1==sigaction(sigNo, &act, NULL))
- return -1;
- return 0;
- }
- struct sockaddr_in make_address(char *address, uint16_t port){
- struct sockaddr_in addr;
- struct hostent *hostinfo;
- addr.sin_family = AF_INET;
- addr.sin_port = htons (port);
- hostinfo = gethostbyname(address);
- if(hostinfo == NULL)HERR("gethostbyname");
- addr.sin_addr = *(struct in_addr*) hostinfo->h_addr;
- return addr;
- }
- void usage(char * name){
- fprintf(stderr,"USAGE: %s domain port operand1 operand2 operation \n",name);
- }
- int main(int argc, char** argv) {
- int fd;
- int32_t data[5];
- if(argc!=6) {
- usage(argv[0]);
- return EXIT_FAILURE;
- }
- // HERE
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement