[En-Nut-Discussion] Getting remote ip address
Harald Kipp
harald.kipp at egnite.de
Mon Feb 9 19:15:57 CET 2004
Hi Georg,
Sorry it took some time to pull your post from
a large queue after the list server crash.
If you subribe at
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
your posts will appear in the list without approval.
Regarding your _real_ problem:
With TCP, you don't worry about the remote IP. You simply
send data back on the same socket (same connection).
See the tcps sample.
For UDP, you'll get the remote address (and port) from
NutUdpReceiveFrom(). Here's a simple snippet to give you
an idea:
u_long raddr; <--- Remote's IP
u_short rport; <--- Remote's port
for (;;) {
if ((got = NutUdpReceiveFrom(sock, &raddr, &rport, buff,
sizeof(buff), 1000)) <= 0) {
printf("Recv failed\n");
}
else {
//printf("R%d-%s:%u\n", got, inet_ntoa(raddr), rport);
if (NutUdpSendTo(sock, raddr, LOCALPORT, buff, got)) {
printf("Send failed\n");
}
else {
putchar('S');
}
}
}
Harald
More information about the En-Nut-Discussion
mailing list