6 #include <sys/socket.h>
11 #define NORMAL_PORT 1234
15 int main(int argc, char** argv)
18 memset((void*)&rawLocal, 0, sizeof(rawLocal));
19 rawLocal.sin_family = AF_INET;
20 rawLocal.sin_port = htons(RAW_PORT);
22 int rawSocket = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
24 perror("socket() for RAW socket. Root permission missing?");
28 if(bind(rawSocket, (sockaddr*)&rawLocal, sizeof(rawLocal)) < 0) {
34 sockaddr_in normalLocal;
35 memset((void*)&normalLocal, 0, sizeof(normalLocal));
36 normalLocal.sin_family = AF_INET;
37 normalLocal.sin_port = htons(NORMAL_PORT);
39 int normalSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
40 if(normalSocket < 0) {
45 if(bind(normalSocket, (sockaddr*)&normalLocal, sizeof(normalLocal)) < 0) {
53 pfds[0].fd = normalSocket;
54 pfds[0].events = POLLIN;
55 pfds[1].fd = rawSocket;
56 pfds[1].events = POLLIN;
58 int result = poll((pollfd*)&pfds, 2, -1);
64 char buffer[65536 + 1];
65 if(pfds[0].revents & POLLIN) {
66 int bytes = recv(normalSocket, (char*)&buffer, sizeof(buffer) - 1, 0);
69 printf("Received %d bytes on NORMAL socket: %s\n", bytes, buffer);
76 if(pfds[1].revents & POLLIN) {
77 int bytes = recv(rawSocket, (char*)&buffer, sizeof(buffer) - 1, 0);
79 printf("Received %d bytes on RAW socket\n", bytes);