... to make MyApp to receive UDP packets on port 138 (netbios) while samba is running ?
I mean to receive packets in a "normal way" from a socket, not from libpcap if it's possible.
The goal for this is to make linux version of intranetChat without server, only on mailslots.
Follwing code works when samba is stoped.
Any ideeas to make it work together with samba are welcome:
Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define PORT 138 //8081
#define MAXBUFLEN 1024
extern int errno;
int main ()
{
struct sockaddr_in server;
struct sockaddr_in from;
char buffer[100];
int sd;
int addr_len, numbytes, i;
char buf[MAXBUFLEN];
if ((sd = socket (AF_INET, SOCK_DGRAM, 0)) == -1)
{
perror ("socket err().\n");
return errno;
}
bzero (&server, sizeof (server));
bzero (&from, sizeof (from));
/* umplem structura folosita de server */
server.sin_family = AF_INET;
server.sin_addr.s_addr = htonl (INADDR_ANY);
server.sin_port = htons (PORT);
if (bind (sd, (struct sockaddr *) &server, sizeof (struct sockaddr)) == -1)
{
perror ("bind err().\n");
return errno;
}
i=0;
while (i<25)
{
addr_len = sizeof (struct sockaddr);
if ((numbytes=recvfrom(sd, buf, MAXBUFLEN, 0, (struct sockaddr*)&from, &addr_len))==-1)
{
perror ("receive err");
return errno;
}
printf ("Got %d bytes from %s\n", numbytes, inet_ntoa(from.sin_addr));
buf[numbytes]='\0';
printf ("CONTENT: '%s'\n\n", buf);
i++;
}
close (sd);
} /* main */