1 / 30

6

3.4 ?? ??. ??? ???? ?? ?? ??setsockopt() ??? ??? ?? ?? ??int getsockopt(int s, int level, int opt, const char *optval, int len);getsockopt() ??? ??? ?? ?? ??int setsockopt(int s, int level, int opt, const char *optval, int *optlen);. 3.4 ?? ??. level :

satya
Download Presentation

6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. ????? 6? 3. ?? ?? ????? 3.4 ?? ?? 3.5 ????? P/G 3.6 ??? ?? ?? ??

    2. 3.4 ?? ?? ??? ???? ?? ?? ?? setsockopt() ??? ??? ?? ?? ?? int getsockopt(int s, int level, int opt, const char *optval, int len); getsockopt() ??? ??? ?? ?? ?? int setsockopt(int s, int level, int opt, const char *optval, int *optlen);

    3. 3.4 ?? ?? level : ???? ??? ?? SOL_SOCKET - ??? ???? ?? ?? IPPROTO_IP - IP ????? ?? ? IPPROTO_TCP - TCP? ?? ?? opt : ??? ??? ?? optval : ?? ??? ??? ?? ??? *optlen : *optval? ??

    4. 3.4 ?? ??

    5. 3.4.2 ???? ??? ?? SO_REUSEADDR ???? ??? ?? ??? ????(IP ??? ?? ??)? ?? ????? ??? ???? ?? ?? ??? ????(IP ??? ?? ??)? ? ???? ?? ?? ???? ????  ???? ?? ??

    6. 3.4.2 ???? ??? ?? TCP ?? ?????? ?? ????? ???? ???? ?? ??? ?? ????? ?????? ?? ???? ?? "?? ??? ???"??? ??? ?? ??? ??? ??? ??? TCP ???? fork()? ???? ???? ?? ?? ??(?, ?? ????)? ???? ? ??? ??? ??

    7. 3.4.2 ???? ??? ?? ?? ?? ??? ????? IP ??? ?? ?? ??? ? ??? ??? ?? ? ???? ? ?? IP ??? ?? ?? (multihomed) ????? ??? ?? ??? ???? ??(?? ?? ?? ??? 80? HTTP ??)? ?? ? ???? ? ?? ??? ?????? ?? ??? ???? ?? ?? ?? ??? ????? ? ? ??

    8. 3.4.2 ???? ??? ?? ?? ??????(?? ? ???? ?? ?? ????) ??? IP ??? ?? ??? bind()?? ?? ??? ? ?? TCP??? ??? ? ?? UDP??? ?? ?? ???? ?? ?? ????? ??? ???? ?? ??

    9. 3.5.1 ????? ?? ????? (Multicast) ??? ??? ??? ????? ?? class D ??? ?? ??? ????? ?????? ???? ? UDP ?? ?? IGMP? ?? ??? ?? ?? ?? TTL? ?? ?? ??

    10. 3.5.1 ????? ?? ?????(multicast) ??? ??? ??? ???? ??? ???? ?? ????? ?? ?????? ???? ??? ??? D? IP ??? ?? ?? ????? ???? ??? ????? ? ?? ??? UDP ??? ??

    11. 3.5.1 ????? ?? ??? ????? MRP(Multicast Routing Protocol)? ?? ??? ???? ????? ??? ???? ???? ??? ????? ????? IGMP ???? ??? ????? ??? ??? ?? ?? IGMP( Internet Group Management Protocol) ~ ??? ???? UDP ??? ??? ???? ?????? ???? ???? ????? ??? ???? UDP ???? ?????? ??? ??, ?? ?? ?? ????? ???. ????? ??? ??? ?? ?????? ????? ??? ??? ? ??.

    12. 3.5.1 ????? ?? ????? ?? ?? TTL ?? ?? Time To Live ??? ??? ??? ????? 1? ?? 0??? ??????? ?? TTL? ????? ?? ????? ???? ??? ?? ?? ??? ???? ??? ???? ?? ?? ??

    13. 3.5.1 ????? ?? ?????? ????? ??? ???? ??? ?? 24??? (hexa)01005e? ?? ????? IP ?? ? ?? 23??? ??? ??? ?? 23??? ?? ???? 239.3.3.3??? ????? ??? ??(join)???? ??? ??? ??? ??? 01 00 5e 03 03 03? ??? ???? ? ???? ?? ??

    14. 3.5.2 ????? P/G ?? ?????? ??? ?? ?? IP_ADD_MEMBERSHIP ????? ??? ?? IP_DROP_MEMBERSHIP ????? ???? ?? IP_MULTICAST_LOOP ????? ??? loopback ?? ?? ?? IP_MULTICAST_TTL ????? ??? TTL ? ?? IP_MULTICAST_IF ????? ?? ??? ????? ??

    15. 3.5.2 ????? P/G ?? ????? ??? ????? ??? ?? ?? ?? ????? ?? ??? ???? ??? ip_mreq ?? struct ip_mreq { struct in_addr imr_multiaddr;/* ????? ?? ??*/ struct in_addr imr_interface;/* ??? IP ?? */ }

    16. 3.5.2 ????? P/G ?? ????? ?? ?? ????? ??? ?? mcast_group? ????? ?? ??? ???? ???? ??? ip_mreq ???? ????? ?? ?? mcast_group ? IP ??? ?? ??? ?????? ???? IP ?? INADDR_ANY? ??

    17. 3.5.2 ????? P/G ?? struct sockaddr_in mcast_group; struct ip_mreq mreq; /* ????? ?? ?? ?? */ memset(&mcast_group, 0, sizeof(mcast_group)); mcast_group.sin_family = AF_INET; mcast_group.sin_port = htons(atoi(argv[2])); mcast_group.sin_addr.s_addr = inet_addr(argv[1]); /* ip_mreq ??? ?? */ mreq.imr_multiaddr = mcast_group.sin_addr; mreq.imr_interface.s_addr = htonl(INADDR_ANY);

    18. 3.5.2 ?????P/G?? UDP ??? ?? ????? ??? ??(join) ??? ????? ??? ?? ?? /* ??? UDP ?? ?? */ recv_s=socket(AF_INET, SOCK_DGRAM, 0); /* ????? ??? ?? */ setsockopt(recv_s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); /* ?? ??? ?? ?? */ unsigned int set = 1; setsockopt(recv_s, SOL_SOCKET, SO_REUSEADDR, &set, sizeof(set)); /* ?? ??? */ bind(recv_s, (struct sockaddr*)&mcast_group, sizeof(mcast_group));

    19. 3.5.2 ?????P/G?? ????? ?? ?? UDP ?? ?? ? ?? ????? ??? ??? ??? ?? /* ??? ?? ?? */ send_s=socket(AF_INET, SOCK_DGRAM, 0); /* ????? ??? ?? */ char msg [MAXLINE+1]; /* ??? ??? */ sendto(send_s,msg,strlen(msg), 0, (struct sockaddr*)&mcast_group, sizeof(mcast_group));

    20. 3.5.2 ?????P/G?? ????? ??? ???? loopback?? loopback? ??? ??? setsockopt()? ???? loopback ??? ?? int no = 0; setsockopt(send_s, IPPROTO_IP, IP_MULTICAST_LOOP, &no, sizeof(no)); ????? ??? TTL ?? ???? 1 ?? LAN ?? ?????? ?? TTL ?? 32, 62, 128 ??? ???? setsockopt() int ttl = 32; setsockopt(send_s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));

    21. 3.5.2 ?????P/G?? IP_MULTICAST_IF ?? ????? ??? ??? IP ??? ???? ??? IP ??? ?? ?? ??? ??? ? ??

    22. 3.5.3 ????? ?? P/G ??? ?????? ?? ???? ? ?? ???? ?? ?? ?? ?????? ???? ?????? ?? ?? ??? UDP ??? ?? ????? ??? ?? ?? ??? ?? ??? bind()? ?? ??? UDP ??? ?? fork()? ?? ?? ????? ?? ???? ??? ?? ?? ????? ??? ?? ? ??? ??? ??

    23. 3.6 ??? ?? ?? ?? ??(daemon) ????? ??? ?? ?? inetd ?? ??

    24. 3.6.1 ?? ?? ??? ????? ??? ?? ??? ?????? ?? ?? ??? ????? ?, ??? ??? ??? ? ?? ??? ?? ?? ??? ??. ?? ????? ?? ?? TCP ?? UDP? ???? ??? ?? ?? ??? ??. ??? UDP? ????? ??? ??? ???? ???? ??? ?? ?? ??? ?? ????? ?? ??? ?? ?? ??? ?? ??? ???? ????? ????? ????? ???? ?? ? ??? ?? ????? ?? ???? ????? ???? ?? ??

    25. 3.6.2 daemon? ??? ?? ?? daemon? ?? ?????? ?? ???? ??? ?? ?? daemon ?? ? if ((pid = fork()) != 0) exit(0); /* ?? ???? ?? */ setsid(); /* ?? ?? ?? */ signal(SIGHUP, SIG_IGN); /* SIGHUP ??? ?? */ if ((pid = fork()) != 0) exit(0); chdir(“/”); /* ???? ?? */ for (i=0 ; i<MAXFD ; i++) /* ???? ??? ?? */ close(i); /* ??? ??? */

    26. 3.6.2 daemon? ??? ?? ?? fork()? ?? ?? ????? ??? ?? ????? ?? setsid()? ???? ??(?? ????)? ??? ???? ??? ??? ??? ??? ??? ??? ??? PID?? ??? ?? ?? ?? ????? ? ??? ??? ??? ??? ?? ????? ??? ??? ?? ?? umask? 0?? ?? ?? ???? ??? ????? ??? ????? ???. ?? ??? ?????? ??? ??? ?? ???.

    27. 3.6.2 daemon? ??? ?? ?? ??? ???? ???? ?? ???? ???? ???? fprintf() ?? ??? ??? ? ?? ???? ???? ?? ?? ???? ???? syslog ??? ???? ?? ??? ?? ??

    28. 3.6.3 inetd? ??? ?? ?? inetd ?? superserver?? ? inetd? ??? ??? ???? ??? ?? telnet, ftp?? ??? /etc/inetd.conf ?? ?? ?? /etc/services ?? ?? ?? ?? ??? ??? ? ?? ?? ??(root) ?? ??

    29. 3.6.3 inetd? ??? ?? ?? inetd superserver ???? ??? ??? ??? ??? ??? ?? ??? ?? inetd? echo, daytime? ?? ??? ??? ?? ?? ?? telnet, ftp? ?? ???? ??? ????? ??? ???? ???? ?? sendmail? httpd? ?? ???? inetd? ???? ?? ??? ???? ??

    30. 3.6.3 inetd? ??? ?? ?? ???? ?? ?? ????? inetd? ??? ?? ????? ?? ?? ???? ?? ?? ????? /etc/services ??? ??? ?? ?? myecho_service 5000/tcp inetd? ??? ? ???? ??? ? ??? /etc/inetd.conf? ?? ?? ?? myecho_service stream tcp nowait root /root/myecho_service myecho_service inetd? ??? ?? ??????? ?? ??, ????? ?? ??? ?? ??? ??? ??? inetd? ?? ??? ?? ????.

More Related