7 typedef struct SunMsgUdp SunMsgUdp;
14 typedef struct Arg Arg;
25 UdpMaxRead = 65536+Udphdrsize
30 int n, paraport, port;
36 uchar localip[IPaddrlen];
43 memmove(localip, v4prefix, IPaddrlen);
47 buf = emalloc(UdpMaxRead);
48 while((n = udpread(arg.fd, &udp, buf, UdpMaxRead)) > 0){
50 fprint(2, "udpread got %d (%d) from %I\n", n, Udphdrsize, udp.raddr);
51 if((srv->localonly || srv->localparanoia) && ipcmp(udp.raddr, localip) != 0){
52 fprint(2, "dropping message from %I: not local\n", udp.raddr);
55 if(srv->localparanoia){
56 port = nhgets(udp.rport);
58 fprint(2, "paranoid mode: only %I/%d allowed\n", localip, port);
60 }else if(paraport != port){
61 fprint(2, "dropping message from %I: not port %d\n", udp.raddr, port);
65 msg = emalloc(sizeof(SunMsgUdp));
67 msg->msg.data = emalloc(n);
69 memmove(msg->msg.data, buf, n);
70 msg->msg.creply = arg.creply;
72 fprint(2, "message %p count %d\n", msg, msg->msg.count);
73 sendp(arg.srv->crequest, msg);
86 buf = emalloc(UdpMaxRead);
87 while((msg = recvp(arg.creply)) != nil){
88 if(udpwrite(arg.fd, &msg->udp, msg->msg.data, msg->msg.count) != msg->msg.count)
89 fprint(2, "udpwrite: %r\n");
96 sunsrvudp(SunSrv *srv, char *address)
102 fd = announce(address, adir);
106 arg = emalloc(sizeof(Arg));
109 arg->creply = chancreate(sizeof(SunMsg*), 10);
110 arg->csync = chancreate(sizeof(void*), 10);
112 proccreate(sunudpread, arg, SunStackSize);
113 proccreate(sunudpwrite, arg, SunStackSize);
116 chanfree(arg->csync);