목록분류 전체보기 (318)
printf("ho_tari\n");
#include #include #include #include void error_handling(char *message); int main(int argc, char *argv[]) { int sock; int snd_buf, rcv_buf, state; socklen_t len; sock=socket(PF_INET, SOCK_STREAM, 0); len=sizeof(snd_buf); state=getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void*)&snd_buf, &len); if(state) error_handling("getsockopt() error"); len=sizeof(rcv_buf); state=getsockopt(sock, SOL_SOCKET, SO_R..
#include #include #include #include #include void error_handling(char *message); int main(int argc, char *argv[]) { int i; struct hostent *host; if(argc!=2) { printf("Usage : %s \n", argv[0]); exit(1); } host=gethostbyname(argv[1]); if(!host) error_handling("gethost... error"); printf("Official name: %s \n", host->h_name); for(i=0; host->h_aliases[i]; i++) printf("Aliases %d: %s \n", i+1, host->..
#include #include #include #include #include #include #define BUF_SIZE 1024 void error_handling(char *message); int main(int argc, char *argv[]) { int sock; char message[BUF_SIZE]; int str_len, recv_len, recv_cnt; struct sockaddr_in serv_adr; if (argc != 3) { printf("Usage : %s \n", argv[0]); exit(1); } // 소켓 생성 sock = socket(PF_INET, SOCK_STREAM, 0); if (sock == -1) error_handling("socket() err..
#include #include #include #include #include #include #define BUF_SIZE 1024 void error_handling(char *message); int main(int argc, char *argv[]) { int serv_sock, clnt_sock; char message[BUF_SIZE]; int str_len, i; struct sockaddr_in serv_adr; struct sockaddr_in clnt_adr; socklen_t clnt_adr_sz; if(argc!=2) { printf("Usage : %s \n", argv[0]); exit(1); } serv_sock=socket(PF_INET, SOCK_STREAM, 0); if..
#include #include int main(int argc, char *argv[]) { char *addr1="127.212.124.78";// 0x4E7CD47F(78.124.212.127) char *addr2="127.212.124.255"; unsigned long conv_addr=inet_addr(addr1); if(conv_addr==INADDR_NONE) printf("Error occured! \n"); else printf("Network ordered integer addr: %#lx \n", conv_addr); conv_addr=inet_addr(addr2); if(conv_addr==INADDR_NONE) printf("Error occureded \n"); else pr..
#include #include int main(int argc, char *argv[]) { unsigned short host_port=0x1234; unsigned short net_port; unsigned long host_addr=0x12345678; unsigned long net_addr; net_port=htons(host_port); net_addr=htonl(host_addr); printf("Host ordered port: %#x \n", host_port); printf("Network ordered port: %#x \n", net_port); printf("Host ordered address: %#lx \n", host_addr); printf("Network ordered..
#include #include #include #include #include #include void error_handling(char *message); int main(int argc, char *argv[]) { int serv_sock; int clnt_sock; struct sockaddr_in serv_addr; struct sockaddr_in clnt_addr; socklen_t clnt_addr_size; char message[]="Hello World!"; if(argc!=2){ printf("Usage : %s \n", argv[0]); exit(1); } serv_sock=socket(PF_INET, SOCK_STREAM, 0); if(serv_sock == -1) error..
#include #include #include #include #define BUF_SIZE 100 void error_handling(char* message); int main(void) { int fd; char buf[BUF_SIZE]; fd=open("data.txt", O_RDWR);//read, write 모두 사용가능 if( fd==-1) error_handling("open() error!"); printf("file descriptor: %d \n" , fd); if(read(0, buf, sizeof(buf))==-1)// 0 : 입력 error_handling("read() error!"); if(write(fd, buf, sizeof(buf))==-1) error_handling..