목록TCP IP 소켓 프로그래밍 (13)
printf("ho_tari\n");
#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..
#include #include #include #include void error_handling(char* message); int main(void) { int fd; char buf[]="Let's go!\n"; fd=open("data.txt", O_CREAT|O_WRONLY|O_TRUNC); if(fd==-1) error_handling("open() error!"); printf("file descriptor: %d \n", fd); if(write(fd, buf, sizeof(buf))==-1) error_handling("write() error!"); close(fd); return 0; } void error_handling(char* message) { fputs(message, s..
#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..