(1-2) 消耗页面分配器的 0x8000
| 102 | } |
| 103 | // (1-2) 消耗页面分配器的 0x8000 |
| 104 | int packet_socket_setup(unsigned int block_size, unsigned int frame_size, |
| 105 | unsigned int block_nr, unsigned int sizeof_priv, int timeout) { |
| 106 | int s = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); |
| 107 | if (s < 0) { |
| 108 | perror("[-] socket(AF_PACKET)"); |
| 109 | exit(EXIT_FAILURE); |
| 110 | } |
| 111 | |
| 112 | packet_socket_rx_ring_init(s, block_size, frame_size, block_nr, |
| 113 | sizeof_priv, timeout); |
| 114 | |
| 115 | struct sockaddr_ll sa; |
| 116 | memset(&sa, 0, sizeof(sa)); |
| 117 | sa.sll_family = PF_PACKET; |
| 118 | sa.sll_protocol = htons(ETH_P_ALL); |
| 119 | sa.sll_ifindex = if_nametoindex("lo"); |
| 120 | sa.sll_hatype = 0; |
| 121 | sa.sll_pkttype = 0; |
| 122 | sa.sll_halen = 0; |
| 123 | |
| 124 | int rv = bind(s, (struct sockaddr *)&sa, sizeof(sa)); |
| 125 | if (rv < 0) { |
| 126 | perror("[-] bind(AF_PACKET)"); |
| 127 | exit(EXIT_FAILURE); |
| 128 | } |
| 129 | |
| 130 | return s; |
| 131 | } |
| 132 | |
| 133 | void packet_socket_send(int s, char *buffer, int size) { |
| 134 | struct sockaddr_ll sa; |
no test coverage detected