Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <string.h>
- #define PORT 0x1234
- /* REPLACE with your server machine name*/
- #define HOST "Unix-machine"
- #define DIRSIZE 8192
- main(argc, argv)
- int argc; char **argv;
- {
- char hostname[100];
- char dir[DIRSIZE];
- int sd;
- struct sockaddr_in sin;
- struct sockaddr_in pin;
- struct hostent *hp;
- strcpy(hostname,HOST);
- if (argc>2)
- { strcpy(hostname,argv[2]); }
- /* go find out about the desired host machine */
- if ((hp = gethostbyname(hostname)) == 0) {
- perror("gethostbyname");
- return 1 ;
- }
- /* fill in the socket structure with host information */
- memset(&pin, 0, sizeof(pin));
- pin.sin_family = AF_INET;
- pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
- pin.sin_port = htons(PORT);
- /* Client-A */
- if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
- perror("socket");
- return 1;
- }//if socket sd is equal to -1, print out an error for "socket"
- /* Client-B */
- if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) {
- perror("connect");
- return 1;
- }//if connect is -1, print error for "connect"
- /* Client-C */
- if (send(sd, argv[1], strlen(argv[1]), 0) == -1) {
- perror("send");
- return 1;
- }//if send = -1 print error "send"
- /* Client-D */
- if (recv(sd, dir, DIRSIZE, 0) == -1) {
- perror("recv");
- return 1;
- }//if recv = -1 print error message "recv"
- /* Client-E */
- printf("%s\n", dir);
- //print name of dir
- close(sd);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement