summaryrefslogtreecommitdiff
path: root/mndp.c
diff options
context:
space:
mode:
authorHaakon Nessjoen <haakon.nessjoen@gmail.com>2010-11-02 13:02:30 +0100
committerHaakon Nessjoen <haakon.nessjoen@gmail.com>2010-11-02 13:02:30 +0100
commita0316461bda85882821a1777a88953797f78292c (patch)
treee865b45b8ef5282707c695da697ba911987bee18 /mndp.c
parent7f6c0cd059d6d913842f625da204801f9c5b67f1 (diff)
parenta993f53f4ab8e08bfa2c198d9375f85686e87c9f (diff)
downloadMAC-Telnet-a0316461bda85882821a1777a88953797f78292c.tar.gz
MAC-Telnet-a0316461bda85882821a1777a88953797f78292c.zip
Merge remote branch 'origin/master' into mactelnet-osx
Conflicts: mactelnet.c mactelnetd.c protocol.c
Diffstat (limited to 'mndp.c')
-rw-r--r--mndp.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/mndp.c b/mndp.c
index 4f2b88a..d7bd33f 100644
--- a/mndp.c
+++ b/mndp.c
@@ -29,14 +29,14 @@
#include "protocol.h"
#include "config.h"
+/* Protocol data direction, not used here, but obligatory for protocol.c */
+unsigned char mt_direction_fromserver = 0;
+
int main(int argc, char **argv) {
int sock,result;
int optval = 1;
struct sockaddr_in si_me, si_remote;
unsigned char buff[MT_PACKET_LEN];
- unsigned short nameLen = 0;
- unsigned char name[MT_MNDP_MAX_NAME_LENGTH + 1];
- unsigned char mac[ETH_ALEN];
/* Open a UDP socket handle */
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
@@ -73,6 +73,7 @@ int main(int argc, char **argv) {
}
while(1) {
+ struct mt_mndp_packet *packet;
/* Wait for a UDP packet */
result = recvfrom(sock, buff, MT_PACKET_LEN, 0, 0, 0);
if (result < 0) {
@@ -80,29 +81,13 @@ int main(int argc, char **argv) {
exit(1);
}
- /* Check for valid packet length */
- if (result < 18) {
- continue;
- }
-
- /* Fetch length of Identifier string */
- memcpy(&nameLen, buff+16,2);
- nameLen = (nameLen >> 8) | ((nameLen&0xff)<<8);
-
- /* Enforce maximum name length */
- nameLen = nameLen < sizeof(name) ? nameLen : MT_MNDP_MAX_NAME_LENGTH;
+ /* Parse MNDP packet */
+ packet = parseMNDP(buff, result);
- /* Read Identifier string */
- memcpy(&name, buff+18, nameLen);
-
- /* Append zero */
- name[nameLen] = 0;
-
- /* Read source MAC address */
- memcpy(&mac, buff+8, ETH_ALEN);
-
- /* Print it */
- printf("%17s %s\n", ether_ntoa((struct ether_addr *)mac), name);
+ if (packet != NULL) {
+ /* Print it */
+ printf("%17s %s\n", ether_ntoa((struct ether_addr *)packet->address), packet->identity);
+ }
}
/* We'll never get here.. */