'Network' 카테고리의 다른 글
[Network/ARP] ARP Request/Reply (0) | 2016.06.25 |
---|---|
[Network/Ethernet] EthernetII header (0) | 2016.06.21 |
[Network/libtins] Sending ARP, ICMP Packet with libtins (0) | 2016.06.21 |
[Network/ARP] ARP Request/Reply (0) | 2016.06.25 |
---|---|
[Network/Ethernet] EthernetII header (0) | 2016.06.21 |
[Network/libtins] Sending ARP, ICMP Packet with libtins (0) | 2016.06.21 |
-ARP Request/Reply-
[ Hardware Type ]
Size : 2 Bytes
Offset : 0 ~ 1
[ Protocol Type ]
Size : 2 Bytes
Offset : 2 ~ 3
[ Hardware Length ]
Size : 1 Bytes
Offset : 4
[ Protocol Length ]
Size : 1 Bytes
Offset : 5
[ Operation ]
Size : 2 Bytes
Offset : 6 ~ 7
[ Sender Hardware Address ]
Size : 6 Bytes
Offset : 8 ~ 13
[ Sender IP Address ]
Size : 4 Bytes
Offset : 14 ~ 17
[ Target Hardware Address ]
Size : 6 Bytes
Offset : 18 ~ 23
[ Target IP Address ]
Size : 4 Bytes
Offset : 24 ~ 27
Hardware Type / Protocol Type :각각 네트워크 유형과 프로토콜을 정의하며, Hardware Type의 경우 Ethernet은 0x0001을 세팅하고 Protocol Type의 경우 IPv4는 0x0800을 세팅하게 됨
Hardware Length / Protocol Length : 각각 MAC주소와 IP주소의 길이를 설정하며, MAC주소의 경우 0x06에서 바뀌는 경우가 없고 Protocol Length의 경우 IPv4일 경우에는 0x04를 세팅하게 됨
Operation : Request Packet의 경우 0x0001을, Reply Packet의 경우 0x0002를 세팅하게 됨
Sender/Target Hardware/IP Address :각각 발신지/목적지의 MAC/IP주소를 명시하며, ARP Request의 경우에는 Target Hardware Address필드를 0x000000000000으로 세팅해서 보내게 됨
[ ARP ]
ARP (Address Resolution Protocol)은 추상적인 주소인 IP주소를 실제 통신에 쓸 수 있는 H/W주소(MAC)으로 변경하는데 필요한 프로토콜이다.
상대방의 IP를 알지만, MAC을 알지 못할 때 Broadcast를 통해 Request를 보내면, 해당 IP를 소유하고 있는 시스템은 자신의 MAC주소를 채워, Request를 한 시스템에게 Unicast방식으로 Reply를 보내게 된다.
Reply를 받은 시스템은 Reply의 Sender Hardware Address필드에서 MAC주소를 알아낼 수 있다.
[ Example ]
A (MAC : 00:1b:78:7b:5d:8c, IP : 192.168.0.1)
B (MAC : 00:13:77:bd:2d:5c, IP : 192.168.0.2)
이 상황에서, A가 B의 IP주소(192.168.0.2)를 알고, H/W주소를 모를경우 다음과 같은 과정을 거치게 된다.
A
→
B (ARP Request : Broadcast)
[EthernetII Src : 00:1b:78:7b:5d:8c]
[EthernetII Dest : ff:ff:ff:ff:ff:ff]
A ←
B (ARP Reply : Unicast)
[EthernetII Src : 00:13:77:bd:2d:5c]
[EthernetII Dest : 00:1b:78:7b:5d:8c]
[Network/libtins] Wi-Fi auto deauthentication attack (C++) (0) | 2016.06.27 |
---|---|
[Network/Ethernet] EthernetII header (0) | 2016.06.21 |
[Network/libtins] Sending ARP, ICMP Packet with libtins (0) | 2016.06.21 |
-Baekjoon Online Judging 11399 - ATM-
[Probs]
https://www.acmicpc.net/problem/11399
[Solve]
그리디 알고리즘...이라고 하기도 민망할 정도로 쉬운 문제였다.
Sorting을 하는 방법과 Priority-Queue를 이용하는 방법이 있다.
하지만 본인의 경우 STL의 multiset이라는 컨테이너를 사용해서 풀었다.
multiset의 경우 기존의 set에서 중복 원소를 허용하는 것으로, insert시 정렬이 가능하다.
priority_queue보다 performance가 우수하며, iteration이 가능해 Range-based for loop에도 사용할 수 있다.
[Code]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> #include <set> int main(){ int num, tmp, ret = 0; std::multiset<int, std::less<int>> vSet; std::cin >> num; for(int i = 0; i < num; ++i){ std::cin >> tmp; vSet.insert(tmp); } tmp = 0; for(auto x : vSet) { tmp = x + tmp; ret += tmp; } std::cout << ret; } | cs |