Page 75 - 2578
P. 75

}
                            }

                            socketclient:
                            #include <sys/types.h>
                            #include <sys/socket.h>
                            #include <sys/un.h>
                            #include <errno.h>
                            #define MAXBUF 256
                            #define FILE "echo.serv"
                            #define NULL    0
                            char *msg = "Hello world!";
                            char buf[MAXBUF];
                            main()
                            {
                                struct sockaddr_un serv_addr, clnt_addr;
                                int sockfd;
                                int saddrlen, caddrlen, msglen, n;
                                bzero(&serv_addr, sizeof(serv_addr));
                                serv_addr.sun_family = AF_UNIX;
                                strcpy(serv_addr.sun_path, FILE);

                            saddrlen=sizeof(serv_addr.sun_family)+strlen(serv_add
                            r.sun_path);
                                if((sockfd = socket(AF_UNIX, SOCK_DGRAM, 0)) <
                            0){
                                    printf("Nemozhlyvo stvoryty' socket\n");
                                    exit(1);
                                }
                                bzero(&clnt_addr, sizeof(clnt_addr));
                                clnt_addr.sun_family = AF_UNIX;
                                strcpy(clnt_addr.sun_path, FILE);
                                mktemp(clnt_addr.sun_path);

                            caddrlen=sizeof(clnt_addr.sun_family)+strlen(clnt_add
                            r.sun_path);
                                if(bind(sockfd, (struct sockaddr*)&clnt_addr,
                            caddrlen) < 0){
                                    printf("Pomylka svyazuvannya socketa\n");
                                    exit(1);
                                                           74
   70   71   72   73   74   75   76   77   78