8 #include <nsdp/protocol.h>
13 static void handler (int sig)
16 printf("interrupt\n");
22 int err = 0, sw_sock = -1, cl_sock = -1;
27 struct sockaddr_in sw_local, cl_local;
32 sw_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
39 cl_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
47 memset(&sw_local, 0, sizeof(struct sockaddr_in));
48 sw_local.sin_family = AF_INET;
49 sw_local.sin_addr.s_addr = htonl(INADDR_ANY);
50 sw_local.sin_port = htons(SWITCH_PORT);
53 cl_local.sin_port = htons(CLIENT_PORT);
55 if (bind(sw_sock, (struct sockaddr*)&sw_local, sizeof(struct sockaddr_in)) < 0) {
61 if (bind(cl_sock, (struct sockaddr*)&cl_local, sizeof(struct sockaddr_in)) < 0) {
68 fds[0].events = POLLIN;
71 fds[1].events = POLLIN;
74 memset(&sa, 0, sizeof(struct sigaction));
75 sa.sa_handler = handler;
76 sigaction(SIGINT, &sa, NULL);
77 sigaction(SIGTERM, &sa, NULL);
79 attr = createEmptyList();
82 err = poll(fds, 2, -1);
86 } else if (err == 0) {
90 memset(&nc, 0, sizeof(struct nsdp_cmd));
91 nc.remote_addr.sin_family = AF_INET;
93 if (fds[0].revents & POLLIN) {
94 nc.remote_addr.sin_port = htons(CLIENT_PORT);
95 err = recvNsdpPacket(sw_sock, &nc, attr, NULL);
97 nc.remote_addr.sin_port = htons(SWITCH_PORT);
98 err = recvNsdpPacket(cl_sock, &nc, attr, NULL);
104 printf("---------------------------------\n");
106 printf("received %d attribute(s)\n", attr->count);
108 for (ln = attr->first; ln != NULL; ln = ln->next) {
110 printf("received attribute code = %04X, length = %d\n", at->attr, at->size);
113 clearList(attr, (void(*)(void*))freeAttr);
115 printf("---------------------------------\n\n");
118 destroyList(attr, (void(*)(void*))freeAttr);