9 int sendNsdpPacket (int sock, const struct nsdp_cmd *nc, const List *attr)
11 unsigned char buffer[1500];
12 struct nsdp_packet np;
16 if (sock < 0 || nc == NULL)
20 np.maxlen = sizeof(buffer);
22 initNsdpHeader(np.nh, nc);
24 ret = addPacketAttributes(&np, attr, nc->ports);
28 ret = sendto(sock, buffer, getPacketTotalSize(&np), 0, (struct sockaddr*)&nc->remote_addr, sizeof(struct sockaddr_in));
37 int recvNsdpPacket (int sock, struct nsdp_cmd *nc, List *attr, const struct timeval *timeout)
39 unsigned char buffer[1500];
40 struct nsdp_packet np;
41 socklen_t slen = sizeof(struct sockaddr_in);
45 struct sockaddr_in remote;
48 if (sock < 0 || nc == NULL || attr == NULL)
56 memset(&remote, 0, sizeof(struct sockaddr_in));
57 remote.sin_family = AF_INET;
62 select(sock + 1, &fs, NULL, NULL, timeout == NULL ? NULL : &rem); /* FIXME: non portable */
64 len = recvfrom(sock, buffer, sizeof(buffer), MSG_DONTWAIT, (struct sockaddr*)&remote, &slen);
71 if ((nc->remote_addr.sin_addr.s_addr != 0 && remote.sin_addr.s_addr != nc->remote_addr.sin_addr.s_addr) ||
72 (nc->remote_addr.sin_port != 0 && remote.sin_port != nc->remote_addr.sin_port) ||
73 len < (int)sizeof(struct nsdp_header) ||
74 !validateNsdpHeader(np.nh, nc) ||
75 extractPacketAttributes(&np, attr, nc->ports) < 0)
78 nc->remote_addr = remote;
80 nc->code = np.nh->code;
81 nc->error = np.nh->error;
82 nc->attr_error = ntohs(np.nh->attr);