Skip to content

Instantly share code, notes, and snippets.

@txomon
Last active November 11, 2015 10:23
Show Gist options
  • Save txomon/699ed25c8bc2b0812379 to your computer and use it in GitHub Desktop.
Save txomon/699ed25c8bc2b0812379 to your computer and use it in GitHub Desktop.
recvfrom 0.0.0.0
unsigned int get_next_pkt(int fd, struct lx_pkt *pkt, struct sockaddr_in *si)
{
socklen_t size_si = sizeof(struct sockaddr);
ssize_t bytes;
bytes = recvfrom(fd, pkt, 1024, 0, (struct sockaddr *) si, &size_si);
if (bytes < 1) {
return 0;
}
return (unsigned int) bytes;
}
static void processor()
{
struct sockaddr_in si = {.sin_port=56700}; /* Avoid improbable null */
unsigned int bytes;
pkt = malloc(1024); /* Enough for known packages */
while ((bytes = get_next_pkt(lx_ctx->sock.fd, pkt, &si))) {
fprintf(stderr, "Address %u\n", si.sin_addr
.s_addr);
}
free(pkt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment