IPv6 적용

Similar documents
The Pocket Guide to TCP/IP Sockets: C Version

The Pocket Guide to TCP/IP Sockets: C Version

The Pocket Guide to TCP/IP Sockets: C Version

vi 사용법

본 강의에 들어가기 전

본 강의에 들어가기 전

The Pocket Guide to TCP/IP Sockets: C Version

본 강의에 들어가기 전

The Pocket Guide to TCP/IP Sockets: C Version

Microsoft PowerPoint - 12 ¼ÒÄÏÀ» ÀÌ¿ëÇÑ Åë½Å 1.ppt

PowerPoint 프레젠테이션

bn2019_2

1217 WebTrafMon II

The Pocket Guide to TCP/IP Sockets: C Version

슬라이드 1

TCP.IP.ppt

Microsoft PowerPoint - Supplement-02-Socket Overview.ppt [호환 모드]

Microsoft PowerPoint - 02 IPv6 Operation.ppt [호환 모드]

제1장 Unix란 무엇인가?

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾

Network seminar.key

Microsoft Word - KPMC-400,401 SW 사용 설명서

Microsoft PowerPoint - 06-IPAddress [호환 모드]

IPv6Q 현배경 > 인터넷의급속한성장 -> IP 주소의고갈 개인휴대통신장치의보급 network TV, VOD 단말기등의인터넷연결 가정용품제어장치의인터넷연결 > 새로운 IP 로의이행문제 IPv4 호스트와의호환성문제를고려하여야합 ~ IPv4 의취약점보완 QoS 지원 인증

K&R2 Reference Manual 번역본

SYN flooding

ARMBOOT 1

Microsoft PowerPoint - IPv6-세미나.ppt

Sena Device Server Serial/IP TM Version

Microsoft PowerPoint - IPv6-세미나.ppt

2009년 상반기 사업계획

Subnet Address Internet Network G Network Network class B networ

PowerPoint 프레젠테이션

Microsoft PowerPoint - Lecture_Note_5.ppt [Compatibility Mode]

SMB_ICMP_UDP(huichang).PDF

TTA Verified : HomeGateway :, : (NEtwork Testing Team)

슬라이드 1

개요 IPv6 개요 IPv6 주소 IPv4와공존 IPv6 전환기술 (Transition Technologies)

<4D F736F F F696E74202D E20B3D7C6AEBFF6C5A920C7C1B7CEB1D7B7A1B9D62E >

제1장 Unix란 무엇인가?

<43B7CE20BECBBEC6BAB8B4C220BCD2C4CFC7C1B7CEB1D7B7A1B9D62E687770>

PWR PWR HDD HDD USB USB Quick Network Setup Guide xdsl/cable Modem PC DVR 1~3 1.. DVR DVR IP xdsl Cable xdsl Cable PC PC DDNS (

Microsoft Word doc


제20회_해킹방지워크샵_(이재석)

Microsoft PowerPoint - 13 ¼ÒÄÏÀ» ÀÌ¿ëÇÑ Åë½Å 2.ppt

Chapter11OSPF

PowerPoint 프레젠테이션

슬라이드 1

Microsoft Word - Network Programming_NewVersion_01_.docx


hd1300_k_v1r2_Final_.PDF

PowerPoint 프레젠테이션

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

슬라이드 제목 없음

Microsoft PowerPoint - 12_name&address.ppt

歯T1-4김병철2.PDF

Microsoft PowerPoint - MobileIPv6_김재철.ppt

IPv6 진화동기 인터넷접속노드증가에따른주소영역의 활장 사용자의다양한서비스욕구충족 실시간서비스, 멀티미디어서비스 보안및 인증서비스 IPng S pecifications IPv6 Specification - Intenet Protocol, Version 6(IPv6) S

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100

USB USB DV25 DV25 REC SRN-475S REC SRN-475S LAN POWER LAN POWER Quick Network Setup Guide xdsl/cable Modem PC DVR 1~3 1.. DVR DVR IP xdsl Cable xdsl C

3ÆÄÆ®-11

MPLAB C18 C

歯김병철.PDF

<C2F7BCBCB4EBC0CEC5CDB3DDC1D6BCD2C0DABFF8B1E2BCFAB5BFC7E2BAB8B0EDBCAD BFACB0A3BAB8B0EDBCAD292E687770>

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

ORANGE FOR ORACLE V4.0 INSTALLATION GUIDE (Online Upgrade) ORANGE CONFIGURATION ADMIN O

The Pocket Guide to TCP/IP Sockets: C Version

IPv6 CHADH

보안(KDN)

untitled

슬라이드 1

untitled

UDP Flooding Attack 공격과 방어

13주-14주proc.PDF

자바-11장N'1-502

SRC PLUS 제어기 MANUAL

강의10

11장 포인터

[ 네트워크 1] 3 주차 1 차시. IPv4 주소클래스 3 주차 1 차시 IPv4 주소클래스 학습목표 1. IP 헤더필드의구성을파악하고요약하여설명할수있다. 2. Subnet ID 및 Subnet Mask 를설명할수있고, 각클래스의사용가능한호스트수와사설 IP 주소및네트

소개 TeraStation 을 구입해 주셔서 감사합니다! 이 사용 설명서는 TeraStation 구성 정보를 제공합니다. 제품은 계속 업데이트되므로, 이 설명서의 이미지 및 텍스트는 사용자가 보유 중인 TeraStation 에 표시 된 이미지 및 텍스트와 약간 다를 수

시스코 무선랜 설치운영 매뉴얼(AP1200s_v1.1)

T100MD+

슬라이드 1


歯I-3_무선통신기반차세대망-조동호.PDF

Assign an IP Address and Access the Video Stream - Installation Guide

Chapter 4 UDP 소켓 사용법

Something that can be seen, touched or otherwise sensed

chap7.key

PowerPoint 프레젠테이션

슬라이드 제목 없음

Microsoft PowerPoint - 09-CE-23-윈도우 소켓

歯A1.1함진호.ppt

chapter4

rmi_박준용_final.PDF

Microsoft Word - FunctionCall

untitled

Microsoft PowerPoint - 2.Catalyst Switch Intrastructure Protection_이충용_V1 0.ppt [호환 모드]

6주차.key

Transcription:

IPv6 적용 1

IPv6 기본규격 2

IPv6 Basic header 3

IPv6 - Extension Headers (1) Hop-by-Hop Options (0) RSVP, PIM/MLD, etc. Routing (43) Source Routing, MIPv6 Fragment (44) Encapsulating Security Payload (50) IPsec Authentication Header (51) IPsec No Next Header (59) Destination Options (60) MIPv6 4

IPv6 - Extension Headers (2) Extension Header Order IPv6 header Hop-by-Hop Options header Destination Options header* Routing header Fragment header Authentication header Encapsulating Security Payload header Destination Options header* upper-layer header 5

IPv6 - Extension Headers (3) Two Options Hop-by-Hop Options header Destination Options header type-length-value (TLV) encoded Format if the processing IPv6 node does not recognize the Option Type: 00 - skip over this option and continue processing. 01/10/11 - discard the packet. 6

IPv6 주소체계 7

IPv6 - Three Types of Addresses Unicast An identifier for a single interface. A packet sent to a unicast address is delivered to the interface identified by that address Anycast An identifier for a set of interfaces. A packet sent to an anycast address is delivered to one of the interfaces identified by that address (the "nearest" one) Multicast An identifier for a set of interfaces A packet sent to a multicast address is delivered to all interfaces identified by that address. 8

IPv6 Addressing Model 128-bit addressing scheme x:x:x:x:x:x:x:x 'x's are the hexadecimal values of the eight 16-bit pieces of the address. "::" indicates multiple groups of 16 bits of zeros. 3FFE:2E01:0:0:0:31:0:21 -> 3FFE:2E01::31:0:21 ipv6-address/prefix-length 3FFE:0000:0000:CD30:0000:0000:0000:0000/64 3FFE::CD30:0:0:0:0/64 3FFE:0:0:CD30::/64 3FFE:0:0:CD3/64 (x) 3FFE::CD30/64 (x) 3FFE::CD3/64 (x) 9

IPv6 Address Type Representation Address type Binary prefix IPv6 notation Unspecified 00...0 (128 bits) ::/128 Loopback 00...1 (128 bits) ::1/128 Multicast 11111111 FF00::/8 Link-local unicast 1111111010 FE80::/10 Site-local unicast 1111111011 FEC0::/10 Global unicast (everything else) 10

IPv6 Unicast General Format n bits subnet prefix 128 - n bits Interface ID Unspecified address 0:0:0:0:0:0:0:0 = ::0 Loopback address 0:0:0:0:0:0:0:1 = ::1 IPv6 Addresses with Embedded IPv4 Addresses IPv4-compatible IPv6 address IPv4-mapped IPv6 address Global Unicast Addresses Local-Use IPv6 Unicast Addresses Link local address 11

IPv6 Address Auto-configuration 64-bit Interface Identifiers (eg., from 48-bit MAC) 0 0 1 5 1 6 3 1 3 2 4 7 cccccc0gcccccccc ccccccccmmmmmmmm mmmmmmmmmmmmmmmm 0 0 1 5 1 6 3 1 3 2 4 7 4 8 6 3 cccccc1gcccccccc cccccccc11111111 11111110mmmmmmmm mmmmmmmmmmmmmmmm 128-bit Address Auto-configuration subnet prefix + Interface ID ff fe 12

IPv6 Addresses with Embedded IPv4 Addresses IPv4-compatible IPv6 address For hosts and routers to dynamically tunnel IPv6 packets over IPv4 routing infrastructure ::203.232.252.110 80 bits 16 32 bits 0000...0000 0000 IPv4 address IPv4-mapped IPv6 address To represent the addresses of IPv4-only nodes as IPv6 addresses ::FFFF:203.232.252.110 80 bits 16 32 bits IPv4 0000...0000 ffff address 13

IPv6 Global Unicast Address General format n bits global routing prefix m bits subnet ID 128 n - m bits interface ID Current policy global routing prefix 4 8 subnet ID 6 4 interface ID 14

Local-Use IPv6 Unicast Addresses Link-Local addresses, fe80::/10 10 bits 54 bits 64 bits 1111111010 0 interface ID Site-Local addresses, fec0::/10 10 bits 38 bits 16 bits 64 bits 1111111011 0 subnet ID interface ID 15

IPv6 - A lot of Address Multiple unicast addresses to be assigned to interfaces Different Reachability Scope Link-local / site-local / global Privacy Considerations Public / temporary Mobility Home address / CoA Multi-homing situation Dual stack situation IPv4 addresses 16

IPv6 Address - Default Policy Table Implementations SHOULD be configurable, via mechanisms at least as powerful as these policy tables. If not configured, then they SHOULD operate according to the default policy table: Prefix Precedence Label ::1/128 50 0 ::/0 40 1 2002::/16 30 2 ::/96 20 3 ::ffff:0:0/96 10 4 17

Source Address Selection Selecting IPv6 source for IPv6 destination: Prefer same address (for loopback). Prefer appropriate scope. Avoid deprecated addresses. Prefer home addresses over care-of addresses. Prefer source assigned to originating interface. Prefer matching label from policy table. Prefer public addresses. Use longest-matching-prefix. 18

Destination Address Ordering Select best source for each destination, IPv6 and IPv4: Avoid unusable destinations. Prefer matching scope. Avoid deprecated source addresses. Prefer home source addresses. Prefer matching label from policy table. Prefer destinations with higher precedence. Prefer smaller scope destinations. Use longest-matching-prefix. Otherwise, leave order from DNS unchanged 19

IPv6 소켓프로그래밍 20

IPv4 주소 주요구조체검토 (1) /* Internet address. */ struct in_addr { be32 s_addr; }; struct sockaddr_in { kernel_sa_family_t sin_family; /* Address family */ be16 sin_port; /* Port number */ struct in_addr sin_addr; /* Internet address */ /* Pad to size of `struct sockaddr'. */ unsigned char pad[ SOCK_SIZE - sizeof(short int) - sizeof(unsigned short int) - sizeof(struct in_addr)]; }; 21

IPv6 주소 주요구조체검토 (2) /* * IPv6 address structure */ struct in6_addr { union { u8 be16 be32 } in6_u; #define s6_addr #define s6_addr16 #define s6_addr32 }; u6_addr8[16]; u6_addr16[8]; u6_addr32[4]; in6_u.u6_addr8 in6_u.u6_addr16 in6_u.u6_addr32 struct sockaddr_in6 { unsigned short int sin6_family; /* AF_INET6 */ be16 sin6_port; /* Transport layer port # */ be32 sin6_flowinfo; /* IPv6 flow information */ struct in6_addr sin6_addr; /* IPv6 address */ u32 sin6_scope_id; /* scope id (new in RFC2553) */ }; 22

주요구조체검토 (3) 범용주소형식 struct sockaddr { SOCKADDR_COMMON (sa_); /* Common data: address family and length. */ char sa_data[14]; /* Address data. */ }; /* Structure large enough to hold any socket address (with the historical exception of AF_UNIX). We reserve 128 bytes. */ #define ss_aligntype unsigned long int #define _SS_SIZE 128 #define _SS_PADSIZE (_SS_SIZE - (2 * sizeof ( ss_aligntype))) struct sockaddr_storage { SOCKADDR_COMMON (ss_); /* Address family, etc. */ ss_aligntype ss_align; /* Force desired alignment. */ char ss_padding[_ss_padsize]; }; 23

이진 / 문자열주소변환함수 (1) IPv4 #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int inet_aton(const char *cp, struct in_addr *inp); unsigned long int inet_addr(const char *cp); unsigned long int inet_network(const char *cp); char *inet_ntoa(struct in_addr in); struct in_addr inet_makeaddr(int net, int host); unsigned long int inet_lnaof(struct in_addr in); unsigned long int inet_netof(struct in_addr in); 24

이진 / 문자열주소변환함수 (2) IPv4/IPv6 #include <arpa/inet.h> int inet_pton(int af, const char *src, void *dst); const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); char clntname[inet6_addrstrlen]; // Array to contain client address string if (inet_ntop(af_inet6, &clntaddr.sin6_addr.s6_addr, clntname, sizeof(clntname))!= NULL) printf("handling client %s\n", clntname); 25

도메인네임서비스이용 (1) 관련구조체 /* Structure to contain information about address of a service provider. */ struct addrinfo { int ai_flags; /* Input flags. */ int ai_family; /* Protocol family for socket. */ int ai_socktype; /* Socket type. */ int ai_protocol; /* Protocol for socket. */ socklen_t ai_addrlen; /* Length of socket address. */ struct sockaddr *ai_addr; /* Socket address for socket. */ char *ai_canonname; /* Canonical name for service location. */ struct addrinfo *ai_next; /* Pointer to next in list. */ }; 26

도메인네임서비스이용 (2) 관련함수 #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res); void freeaddrinfo(struct addrinfo *res); const char *gai_strerror(int errcode); 27

도메인네임서비스이용 (3) getaddrinfo () 이용예제 // Tell the system what kind(s) of address info we want struct addrinfo addrcriteria; // Criteria for address match memset(&addrcriteria, 0, sizeof(addrcriteria)); // Zero out structure addrcriteria.ai_family = AF_UNSPEC; // Any address family addrcriteria.ai_socktype = SOCK_STREAM; // Only stream sockets addrcriteria.ai_protocol = IPPROTO_TCP; // Only TCP protocol // Get address(es) associated with the specified name/service struct addrinfo *addrlist; // Holder for list of addresses returned // Modify servaddr contents to reference linked list of addresses int rtnval = getaddrinfo(addrstring, portstring, &addrcriteria, &addrlist); if (rtnval!= 0) fprintf(stderr, "getaddrinfo() failed : %s", gai_strerror(rtnval)); // Display returned addresses for (struct addrinfo *addr = addrlist; addr!= NULL; addr = addr->ai_next) { PrintSocketAddress(addr->ai_addr, stdout); } freeaddrinfo(addrlist); // Free addrinfo allocated in getaddrinfo() 28

V6 용 TCP 클라이언트예제 (1) SetupTCPClient6Socket() 호스트이름으로 DNS 질의후결과로반환된 IPv6 주소로연결 (connect) int SetupTCPClient6Socket(const char *host, const char *service) { // Tell the system what kind(s) of address info we want struct addrinfo addrcriteria; // Criteria for address match memset(&addrcriteria, 0, sizeof(addrcriteria)); // Zero out structure addrcriteria.ai_family = AF_INET6 ; // IPv6 address family addrcriteria.ai_socktype = SOCK_STREAM; // Only streaming sockets addrcriteria.ai_protocol = IPPROTO_TCP; // Only TCP protocol // Get address(es) struct addrinfo *servaddr; // Holder for returned list of server addrs int rtnval = getaddrinfo(host, service, &addrcriteria, &servaddr); if (rtnval!= 0) fprintf(stderr, "getaddrinfo() failed : %s", gai_strerror(rtnval)); 29

V6 용 TCP 클라이언트예제 (2) SetupTCPClient6Socket() ( 계속 ) int sock = -1; for (struct addrinfo *addr = servaddr; addr!= NULL; addr = addr->ai_next) { // Create a reliable, stream socket using TCP sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); if (sock < 0) continue; // Socket creation failed; try next address // Establish the connection to the echo server if (connect(sock, addr->ai_addr, addr->ai_addrlen) == 0) break; // Socket connection succeeded; break and return socket } close(sock); // Socket connection failed; try next address sock = -1; freeaddrinfo(servaddr); // Free addrinfo allocated in getaddrinfo() } return sock; 30

범용 TCP 클라이언트예제 (1) SetupTCPClientSocket() 호스트이름으로 DNS 질의후결과로반환된 IPv4 또는 IPv6 주소로연결 (connect) int SetupTCPClientSocket(const char *host, const char *service) { // Tell the system what kind(s) of address info we want struct addrinfo addrcriteria; // Criteria for address match memset(&addrcriteria, 0, sizeof(addrcriteria)); // Zero out structure addrcriteria.ai_family = AF_UNSPEC; // v4 or v6 is OK addrcriteria.ai_socktype = SOCK_STREAM; // Only streaming sockets addrcriteria.ai_protocol = IPPROTO_TCP; // Only TCP protocol // Get address(es) struct addrinfo *servaddr; // Holder for returned list of server addrs int rtnval = getaddrinfo(host, service, &addrcriteria, &servaddr); if (rtnval!= 0) fprintf(stderr, "getaddrinfo() failed : %s", gai_strerror(rtnval)); 31

범용 TCP 클라이언트예제 (2) SetupTCPClientSocket() ( 계속 ) int sock = -1; for (struct addrinfo *addr = servaddr; addr!= NULL; addr = addr->ai_next) { // Create a reliable, stream socket using TCP sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); if (sock < 0) continue; // Socket creation failed; try next address // Establish the connection to the echo server if (connect(sock, addr->ai_addr, addr->ai_addrlen) == 0) break; // Socket connection succeeded; break and return socket } close(sock); // Socket connection failed; try next address sock = -1; freeaddrinfo(servaddr); // Free addrinfo allocated in getaddrinfo() } return sock; 32

V6 용 TCP 서버예제 (1) SetupTCPServer6Socket() DNS 질의를통해얻어진 IPv6 또는 IPv4 주소로바인딩 int SetupTCPServer6Socket(const char *service) { // Construct the server address structure struct addrinfo addrcriteria; // Criteria for address match memset(&addrcriteria, 0, sizeof(addrcriteria)); // Zero out structure addrcriteria.ai_family = AF_INET6; // IPv6 address family addrcriteria.ai_flags = AI_PASSIVE; // Accept on any address/port addrcriteria.ai_socktype = SOCK_STREAM; // Only stream sockets addrcriteria.ai_protocol = IPPROTO_TCP; // Only TCP protocol struct addrinfo *servaddr; // List of server addresses int rtnval = getaddrinfo(null, service, &addrcriteria, &servaddr); if (rtnval!= 0) fprintf(stderr, "getaddrinfo() failed : %s", gai_strerror(rtnval)); 33 int servsock = -1; for (struct addrinfo *addr = servaddr; addr!= NULL; addr = addr->ai_next) { // Create a TCP socket servsock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); if (servsock < 0) continue; // Socket creation failed; try next address

V6 용 TCP 서버예제 (2) SetupTCPServer6Socket() ( 계속 ) // Bind to the local address and set socket to listen if ((bind(servsock, addr->ai_addr, addr->ai_addrlen) == 0) && (listen(servsock, MAXPENDING) == 0)) { // Print local address of socket struct sockaddr_in6 localaddr; socklen_t addrsize = sizeof(localaddr); if (getsockname(servsock, (struct sockaddr *) &localaddr, &addrsize) < 0) fprintf(stderr, "getsockname() failed"); } break; // Bind and listen successful } close(servsock); // Close and try again servsock = -1; 34 } // Free address list allocated by getaddrinfo() freeaddrinfo(servaddr); return servsock;

V6 용 TCP 서버예제 (3) AcceptTCPConnection6() 클라이언트와연결설정 int AcceptTCPConnection6(int servsock) { struct sockaddr_in6 clntaddr; // Client address // Set length of client address structure (in-out parameter) socklen_t clntaddrlen = sizeof(clntaddr); // Wait for a client to connect int clntsock = accept(servsock, (struct sockaddr *) &clntaddr, &clntaddrlen); if (clntsock < 0) fprintf(stderr, "accept() failed"); // clntsock is connected to a client! } return clntsock; 35

범용 TCP 서버예제 (1) SetupTCPServerSocket() DNS 질의를통해얻어진 IPv6 또는 IPv4 주소로바인딩 int SetupTCPServerSocket(const char *service) { // Construct the server address structure struct addrinfo addrcriteria; // Criteria for address match memset(&addrcriteria, 0, sizeof(addrcriteria)); // Zero out structure addrcriteria.ai_family = AF_UNSPEC; // Any address family addrcriteria.ai_flags = AI_PASSIVE; // Accept on any address/port addrcriteria.ai_socktype = SOCK_STREAM; // Only stream sockets addrcriteria.ai_protocol = IPPROTO_TCP; // Only TCP protocol struct addrinfo *servaddr; // List of server addresses int rtnval = getaddrinfo(null, service, &addrcriteria, &servaddr); if (rtnval!= 0) fprintf(stderr, "getaddrinfo() failed : %s", gai_strerror(rtnval)); 36 int servsock = -1; for (struct addrinfo *addr = servaddr; addr!= NULL; addr = addr->ai_next) { // Create a TCP socket servsock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); if (servsock < 0) continue; // Socket creation failed; try next address

범용 TCP 서버예제 (2) SetupTCPServerSocket() ( 계속 ) // Bind to the local address and set socket to listen if ((bind(servsock, addr->ai_addr, addr->ai_addrlen) == 0) && (listen(servsock, MAXPENDING) == 0)) { // Print local address of socket struct sockaddr_storage localaddr; socklen_t addrsize = sizeof(localaddr); if (getsockname(servsock, (struct sockaddr *) &localaddr, &addrsize) < 0) fprintf(stderr, "getsockname() failed"); } break; // Bind and listen successful } close(servsock); // Close and try again servsock = -1; 37 } // Free address list allocated by getaddrinfo() freeaddrinfo(servaddr); return servsock;

범용 TCP 서버예제 (3) AcceptTCPConnection() 클라이언트와연결설정 int AcceptTCPConnection(int servsock) { struct sockaddr_storage clntaddr; // Client address // Set length of client address structure (in-out parameter) socklen_t clntaddrlen = sizeof(clntaddr); // Wait for a client to connect int clntsock = accept(servsock, (struct sockaddr *) &clntaddr, &clntaddrlen); if (clntsock < 0) fprintf(stderr, "accept() failed"); // clntsock is connected to a client! } return clntsock; 38

Scope_id 설정 (1) Link-local 주소를이용하는경우 sockaddr_in6 구조체의 scope_id 멤버설정필요 하나의호스트에여러개의인터페이스가있을수있고, 따라서어떤인터페이스를이용할지 scope_id 로명시 상대방주소 ( 인터페이스 ) 와함께있는인터페이스명시 if_nameindex 활용 모든네트워크인터페이스와인덱스반환 #include <net/if.h> struct if_nameindex *if_nameindex(void); 사용후에는반드시 if_freenameindex() 를이용하여메모리를반환시켜야함 관련함수들 if_indextoname() if_nametoindex() 39

Scope_id 설정 (2) if_nameindex 활용예제 if_name_to_scope_id() 자체제작 #include <net/if.h> 인터페이스이름을받아들여, 시스템내에있는인터페이스이름과비교하여이름에해당하는인덱스반환 int if_name_to_scope_id(const char *if_name) { int scope_id = -1; struct if_nameindex *if_idx, *ifp; if_idx = if_nameindex(); for (ifp = if_idx; ifp->if_name!= NULL; ifp++) { if (!strcmp(if_name, ifp->if_name)) { scope_id = ifp->if_index; } } if_freenameindex(if_idx); } return (scope_id); 40

Scope_id 설정 (3) if_name_to_scope_id( ) 사용예제 인터페이스이름이존재하는경우 if_name_to_scope_id( ) 호출... sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); if (sock < 0) continue; // Socket creation failed; try next address struct sockaddr_in6 *sin = (struct sockaddr_in6 *)addr->ai_addr; if (if_name) { // not NULL int scope_id; }... if ((scope_id = if_name_to_scope_id(if_name)) >= 0) { sin->sin6_scope_id = scope_id; } else { fprintf(stderr, "Cannot find the scope_id of %s\n", if_name); close (sock); sock = -1; } 41

ifconfig -a 시스템인터페이스확인 eno1: flags=4163<up,broadcast,running,multicast> mtu 1500 inet 203.232.252.110 netmask 255.255.255.0 broadcast 203.232.252.255 inet6 fe80::ae16:2dff:fe89:32a4 prefixlen 64 scopeid 0x20<link> ether ac:16:2d:89:32:a4 txqueuelen 1000 (Ethernet) RX packets 31363186 bytes 22288924843 (20.7 GiB) RX errors 0 dropped 61760 overruns 0 frame 0 TX packets 18906148 bytes 11237679682 (10.4 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 32... lo: flags=73<up,loopback,running> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 1452812 bytes 22080139786 (20.5 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1452812 bytes 22080139786 (20.5 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<up,broadcast,multicast> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:3b:95:15 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 42