diff options
Diffstat (limited to 'src/pdesc.c')
-rw-r--r-- | src/pdesc.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/pdesc.c b/src/pdesc.c index 82cc600..77f511e 100644 --- a/src/pdesc.c +++ b/src/pdesc.c @@ -1,12 +1,33 @@ #include "pdesc.h" +#include "ppkt.h" #include "psock.h" +#include <netinet/ip_icmp.h> -enum pdesc_retval pdesc_find_remote(struct psock * psock) +static void pdesc_init(struct psock * psock, struct pdesc * pdesc, uint16_t identifier) { - for (size_t i = 0; i < psock->remotes.used; ++i) - { + pdesc->state = PDESC_STATE_AUTH; + pdesc->peer = psock->current.peer; + pdesc->identifier = identifier; + pdesc->sequence = 0; +} + +struct pdesc * pdesc_find_remote(struct psock * psock) +{ + size_t i; + + if (psock->remotes.used == psock->remotes.max || ppkt_process_icmp(psock) != 0 || + psock->current.packet.icmphdr->type != ICMP_ECHOREPLY || ppkt_process_ppkt(psock) != 0) { + return NULL; } - return PDESC_REMOTE_FOUND; + for (i = 0; i < psock->remotes.used; ++i) { + if (psock->current.packet.icmphdr->un.echo.id == psock->remotes.descriptors[i].identifier) { + return &psock->remotes.descriptors[i]; + } + } + + pdesc_init(psock, &psock->remotes.descriptors[i], psock->current.packet.icmphdr->un.echo.id); + + return &psock->remotes.descriptors[i]; } |